通过openxml在altchunk中附加中文文本 [英] Append Chinese text in altchunk through openxml
问题描述
大家好,
我通过c#生成一个单词报告并打开xml但问题是当我追加altchunk下面的代码
string id =ReportChkName+ details.check_id;
string altChunkId1 = id;
AlternativeFormatImportPart altchunk = part.AddAlternativeFormatImportPart( AlternativeFormatImportPartType.Html,altChunkId1);
使用(Stream stream = altchunk.GetStream())
{
byte [] buf =(new System.Text.UTF8Encoding())。GetBytes(< html>< body> + mystring +< / body> < / html>);
stream.Write(buf,0,buf.Length);
}
AltChunk altChunk1 = new AltChunk();
altChunk1.Id = altChunkId1;
run362.Append (altChunk1);
'mystring'中的中文文本不应以适当的格式出现在单词报告中。
所以请你帮帮我,我怎样才能附上中文文字
< blockquote>嗨......我通过改变下面的语句解决了这个问题
byte [] buf =(new System.Text.UTF8Encoding())。GetBytes( < html>< body>+ mystring +< / body>< / html>);
以上语句替换为< br $>
byte [] buf = Encoding.Unicode.GetPreamble()。Concat(Encoding.Unicode.GetBytes(< html>< body>+ mystring + < / body>< / html>>+ details.check_comments +< / body>< / html>))。ToArray ();
Hi all,
I am generating a word report through c# and open xml but the problem is that when i append altchunk the below code
string id = "ReportChkName" + details.check_id;
string altChunkId1 = id;
AlternativeFormatImportPart altchunk = part.AddAlternativeFormatImportPart(AlternativeFormatImportPartType.Html, altChunkId1);
using (Stream stream = altchunk.GetStream())
{
byte[] buf = (new System.Text.UTF8Encoding()).GetBytes("<html><body>" + mystring + "</body></html>");
stream.Write(buf, 0, buf.Length);
}
AltChunk altChunk1 = new AltChunk();
altChunk1.Id = altChunkId1;
run362.Append(altChunk1);
the chinese text in 'mystring' should not appear on word report in appropriate format.
So will you please help me, how can i append the string with chinese text
Hi...I solved this problem itself by altering the below statement
byte[] buf = (new System.Text.UTF8Encoding()).GetBytes("<html><body>" + mystring + "</body></html>");
the above statement is replace by
byte[] buf = Encoding.Unicode.GetPreamble().Concat(Encoding.Unicode.GetBytes("<html><body>" + mystring + "</body></html>">" + details.check_comments + "</body></html>")).ToArray();
这篇关于通过openxml在altchunk中附加中文文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!