Open Xml Open Methodを使用してドキュメントファイルを開き、ドキュメント内のブックマークを検索し、aspxページのテキストボックスまたはラベルからブックマークにテキストを割り当て、最後に新しいドキュメントに保存したいと思います。OfficeInteropWordメソッドを使用する前。ここで、OpenXmlメソッドで同じことを試してみたいと思います。しかし、私はそれを達成することができません。私たちを手伝ってくれますか?前もって感謝します。
参考までに、私のオフィスの相互運用コードは次のとおりです。
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();