xlnt icon indicating copy to clipboard operation
xlnt copied to clipboard

Languages support

Open earth2378 opened this issue 6 years ago • 7 comments

I tried to use with Thai language but it was found that:

terminate called after throwing an instance of 'xml::serialization' what(): xl/sharedStrings.xml: error: invalid UTF-8

earth2378 avatar May 12 '18 10:05 earth2378

thanks for reporting his problem. UTF compatibility is a priority for me. Could you show me the code that caused this problem? Or tell me more about what you were trying to do.

tfussell avatar Jun 04 '18 15:06 tfussell

@tfussell Chinese also got the same fault. Just substitute

ws.cell("B2").value("Hello world");

in sample code with

ws.cell("B2").value("你好,世界");

and you will get the fault. I use vs2017 and use xlnt.lib as the linker input. I got the right xlsx file after running the sample code, but got fault immediately when I changed the string to Chinese.

ZM-J avatar Jul 12 '18 04:07 ZM-J

Finally I solved the problem by noticing issue #215 and using u8"你好,世界". I think @earth2378 might encounter the same problem as mine.

ZM-J avatar Jul 12 '18 05:07 ZM-J

Nice find.

A catch you may want to be aware of if you need portability is that even with the u8 literal, different compilers/editors may still choke and give the incorrect output (relevant stack overflow).

The only way to ensure that everything works as expected anywhere with literals is the unicode escape sequences. It's downright ugly though :(

你好,世界
u8"\u4F60\u597D\uFF0C\u4E16\u754C"

Hex format from https://unicodelookup.com/#%E4%BD%A0%E5%A5%BD%EF%BC%8C%E4%B8%96%E7%95%8C/1

Crzyrndm avatar Jul 12 '18 21:07 Crzyrndm

It is likely that using u8 prefix (+ escape sequences if neccesary) will resolve the reported issue for @earth2378 . Confirmation (or not) of this would be appreciated

@tfussell This is a recurring issue. I wonder if documentation (e.g. where UTF8 compatibility is mentioned, add a note about source literals) or source changes/additions can be made that may prevent this error.

Crzyrndm avatar Jul 28 '18 01:07 Crzyrndm

Finally I solved the problem by noticing issue #215 and using u8"你好,世界". I think @earth2378 might encounter the same problem as mine.

I try to use your method,but if I want to read a excel,like ws.cell(1,1).to_string() ,if the value of (1,1) is Chinese,it will be messy code.Do you know how can I fix it?

li1553770945 avatar Aug 08 '20 12:08 li1553770945

Finally I solved the problem by noticing issue #215 and using u8"你好,世界". I think @earth2378 might encounter the same problem as mine.

I try to use your method,but if I want to read a excel,like ws.cell(1,1).to_string() ,if the value of (1,1) is Chinese,it will be messy code.Do you know how can I fix it?

What are you trying to do with it? It should be a valid UTF-8 string you can use like any other Chinese UTF-8 string from another source.

tfussell avatar Aug 20 '20 19:08 tfussell