gpt4 book ai didi

c# - CustomXMLPart 中的换行符

转载 作者:数据小太阳 更新时间:2023-10-29 02:27:43 25 4
gpt4 key购买 nike

我正在通过重写 CustomXMLPart 文件来更新 word 文档。我基本上遵循了本教程:http://blogs.msdn.com/b/brian_jones/archive/2009/01/05/taking-advantage-of-bound-content-controls.aspx

private bool _makeDoc()
{

var path = HttpContext.Current.Server.MapPath("~/Classes/Word/template.docx");
using (WordprocessingDocument myDoc = WordprocessingDocument.Open(path, true))
{
//create new XML string
//these values will populate the template word doc
string newXML = "<root>";
newXML += "<name>";
newXML += "name goes here";
newXML += "</name>";
newXML += "<bio>";
newXML += "text" + "more text";
newXML += "</bio>";
newXML += "</root>";

MainDocumentPart mainPart = myDoc.MainDocumentPart;

//delete old xml part
mainPart.DeleteParts<CustomXmlPart>(mainPart.CustomXmlParts);

//add new xml part
CustomXmlPart customXml = mainPart.AddCustomXmlPart(CustomXmlPartType.CustomXml);
using(StreamWriter ts = new StreamWriter(customXml.GetStream()))
{
ts.Write(newXML);
}
myDoc.Close();
}
return true;
}

问题是我不知道如何在“文本”和“更多文本”之间添加换行符。我试过 Environment.NewLine,我试过将它包装在 <w:p><w:r><w:t> 中标签。我似乎无法让它生成有效的 docx 文件。

如有任何帮助,我们将不胜感激。

最佳答案

内容控件属性有一个“允许回车”选项。打开它并使用 Environment.NewLine 效果很好。

关于c# - CustomXMLPart 中的换行符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6507999/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com