Bug 60147 - Unable to export string “IBM_x3550_M2” correctly
Summary: Unable to export string “IBM_x3550_M2” correctly
Status: RESOLVED DUPLICATE of bug 57008
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-09-19 07:27 UTC by onlyarticle
Modified: 2016-09-19 13:14 UTC (History)
0 users



Attachments
export result (10.65 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2016-09-19 07:27 UTC, onlyarticle
Details
code sample (16.24 KB, text/x-csrc)
2016-09-19 08:34 UTC, onlyarticle
Details

Note You need to log in before you can comment on or make changes to this bug.
Description onlyarticle 2016-09-19 07:27:10 UTC
Created attachment 34272 [details]
export result

Hello !
I want to export to excel 2007 use XSSF, but i found some string can't export correctly such as "IBM_x3550_M2", this string will be export to "IBM㕐M2".

Then i found the problem is "_x3550_", when the string's format like "_xNUMBER_"  and the NUMBER is a Unicode code , then it will be export to "_xChinese character_".

Is this a bug of XSSF ?
Or there are some other ways to resolve it?

PS:Use HSSF to export Excel 2003 is correctly!
Comment 1 Javen O'Neal 2016-09-19 07:41:07 UTC
Could you include a code sample to reproduce this?
Comment 2 onlyarticle 2016-09-19 08:02:46 UTC
(In reply to Javen O'Neal from comment #1)
> Could you include a code sample to reproduce this?

code sample is normal ,you can try it by yourself!

By the way,jxls has same problem when i use to export Excel 2007,because jxls is base poi!
Comment 3 onlyarticle 2016-09-19 08:34:51 UTC
Created attachment 34273 [details]
code sample
Comment 4 Javen O'Neal 2016-09-19 09:04:08 UTC
I was hoping for a code sample that is less than 20 lines. I do not understand what function is causing the problem from comment 0.

What code is called when you "export to Excel"? Where is the Unicode string set? Is this on an existing document or a new document? A concise code sample should be able to answer this.
Comment 5 onlyarticle 2016-09-19 09:14:37 UTC
(In reply to Javen O'Neal from comment #4)

code sample like this :

XSSFRow row = sheet.createRow(rowNum);
XSSFCell cell = row.createCell(i);
cell.setCellStyle(style);
cell.setCellValue(textValue);

OR 

XSSFRichTextString richString = new XSSFRichTextString(textValue);
richString.applyFont(font);
cell.setCellValue(richString);
Comment 6 Dominik Stadler 2016-09-19 13:14:32 UTC
We had a few discussions around this already, see https://bz.apache.org/bugzilla/buglist.cgi?f0=OP&f1=OP&f3=CP&f4=CP&j2=OR&list_id=151221&product=POI&query_format=advanced&short_desc=_x&short_desc_type=allwordssubstr for some matches. 

Specifically bug 57008 discussed this. Short answer: this is how Excel encodes special characters and the POI API currently does not interfere with these escape-sequences currently, so to solve this you should escape strings like these as described in bug 57008, specifically "This seems to be an Excel "feature" and if you prepend this string with "_0x005F" the string stays at it is."

*** This bug has been marked as a duplicate of bug 57008 ***