2012-06-19 48 views
0

我想使用Open Xml Open Method打开文档文件,搜索文档内的书签,从aspx页面中的文本框或标签分配文本到书签并最终保存到一个新的文档。在我使用Office Interop Word Method之前。现在我想在Open Xml Method中尝试同样的事情。但我无法实现它。你可以帮帮我吗?提前致谢。打开现有的Word文档,编辑其书签并使用Open Xml方法保存为新文档

供您参考我的办公室互操作的代码是如下,

object Nothing = System.Reflection.Missing.Value; 
    object format = Word.WdSaveFormat.wdFormatDocument; 

    Word.Application wordApp = new Word.ApplicationClass(); 

    object srcFileName = Server.MapPath(ResolveUrl(@"~/HRLetter\Arabia\Templates\Employment Certificate.doc")); 

    Word.Document wordDoc = wordApp.Documents.Open 
    (ref srcFileName, ref format, ref Nothing, ref Nothing, 
    ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, 
    ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, 
    ref Nothing, ref Nothing); 

     object bookmarkDate = "Date"; 
     wordDoc.Bookmarks.get_Item(ref bookmarkDate).Select(); 

     wordApp.Selection.Text = string.Format("{0:MM/dd/yyyy}", lblRequestdate.Text); 

     string DocName; 
     DocName = string.Format("{0}_employment_certificate", lblRequestNo.Text); 
     hFilename.Value = DocName; 
     wordDoc.SaveAs(Server.MapPath(ResolveUrl(@"~/HRLetter\Arabia\Letters\" + DocName + ".doc"))); 


     wordDoc.Close(ref Nothing, ref Nothing, ref Nothing); 
     if (wordDoc != null) 
     { 
      System.Runtime.InteropServices.Marshal.ReleaseComObject(wordDoc); 
      wordDoc = null; 
     } 

     wordApp.Quit(ref Nothing, ref Nothing, ref Nothing); 
     if (wordApp != null) 
     { 
      System.Runtime.InteropServices.Marshal.ReleaseComObject(wordApp); 
      wordApp = null; 
     } 
    GC.Collect(); 

回答

0

我能够使用开放的XML的方法来实现它。

相关问题