【发布时间】:2014-08-07 08:24:16
【问题描述】:
我正在使用 RTF 模板。在这个模板中有几个地方需要替换文本。当使用 ASCII 字符时,这很好用。当我使用非 ASCII 字符时,字符变为问号。
我的程序代码:
memo = memo.Replace("%TITEL%", titel);
memo 是 RTF 文件,在我的代码中作为字符串读取。 %TITEL% 存在于 RTF 模板中 en titel 具有以下文本:
Förderband
所以%TITEL% 被Förderband 替换。
当我打开文档时,文字显示:
F?rderband
我将 RTF 字符串添加到 Word 文档中:
// Read RTF document content.
string rtfDocumentContent = memo;
using (MemoryStream ms = new MemoryStream(Encoding.ASCII.GetBytes(rtfDocumentContent)))
{
chunk.FeedData(ms);
}
AltChunk altChunk = new AltChunk();
altChunk.Id = altChunkId;
// Embed AltChunk after the last paragraph.
mainDocPart.Document.Body.InsertAfter(
altChunk, mainDocPart.Document.Body.Elements<DocumentFormat.OpenXml.Wordprocessing.Paragraph>().Last());
谁能帮帮我?
【问题讨论】:
-
如何保存文件?
-
“文档”有什么编码?
-
你用什么编码来写文件?
-
看看:stackoverflow.com/questions/1368020/… 提供了一个函数,它将 UTF 字符更改为它们各自的代码点表示。
标签: c# rtf non-ascii-characters