如何使用DocX库将文本正确导出到Word

时间:2014-09-04 06:29:07

标签: c# novacode-docx

我正在尝试将一些文本从c#程序输出到一个新的Word文档,但我有一个奇怪的问题:我的很多输出都是颠倒的。任何没有以字母结尾的单词都会跳到句子的末尾。例如:

DocX doc= DocX.Create(filePath);
Paragraph p1 = template.InsertParagraph();
p1.AppendLine("This line contains a ").Append("bold").Bold().Append(" word.");
p1.AppendLine("Here is example with question mark?");
p1.AppendLine();
p1.AppendLine("Can you help me figure it out?");
p1.AppendLine();

Output of the code

Output of the code

正如你所看到的,以非字母结尾的句子正在混淆。我正在使用2010 Office Word

1 个答案:

答案 0 :(得分:1)

尝试改为

Paragraph p1 = template.InsertParagraph();

使用此

Paragraph p1 = doc.InsertParagraph();