我正在使用 TextWriter 基于字符串制作 RTF 文件。
TextWriter tw = new StreamWriter(@"C:\test\test.rtf",false,Encoding.GetEncoding("iso-8859-1"));
tw.Write(text);
下面是我输入的字符串TextWriter
。我使用
String.Concat<T>(IEnumerable<T>)
该集合中的值已通过以下方式将其转换为 RTFXceed.Wpf.Toolkit.RichTextBox
"{\\rtf1\\ansi\\ansicpg1252\\uc1\\htmautsp\\deff2{\\fonttbl{\\f0\\fcharset0 Times New Roman;}{\\f2\\fcharset0 Segoe UI;}}{\\colortbl\
\red0\\green0\\blue0;\\red255\\green255\\blue255;}\\loch\\hich\\dbch\\pard\\plain\\ltrpar\\itap0{\\lang1033\\fs24\\f2\\cf0 \\cf0\\ql{\
\f2 {\\b\\ltrch test.}\\li0\\ri0\\sa0\\sb0\\fi0\\ql\\par}\r\n{\\f2 {\\b\\ltrch (test, test, test, test)}\\li0\\ri0\\sa0\\sb0\\fi0\\ql\
\par}\r\n{\\f2 \\li0\\ri0\\sa0\\sb0\\fi0\\ql\\par}\r\n{\\f2 {\\ltrch test: test}\\li0\\ri0\\sa0\\sb0\\fi0\\ql\\par}\r\n}\r\n}{\\rtf1\
\ansi\\ansicpg1252\\uc1\\htmautsp\\deff2{\\fonttbl{\\f0\\fcharset0 Times New Roman;}{\\f2\\fcharset0 Segoe UI;}}{\\colortbl\\red0\
\green0\\blue0;\\red255\\green255\\blue255;}\\loch\\hich\\dbch\\pard\\plain\\ltrpar\\itap0{\\lang1033\\fs24\\f2\\cf0 \\cf0\\ql{\\f2 {\
\b\\ltrch test.}\\li0\\ri0\\sa0\\sb0\\fi0\\ql\\par}\r\n{\\f2 {\\b\\ltrch (test, test, test, test)}\\li0\\ri0\\sa0\\sb0\\fi0\\ql\\par}\r
\n{\\f2 \\li0\\ri0\\sa0\\sb0\\fi0\\ql\\par}\r\n{\\f2 {\\ltrch test: test}\\li0\\ri0\\sa0\\sb0\\fi0\\ql\\par}\r\n}\r\n}"
这是 RTF 文件:
{\rtf1\ansi\ansicpg1252\uc1\htmautsp\deff2{\fonttbl{\f0\fcharset0 Times New Roman;}{\f2\fcharset0 Segoe UI;}}{\colortbl
\red0\green0\blue0;\red255\green255\blue255;}\loch\hich\dbch\pard\plain\ltrpar\itap0{\lang1033\fs24\f2\cf0 \cf0\ql{\f2 {\b\ltrch
test.}\li0\ri0\sa0\sb0\fi0\ql\par}
{\f2 {\b\ltrch (test, test, test, test)}\li0\ri0\sa0\sb0\fi0\ql\par}
{\f2 \li0\ri0\sa0\sb0\fi0\ql\par}
{\f2 {\ltrch test: test}\li0\ri0\sa0\sb0\fi0\ql\par}
}
}{\rtf1\ansi\ansicpg1252\uc1\htmautsp\deff2{\fonttbl{\f0\fcharset0 Times New Roman;}{\f2\fcharset0 Segoe UI;}}{\colortbl
\red0\green0\blue0;\red255\green255\blue255;}\loch\hich\dbch\pard\plain\ltrpar\itap0{\lang1033\fs24\f2\cf0 \cf0\ql{\f2 {\b\ltrch
test.}\li0\ri0\sa0\sb0\fi0\ql\par}
{\f2 {\b\ltrch (test, test, test, test)}\li0\ri0\sa0\sb0\fi0\ql\par}
{\f2 \li0\ri0\sa0\sb0\fi0\ql\par}
{\f2 {\ltrch test: test}\li0\ri0\sa0\sb0\fi0\ql\par}
}
}
它在记事本中打开良好。但我必须删除 2 个花括号(}{
就在第二个rtf1
标签之前)才能让 MS Word 显示整个文件:
{\rtf1\ansi\ansicpg1252\uc1\htmautsp\deff2{\fonttbl{\f0\fcharset0 Times New Roman;}{\f2\fcharset0 Segoe UI;}}{\colortbl
\red0\green0\blue0;\red255\green255\blue255;}\loch\hich\dbch\pard\plain\ltrpar\itap0{\lang1033\fs24\f2\cf0 \cf0\ql{\f2 {\b\ltrch
test.}\li0\ri0\sa0\sb0\fi0\ql\par}
{\f2 {\b\ltrch (test, test, test, test)}\li0\ri0\sa0\sb0\fi0\ql\par}
{\f2 \li0\ri0\sa0\sb0\fi0\ql\par}
{\f2 {\ltrch test: test}\li0\ri0\sa0\sb0\fi0\ql\par}
}
\rtf1\ansi\ansicpg1252\uc1\htmautsp\deff2{\fonttbl{\f0\fcharset0 Times New Roman;}{\f2\fcharset0 Segoe UI;}}{\colortbl
\red0\green0\blue0;\red255\green255\blue255;}\loch\hich\dbch\pard\plain\ltrpar\itap0{\lang1033\fs24\f2\cf0 \cf0\ql{\f2 {\b\ltrch
test.}\li0\ri0\sa0\sb0\fi0\ql\par}
{\f2 {\b\ltrch (test, test, test, test)}\li0\ri0\sa0\sb0\fi0\ql\par}
{\f2 \li0\ri0\sa0\sb0\fi0\ql\par}
{\f2 {\ltrch test: test}\li0\ri0\sa0\sb0\fi0\ql\par}
}
}
在我删除这些大括号之前,Word 只显示第一条记录:
test.
(test, test, test, test)
test: test
而不是整个文档:
test.
(test, test, test, test)
test: test
test.
(test, test, test, test)
test: test
我试图谷歌一个解决方案,但无济于事。任何帮助,将不胜感激。