我可以使用Silverlight中的Microsoft.Office.Interop.Word .dll来操作MSWord的SaveDialogFile吗?

发布于 2024-12-16 10:34:05 字数 2227 浏览 7 评论 0原文

我在制作 silverlight 应用程序时遇到问题,我需要使用 silverlight 创建 Word 文档,并使用 MSWord 中的“默认保存”按钮将其直接保存到数据库,但随后我无法使用silverlight中的“Microsoft.Office.Interop.Word .dll”来操作SaveFileDialog,以便我可以在保存时设置默认路径。

另一个问题是,我可以隐藏或在 Silverlight 中设置 MSWord SaveFileDialog = false使用 Microsoft.Office.Interop.Word .dll? 因为我的另一个计划是在 Silverlight 中创建自定义保存文件对话框而不是使用 MSWord 保存文件对话框..?

我使用的是Silverlight 5 Beta,使用其他版本的MS Office是否有兼容性问题?

 public partial class MainPage : UserControl
 {
     dynamic objWord;
     dynamic document;
     dynamic range;
     static bool saveDoc = false;

     public MainPage()
     {
         InitializeComponent();
         objWord = AutomationFactory.CreateObject("Word.Application"); 
         AutomationEvent saveEvent = AutomationFactory.GetEvent(objWord, "DocumentBeforeSave");
         saveEvent.EventRaised += (s, args) =>
         {
             saveDoc = true;

             if (saveDoc == true)
             {
                 SaveFileDialog dlg = new SaveFileDialog();
                 dlg.DefaultExt = ".doc"; // Default file extension
                 dlg.Filter = "Word documents (.doc)|*.doc"; // Filter files by extension
                 Nullable<bool> result = dlg.ShowDialog();

                 if (result == true)
                 {
                     string filename = dlg.SafeFileName;
                     FileInfo aD = new FileInfo(filename);
                     string pathDoc = aD.DirectoryName.ToString();
                     MessageBox.Show(pathDoc); //trying to get the path so that i can flush it to memory stream
                 }
             }
         };
     }

     private void Button_Click(object sender, RoutedEventArgs e)
     {
         if (AutomationFactory.IsAvailable)
         {
             try
             {
                 document = objWord.Documents.Add();
                 object startIndex = 0;
                 range = document.Range(ref startIndex);
                 objWord.Visible = true;
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message);
             }
         }
     }
}

预先感谢:)上帝保佑

I have problem in making silverlight application, I need to create a Word Document using silverlight and the Save it directly to the database using the Default Save button in MSWord, but then I cannot use the "Microsoft.Office.Interop.Word .dll" in silverlight to manipulate the SaveFileDialog so that I can set the Default path when saving..

Another question is, can I hide or set the MSWord SaveFileDialog = false in Silverlight using Microsoft.Office.Interop.Word .dll? because my other plan is that to create a custom savefiledialog box in Silverlight and not to use the MSWord SaveFileDialog box..?

I use the Silverlight 5 Beta, is there any compatibility issue in using other version of MS Office.?

 public partial class MainPage : UserControl
 {
     dynamic objWord;
     dynamic document;
     dynamic range;
     static bool saveDoc = false;

     public MainPage()
     {
         InitializeComponent();
         objWord = AutomationFactory.CreateObject("Word.Application"); 
         AutomationEvent saveEvent = AutomationFactory.GetEvent(objWord, "DocumentBeforeSave");
         saveEvent.EventRaised += (s, args) =>
         {
             saveDoc = true;

             if (saveDoc == true)
             {
                 SaveFileDialog dlg = new SaveFileDialog();
                 dlg.DefaultExt = ".doc"; // Default file extension
                 dlg.Filter = "Word documents (.doc)|*.doc"; // Filter files by extension
                 Nullable<bool> result = dlg.ShowDialog();

                 if (result == true)
                 {
                     string filename = dlg.SafeFileName;
                     FileInfo aD = new FileInfo(filename);
                     string pathDoc = aD.DirectoryName.ToString();
                     MessageBox.Show(pathDoc); //trying to get the path so that i can flush it to memory stream
                 }
             }
         };
     }

     private void Button_Click(object sender, RoutedEventArgs e)
     {
         if (AutomationFactory.IsAvailable)
         {
             try
             {
                 document = objWord.Documents.Add();
                 object startIndex = 0;
                 range = document.Range(ref startIndex);
                 objWord.Visible = true;
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message);
             }
         }
     }
}

Thanks in Advance :) God Bless

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

放飞的风筝 2024-12-23 10:34:05

如果您有 Silverlight 应用程序,则可以访问 Word/Excel/Outlook。位于 FullTrust 和 OutOfBrowser 中。

这里有一个很好的 Excel 示例

You can access Word/Excel/Outlook if your Silverlight App. is in FullTrust and OutOfBrowser.

Here you have a good example with Excel

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文