sheetjs icon indicating copy to clipboard operation
sheetjs copied to clipboard

how to resolve the encode problem?

Open LittleBreak opened this issue 9 years ago • 21 comments

i got a xml file include some chinese characters, when i use the XLSX.write api, the chinese characters changed. here is my code workbook is a xml string var workbook = XLSX.read(content, {type: 'binary'}); workbook.Sheets['ag-grid']['A24'].v image the cell value became this, the oringin value is '中文测试',apologize for my bed english,.

LittleBreak avatar Jul 20 '17 02:07 LittleBreak

Can you share the original file and a screenshot of what excel shows?

reviewher avatar Jul 20 '17 02:07 reviewher

I also have the same question. I'm working with japanese/korean. It cannot read these words, but english shows no problem. Target excel file is the one which generated from python workbook library. But something weird is, it reads the data well after export new xlsx file from original one without no changing.

kwangin avatar Jul 28 '17 05:07 kwangin

@kwangin Can you upload or send us:

  1. the original file (that was causing an issue)
  2. an Excel screenshot showing the right values
  3. the new file after export

If you are running in the browser, are you using the full version or the core version?

SheetJSDev avatar Jul 28 '17 05:07 SheetJSDev

I also have the same question.@kwangin you solve the problem? @SheetJSDev My files are as follows 预算_月度累计预算_20170920_1216.xlsx

nicaicaicaicai avatar Sep 20 '17 04:09 nicaicaicaicai

@PWDream thanks for sharing! This was very helpful. It looks like a file from Apache POI.

The tool that wrote the file used xml entities rather than the UTF8 string. Despite the fact that the subfile clearly has a UTF-8 encoding, the writer opted to use XML entities. This is the text for A1:

<!-- this is from the @PWDream file -->
<t>&#39044;&#31639;&#32534;&#30721;</t>

In a good file generated by Excel, the stored text is written directly:

<!-- this is from the resaved file -->
<t>预算编码</t>

Looking at other files in the test suite, those values should have be encoded using hexadecimal notation:

<!-- this is what should have been written -->
<t>&#x9884;&#x7b97;&#x7f16;&#x7801;</t>

The XLSX reader accepts UTF8-encoded Chinese characters (second example) and hexadecimal digit entities (third example), but the relevant entity checker does not accept the decimal digit case (problematic case). Since Excel accepts it, we probably should do the same. Fortunately the fix is straightforward.

SheetJSDev avatar Sep 20 '17 04:09 SheetJSDev

Thank you very much for your reply.What time do you fix this problem?

nicaicaicaicai avatar Sep 20 '17 05:09 nicaicaicaicai

A small local change seemed to have fixed the immediate problem but we need to do some more tests to be sure. Expect a release tomorrow or Friday

SheetJSDev avatar Sep 20 '17 05:09 SheetJSDev

Thank you very much

nicaicaicaicai avatar Sep 20 '17 05:09 nicaicaicaicai

@SheetJSDev Hello, is this problem solved?

nicaicaicaicai avatar Sep 21 '17 08:09 nicaicaicaicai

@SheetJSDev Hello, is this problem solved?

nicaicaicaicai avatar Sep 22 '17 04:09 nicaicaicaicai

@SheetJSDev Hello, is this problem solved? or you tell me how to change, I go to change.Thanks

nicaicaicaicai avatar Sep 22 '17 06:09 nicaicaicaicai

@PWDream it's available now in version 0.11.4

SheetJSDev avatar Sep 23 '17 00:09 SheetJSDev

@SheetJSDev Thank you very much for your changes.I have upgraded to the latest version,the coding problem has been solved,but why did I turn behind the three empty lines after the line. image My files are as follows

预算_+——)(-&……%¥#@!-_20170925_0715.xlsx

nicaicaicaicai avatar Sep 24 '17 23:09 nicaicaicaicai

The file has a weird record near the end of the worksheet:

<row r="5">
</row>

If you want to hide those blank rows, when converting to CSV pass the option blankrows:false. For example, in node:

> var XLSX = require('xlsx');
> var wb = XLSX.readFile('_.-.-_20170925_0715.xlsx');
> var ws = wb.Sheets[wb.SheetNames[0]];

> console.log(XLSX.utils.sheet_to_csv(ws)); // this shows the blank lines
预算编码,项目,2017年预算金额,预算超额时控制,负责人
,项目1,0.00,允许单据提交,
,,,,
,,,,
,,,,

> console.log(XLSX.utils.sheet_to_csv(ws, {blankrows:false})) // this will hide those rows
预算编码,项目,2017年预算金额,预算超额时控制,负责人
,项目1,0.00,允许单据提交,

SheetJSDev avatar Sep 24 '17 23:09 SheetJSDev

Thank you very much!

nicaicaicaicai avatar Sep 24 '17 23:09 nicaicaicaicai

Hello I have the same issue for the encoding. XLS BIFF8(office 97-2004 document) and contains japanese characters. So i have used codepage:932 for japanese and it's working well for csv files. Unfortunately, it's not working for office 97 xls file. Manually, i open office 97 xls file and save as xlsx or csv file and one alert prompted as like that: "Some features in your workbook must be lost if you save it as Microsoft Excel 5.0/95 Workbook. Do you want to keep using that format?" After i click "Yes" and save, then it's working without any problem.(of course we use codepage: 932) Could you please give me instruction how can i solve that issue? Thanks.

margin-hub avatar Sep 20 '20 13:09 margin-hub

@WangHwaKok is this happening when you read in a file or make one from scratch? Can you share the bad file?

SheetJSDev avatar Sep 20 '20 21:09 SheetJSDev

Hello @SheetJSDev Yes, I am trying to read a downloaded xls file from the site. I share office 97 xls file.(it is zipped) test.zip Please take a look and hope we will solve the issue easily.

margin-hub avatar Sep 21 '20 06:09 margin-hub

Does this actually work for you in Excel @WangHwaKok ? The file has a CodePage record but the specified codepage is 1252.

SheetJSDev avatar Sep 21 '20 14:09 SheetJSDev

image Yes, working well so i can see japanese characters in Excel. Normally, we can't see original japanese characters. I am using win 10 OS and changed region/language setting as Japanese. image As i said before, after i save the file again & click 'yes' on alert message then i can analyze the file with codepage: 932 and i can see original characters. Hopefully this can be helpful.

margin-hub avatar Sep 21 '20 15:09 margin-hub