0

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

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

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();
4

1 回答 1

0

我可以使用 Open Xml 方法来实现它。

于 2012-06-21T07:51:52.110 回答