通过openxml在altchunk中附加中文文本 [英] Append Chinese text in altchunk through openxml

查看:121
本文介绍了通过openxml在altchunk中附加中文文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我通过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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆