我想創建一個基於帶內容控件的模板的新Word文檔。C#使用OpenXml填充單詞模板
我需要填寫這些內容控件(文本)。
我只發現如何生成一個新的Word文檔,但不是基於模板。
您有任何鏈接或教程嗎?
也許我錯了使用OpenXml來填充模板?
// Create a Wordprocessing document.
using (WordprocessingDocument myDoc =
WordprocessingDocument.Create("d:/dev/test.docx",
WordprocessingDocumentType.Document))
{
// Add a new main document part.
MainDocumentPart mainPart = myDoc.AddMainDocumentPart();
//Create Document tree for simple document.
mainPart.Document = new Document();
//Create Body (this element contains
//other elements that we want to include
Body body = new Body();
//Create paragraph
Paragraph paragraph = new Paragraph();
Run run_paragraph = new Run();
// we want to put that text into the output document
Text text_paragraph = new Text("Hello World!");
//Append elements appropriately.
run_paragraph.Append(text_paragraph);
paragraph.Append(run_paragraph);
body.Append(paragraph);
mainPart.Document.Append(body);
// Save changes to the main document part.
mainPart.Document.Save();
}