C# 从SQL Server DB到XML Word文档的nvarchar(最大值)不保留回车
我编写了一个程序,可以从SQLServer表中提取信息,并将信息放入MS WORD中C# 从SQL Server DB到XML Word文档的nvarchar(最大值)不保留回车,c#,sql-server,xml,C#,Sql Server,Xml,我编写了一个程序,可以从SQLServer表中提取信息,并将信息放入MS WORD中 foreach (String note in doc_object.alJobNotes) { String formattednote = ""; newTextElement = xdoc.CreateElement("w:t", wordmlNamespace); formattednote = note.Replace(Environment.NewLine, "
foreach (String note in doc_object.alJobNotes)
{
String formattednote = "";
newTextElement = xdoc.CreateElement("w:t", wordmlNamespace);
formattednote = note.Replace(Environment.NewLine, " ");
XmlText newText = xdoc.CreateTextNode(formattednote);
newTextElement.AppendChild(newText);
XmlAttribute xmlSpace = xdoc.CreateAttribute(
"xml", "space",
"http://www.w3.org/XML/1998/namespace");
xmlSpace.Value = "preserve";
newTextElement.Attributes.Append(xmlSpace);
ChildNode.ParentNode.InsertAfter(newTextElement, ChildNode);
EmptyElement = xdoc.CreateElement("w:br", wordmlNamespace);
EmptyElement.Attributes.Append(xmlSpace);
ChildNode.ParentNode.InsertAfter(EmptyElement, ChildNode);
ChildNode.ParentNode.InsertAfter(EmptyElement, ChildNode);
ChildNode.ParentNode.InsertAfter(EmptyElement, ChildNode);
ChildNode.ParentNode.InsertAfter(EmptyElement, ChildNode);
}
然而,当我打开Ms Word时,车厢返回的位置仅显示&13
我尝试过用&10;,替换它;,char13,char10,但我找不到怎么做
有什么建议吗?好吧,如果我正确解释了您的代码和问题描述,我相信问题在于您没有生成有效的WordOpenXML。我假设这是docx文件格式 查看代码发出的原始XML,并将其与ZIP包中的示例Word文档的document.XML文件进行比较 您的代码似乎将新行作为w:t元素的一部分追加。但WordOpenXML不是这样设计的。WordOpenXML更像这样,其中w:p是段落回车/ANSI 13:
<w:p>
<w:r>
<w:t>text here</w:t>
</w:r>
</w:p>