
[英]How to create custom style Linked (paragraph and character) in MS Word using OpenXml.Wordprocessing and C#
[英]How to create a textbox in word openxml using c#
我正在尝试使用 openxml nuget 为 word 文档创建一个文本框。 我似乎没有任何关于如何向我的页面添加文本框的资源
这是我尝试过的
using (MemoryStream memory = new MemoryStream())
{
// Create Document
using (WordprocessingDocument wordDocument =
WordprocessingDocument.Create(memory, WordprocessingDocumentType.Document, true))
{
// Add a main document part.
MainDocumentPart mainPart = wordDocument.AddMainDocumentPart();
// Create the document structure and add some text.
mainPart.Document = new Document();
Body docBody = new Body();
TextBox testBox = new TextBox();
TextBoxContent textBoxContent = new TextBoxContent();
Paragraph paragraph = new Paragraph();
Run run = new Run();
Text text = new Text("test");
run.Append(text);
paragraph.Append(run);
textBoxContent.Append(paragraph);
testBox.Append(textBoxContent);
docBody.Append(testBox);
mainPart.Document.Append(docBody);
wordDocument.Save();
}
//Download File
return new MemoryStream(memory.ToArray());
}
显示的代码给了我损坏的单词错误。 我应该如何 append 使其工作的元素?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.