繁体   English   中英

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

[英]Can I use the Microsoft.Office.Interop.Word .dll in Silverlight to manipulate the SaveDialogFile of MSWord?

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

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

我使用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);
             }
         }
     }
}

在此先感谢:)上帝保佑

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

在这里,您有一个使用Excel的好例子

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM