Free Support Forum - aspose.com

Mail merge and Chinese content

Hi,

I have tried to do a mail merge from a database containing both English and Foreign text. The English and European characters are showing fine in the resulting document, but Chinese characters are not showing at all.

Does Aspose.Word support Chinese characters?

Thanks,
Seb

Aspose.Words library supports any language that is supported by MS Word. But please mind that not every font contains Chinese characters and that can be the cause of your problem.

Please attach the template you are using and post some chinese text here so that we can research it further.

Regards,

Thank you.

Please find attached original template and output document following merge.

Text in "Entry overview" field (from Access DB) is:

entries
EntryOverview
Yahoo! Chinese - 雅虎中文. Yahoo! 新聞 - 為你即時掌握天下事. 搜尋, 搜尋. 【資訊】, 新聞 -

Chinese characters do appear properly in Access and in the VB.NET application, but are replaced by squares in mail merge output.

Thanks,
Sebastien

Thanks for the info. I will research the matter and let you know.

The problem is, as I have mentioned before, that not all TrueType fonts support localized characters. In fact on my system I have only one font supporting far east characters - Arial Unicode MS. So, to make Far East characters to display correctly in your document you need to assign to them the font that supports these characters.

Word actually permits to assign different fonts for different unicode ranges in one run of characters. Font.NameAscii, Font.NameBi, Font.NameFarEast and Font.NameOther serve to that purpose.

So, to simplify your task you can assign Font.NameFarEast property to all runs of your document just before saving it. That way you can be sure that all chinese or other far east characters will be diaplayed in the font that actually supports them.

You should also set correct Font.LocalIdFarEast to ensure proper choice of language for spell checking. If you don't care about spell checking, then it is not necessary.

Here is the code that should be executed just before saving your document:

foreach (Run run in doc.GetChildNodes(NodeType.Run, true))

{

// Specify the font name. Make sure it the font has the glyphs that you want to dislplay.

run.Font.NameFarEast = "Arial Unicode MS";

// Specify the locale so Microsoft Word recognizes this text as Chinese.

// For the list of locale identifiers see http://www.microsoft.com/globaldev/reference/lcid-all.mspx

run.Font.LocaleIdFarEast = 2052;

}

Thank you for this.

I have done some tests and it appears that only "Arial Unicode MS" font is able to display the characters properly. However, I was wondering if there was a way programmatically to only replace the font on Words containing Unicode characters, as opposed to the full string? The reason being that outputting everything in Arial Unicode is restrictive, and the font does not look that great.

For example, I might have:

Yahoo! Chinese - 雅虎中文. Yahoo! 新聞

in one single mail merge field. Ideally, I would like to have the words in English in their original fonts, and only the Chinese glyphs in Arial Unicode.

Thanks,
Sebastien

Setting Font.NameFarEast controls font of far east characters only. All other characters in the document retain their font setting.

So, the code I have posted above does exactly what you require.

Best regards,

Hi,

This is working great. Big Smile [:D]

Thanks!

Seb