How to output a fullwidth space? #1156

Closed
opened 2018-06-25 07:38:31 +00:00 by Sakura777 · 2 comments
Sakura777 commented 2018-06-25 07:38:31 +00:00 (Migrated from github.com)

Thank you for a nice script.
I use Japanese. When this code is executed, the fullwidth space (Ideographic space) in the exported file disappears.

//in HTML
<td> abc</td>

//in JS
var wb = XLSX.utils.book_new();
var ws = XLSX.utils.table_to_sheet(document.getElementById(table));
XLSX.utils.book_append_sheet(wb, ws, "sheetname");

//in exported Excel
|abc|
(I want to | abc|)

What should I do? Do I need to set something?

Thank you for a nice script. I use Japanese. When this code is executed, the fullwidth space (Ideographic space) in the exported file disappears. ``` //in HTML <td> abc</td> //in JS var wb = XLSX.utils.book_new(); var ws = XLSX.utils.table_to_sheet(document.getElementById(table)); XLSX.utils.book_append_sheet(wb, ws, "sheetname"); //in exported Excel |abc| (I want to | abc|) ``` What should I do? Do I need to set something?
SheetJSDev commented 2018-06-25 15:41:21 +00:00 (Migrated from github.com)

Good catch! IDEOGRAPHIC SPACE U+3000 is a whitespace character according to JS but not according to DOM rules. The whitespace normalization should be restricted to the DOM whitespace characters /[\t\n\r ]+/ instead of the full whitespace class \s+.

IF you would like to submit a PR, the linked line should be corrected to use the restricted class [\t\n\r ]+

Good catch! IDEOGRAPHIC SPACE U+3000 is a whitespace character according to JS but not according to DOM rules. The [whitespace normalization](https://github.com/SheetJS/js-xlsx/blob/master/bits/22_xmlutils.js#L177) should be restricted to the DOM whitespace characters `/[\t\n\r ]+/` instead of the full whitespace class `\s+`. IF you would like to submit a PR, the linked line should be corrected to use the restricted class `[\t\n\r ]+`
Sakura777 commented 2018-07-02 11:52:07 +00:00 (Migrated from github.com)

Thank you for the advice!
I rewrote the following code and it went well :)

//htmldecode function

//before
var o = str.trim().replace(/\s+/g, " ").replace(/<\s*[bB][rR]\s*\/?>/g,"\n").replace(/<[^>]*>/g,"");

//after : Deleted trim() and replaced space at the beginning of the line with full-width characters.
var o = str.replace(/\s+/g, " ").replace(/^\s+/g, " ").replace(/<\s*[bB][rR]\s*\/?>/g,"\n").replace(/<[^>]*>/g,"");
Thank you for the advice! I rewrote the following code and it went well :) ``` //htmldecode function //before var o = str.trim().replace(/\s+/g, " ").replace(/<\s*[bB][rR]\s*\/?>/g,"\n").replace(/<[^>]*>/g,""); //after : Deleted trim() and replaced space at the beginning of the line with full-width characters. var o = str.replace(/\s+/g, " ").replace(/^\s+/g, " ").replace(/<\s*[bB][rR]\s*\/?>/g,"\n").replace(/<[^>]*>/g,""); ```
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sheetjs/sheetjs#1156
No description provided.