version bump 0.11.15: right-to-left write

- XLSX right-to-left support (fixes #927 h/t @mghayour)
- HTML string preserve newline (fixes #929 h/t @Irikos)
This commit is contained in:
SheetJS 2017-12-24 21:25:03 -05:00
parent 028d7010a5
commit 33f96fc6ae
22 changed files with 108 additions and 68 deletions

1
.gitattributes vendored
View File

@ -8,3 +8,4 @@ docbits/* linguist-documentation
dist/* linguist-generated=true
xlsx.js linguist-generated=true
xlsxworker.js linguist-generated=true
tests/core.js linguist-generated=true

4
.gitignore vendored
View File

@ -12,8 +12,8 @@ tmp
*.[pP][rR][nN]
*.[sS][lL][kK]
*.socialcalc
*.[xX][lL][sSwWcC]
*.[xX][lL][sS][xXmMbB]
*.[xX][lL][sSwWcCaAtT]
*.[xX][lL][sSaAtT][xXmMbB]
*.[oO][dD][sS]
*.[fF][oO][dD][sS]
*.[xX][mM][lL]

View File

@ -1 +1 @@
XLSX.version = '0.11.14';
XLSX.version = '0.11.15';

View File

@ -148,6 +148,7 @@ var CT_LIST = (function(){
xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml",
xlsm: "application/vnd.ms-excel.sheet.macroEnabled.main+xml",
xlsb: "application/vnd.ms-excel.sheet.binary.macroEnabled.main",
xlam: "application/vnd.ms-excel.addin.macroEnabled.main+xml",
xltx: "application/vnd.openxmlformats-officedocument.spreadsheetml.template.main+xml"
},
strs: { /* Shared Strings */

View File

@ -193,7 +193,10 @@ function write_ws_xml_autofilter(data)/*:string*/ {
/* 18.3.1.88 sheetViews CT_SheetViews */
/* 18.3.1.87 sheetView CT_SheetView */
function write_ws_xml_sheetviews(ws, opts, idx, wb)/*:string*/ {
return writextag("sheetViews", writextag("sheetView", null, {workbookViewId:"0"}), {});
var sview = {workbookViewId:"0"};
// $FlowIgnore
if( (((wb||{}).Workbook||{}).Views||[])[0] ) sview.rightToLeft = wb.Workbook.Views[0].RTL ? "1" : "0";
return writextag("sheetViews", writextag("sheetView", null, sview), {});
}
function write_ws_xml_cell(cell, ref, ws, opts, idx, wb) {

View File

@ -335,9 +335,12 @@ function write_BrtMargins(margins/*:Margins*/, o) {
}
/* [MS-XLSB] 2.4.292 BrtBeginWsView */
function write_BrtBeginWsView(ws, o) {
function write_BrtBeginWsView(ws, Workbook, o) {
if(o == null) o = new_buf(30);
o.write_shift(2, 924); // bit flag
var f = 0x39c;
// $FlowIgnore
if((((Workbook||{}).Views||[])[0]||{}).RTL) f |= 0x20;
o.write_shift(2, f); // bit flag
o.write_shift(4, 0);
o.write_shift(4, 0); // view first row
o.write_shift(4, 0); // view first col
@ -748,11 +751,11 @@ function write_AUTOFILTER(ba, ws) {
write_record(ba, "BrtEndAFilter");
}
function write_WSVIEWS2(ba, ws) {
function write_WSVIEWS2(ba, ws, Workbook) {
write_record(ba, "BrtBeginWsViews");
{ /* 1*WSVIEW2 */
/* [ACUID] */
write_record(ba, "BrtBeginWsView", write_BrtBeginWsView(ws));
write_record(ba, "BrtBeginWsView", write_BrtBeginWsView(ws, Workbook));
/* [BrtPane] */
/* *4BrtSel */
/* *4SXSELECT */
@ -785,7 +788,7 @@ function write_ws_bin(idx/*:number*/, opts, wb/*:Workbook*/, rels) {
write_record(ba, "BrtBeginSheet");
write_record(ba, "BrtWsProp", write_BrtWsProp(c));
write_record(ba, "BrtWsDim", write_BrtWsDim(r));
write_WSVIEWS2(ba, ws);
write_WSVIEWS2(ba, ws, wb.Workbook);
write_WSFMTINFO(ba, ws);
write_COLINFOS(ba, ws, idx, opts, wb);
write_CELLTABLE(ba, ws, idx, opts, wb);

View File

@ -24,7 +24,6 @@ var HTML_ = (function() {
var m = cell, cc = 0;
/* TODO: parse styles etc */
while(m.charAt(0) == "<" && (cc = m.indexOf(">")) > -1) m = m.slice(cc+1);
while(m.indexOf(">") > -1) m = m.slice(0, m.lastIndexOf("<"));
var tag = parsexmltag(cell.slice(0, cell.indexOf(">")));
CS = tag.colspan ? +tag.colspan : 1;
if((RS = +tag.rowspan)>0 || CS>1) merges.push({s:{r:R,c:C},e:{r:R + (RS||1) - 1, c:C + CS - 1}});

16
dist/xlsx.core.min.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/xlsx.core.min.map generated vendored

File diff suppressed because one or more lines are too long

20
dist/xlsx.full.min.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/xlsx.full.min.map generated vendored

File diff suppressed because one or more lines are too long

24
dist/xlsx.js generated vendored
View File

@ -4,7 +4,7 @@
/*global global, exports, module, require:false, process:false, Buffer:false */
var XLSX = {};
(function make_xlsx(XLSX){
XLSX.version = '0.11.14';
XLSX.version = '0.11.15';
var current_codepage = 1200;
/*global cptable:true */
if(typeof module !== "undefined" && typeof require !== 'undefined') {
@ -3385,6 +3385,7 @@ var CT_LIST = (function(){
xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml",
xlsm: "application/vnd.ms-excel.sheet.macroEnabled.main+xml",
xlsb: "application/vnd.ms-excel.sheet.binary.macroEnabled.main",
xlam: "application/vnd.ms-excel.addin.macroEnabled.main+xml",
xltx: "application/vnd.openxmlformats-officedocument.spreadsheetml.template.main+xml"
},
strs: { /* Shared Strings */
@ -11747,7 +11748,10 @@ function write_ws_xml_autofilter(data) {
/* 18.3.1.88 sheetViews CT_SheetViews */
/* 18.3.1.87 sheetView CT_SheetView */
function write_ws_xml_sheetviews(ws, opts, idx, wb) {
return writextag("sheetViews", writextag("sheetView", null, {workbookViewId:"0"}), {});
var sview = {workbookViewId:"0"};
// $FlowIgnore
if( (((wb||{}).Workbook||{}).Views||[])[0] ) sview.rightToLeft = wb.Workbook.Views[0].RTL ? "1" : "0";
return writextag("sheetViews", writextag("sheetView", null, sview), {});
}
function write_ws_xml_cell(cell, ref, ws, opts, idx, wb) {
@ -12445,9 +12449,12 @@ function write_BrtMargins(margins, o) {
}
/* [MS-XLSB] 2.4.292 BrtBeginWsView */
function write_BrtBeginWsView(ws, o) {
function write_BrtBeginWsView(ws, Workbook, o) {
if(o == null) o = new_buf(30);
o.write_shift(2, 924); // bit flag
var f = 0x39c;
// $FlowIgnore
if((((Workbook||{}).Views||[])[0]||{}).RTL) f |= 0x20;
o.write_shift(2, f); // bit flag
o.write_shift(4, 0);
o.write_shift(4, 0); // view first row
o.write_shift(4, 0); // view first col
@ -12857,11 +12864,11 @@ function write_AUTOFILTER(ba, ws) {
write_record(ba, "BrtEndAFilter");
}
function write_WSVIEWS2(ba, ws) {
function write_WSVIEWS2(ba, ws, Workbook) {
write_record(ba, "BrtBeginWsViews");
{ /* 1*WSVIEW2 */
/* [ACUID] */
write_record(ba, "BrtBeginWsView", write_BrtBeginWsView(ws));
write_record(ba, "BrtBeginWsView", write_BrtBeginWsView(ws, Workbook));
/* [BrtPane] */
/* *4BrtSel */
/* *4SXSELECT */
@ -12894,7 +12901,7 @@ function write_ws_bin(idx, opts, wb, rels) {
write_record(ba, "BrtBeginSheet");
write_record(ba, "BrtWsProp", write_BrtWsProp(c));
write_record(ba, "BrtWsDim", write_BrtWsDim(r));
write_WSVIEWS2(ba, ws);
write_WSVIEWS2(ba, ws, wb.Workbook);
write_WSFMTINFO(ba, ws);
write_COLINFOS(ba, ws, idx, opts, wb);
write_CELLTABLE(ba, ws, idx, opts, wb);
@ -17335,7 +17342,6 @@ var HTML_ = (function() {
var m = cell, cc = 0;
/* TODO: parse styles etc */
while(m.charAt(0) == "<" && (cc = m.indexOf(">")) > -1) m = m.slice(cc+1);
while(m.indexOf(">") > -1) m = m.slice(0, m.lastIndexOf("<"));
var tag = parsexmltag(cell.slice(0, cell.indexOf(">")));
CS = tag.colspan ? +tag.colspan : 1;
if((RS = +tag.rowspan)>0 || CS>1) merges.push({s:{r:R,c:C},e:{r:R + (RS||1) - 1, c:C + CS - 1}});
@ -18929,7 +18935,7 @@ function sheet_to_json(sheet, opts) {
case 2: hdr[C] = cols[C]; break;
case 3: hdr[C] = o.header[C - r.s.c]; break;
default:
if(val == null) continue;
if(val == null) val = {w: "__EMPTY", t: "s"};
vv = v = format_cell(val, null, o);
counter = 0;
for(CC = 0; CC < hdr.length; ++CC) if(hdr[CC] == vv) vv = v + "_" + (++counter);

22
dist/xlsx.min.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/xlsx.min.map generated vendored

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{
"name": "xlsx",
"version": "0.11.14",
"version": "0.11.15",
"author": "sheetjs",
"description": "SheetJS Spreadsheet data parser and writer",
"keywords": [

View File

@ -1900,6 +1900,11 @@ describe('HTML', function() {
it('should interpret values by default', function() { plaintext_test(X.read(html_bstr, {type:"binary"}), false, false); });
it('should generate strings if raw option is passed', function() { plaintext_test(X.read(html_bstr, {type:"binary", raw:true}), true, false); });
it('should handle "string" type', function() { plaintext_test(X.read(html_str, {type:"string"}), false, false); });
it('should handle newlines correctly', function() {
var table = "<table><tr><td>foo<br/>bar</td><td>baz</td></tr></table>";
var wb = X.read(table, {type:"string"});
assert.equal(get_cell(wb.Sheets.Sheet1, "A1").v, "foo\nbar");
});
});
(domtest ? describe : describe.skip)('input DOM', function() {
it('should interpret values by default', function() { plaintext_test(X.utils.table_to_book(get_dom_element(html_str)), false, true); });

5
tests/core.js generated
View File

@ -1900,6 +1900,11 @@ describe('HTML', function() {
it('should interpret values by default', function() { plaintext_test(X.read(html_bstr, {type:"binary"}), false, false); });
it('should generate strings if raw option is passed', function() { plaintext_test(X.read(html_bstr, {type:"binary", raw:true}), true, false); });
it('should handle "string" type', function() { plaintext_test(X.read(html_str, {type:"string"}), false, false); });
it('should handle newlines correctly', function() {
var table = "<table><tr><td>foo<br/>bar</td><td>baz</td></tr></table>";
var wb = X.read(table, {type:"string"});
assert.equal(get_cell(wb.Sheets.Sheet1, "A1").v, "foo\nbar");
});
});
(domtest ? describe : describe.skip)('input DOM', function() {
it('should interpret values by default', function() { plaintext_test(X.utils.table_to_book(get_dom_element(html_str)), false, true); });

View File

@ -158,6 +158,7 @@ ws['!protect'] = {
if(!wb.Workbook) wb.Workbook = {Sheets:[], WBProps:{}};
if(!wb.Workbook.WBProps) wb.Workbook.WBProps = {};
wb.Workbook.WBProps.filterPrivacy = true;
//wb.Workbook.Views = [{RTL:true}];
console.log("Worksheet Model:");
console.log(ws);

3
types/index.d.ts vendored
View File

@ -271,6 +271,9 @@ export interface WBProps {
/** Defined Names */
Names?: DefinedName[];
/** Workbook Views */
Views?: any[];
/** Other Workbook Properties */
WBProps?: WorkbookProperties;
}

View File

@ -144,6 +144,7 @@ ws['!protect'] = {
if(!wb.Workbook) wb.Workbook = {Sheets:[], WBProps:{}};
if(!wb.Workbook.WBProps) wb.Workbook.WBProps = {};
wb.Workbook.WBProps.filterPrivacy = true;
wb.Workbook.Views = [{RTL:true}];
console.log("Worksheet Model:");
console.log(ws);

View File

@ -4,7 +4,7 @@
/*global global, exports, module, require:false, process:false, Buffer:false */
var XLSX = {};
(function make_xlsx(XLSX){
XLSX.version = '0.11.14';
XLSX.version = '0.11.15';
var current_codepage = 1200;
/*:: declare var cptable:any; */
/*global cptable:true */
@ -3468,6 +3468,7 @@ var CT_LIST = (function(){
xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml",
xlsm: "application/vnd.ms-excel.sheet.macroEnabled.main+xml",
xlsb: "application/vnd.ms-excel.sheet.binary.macroEnabled.main",
xlam: "application/vnd.ms-excel.addin.macroEnabled.main+xml",
xltx: "application/vnd.openxmlformats-officedocument.spreadsheetml.template.main+xml"
},
strs: { /* Shared Strings */
@ -11836,7 +11837,10 @@ function write_ws_xml_autofilter(data)/*:string*/ {
/* 18.3.1.88 sheetViews CT_SheetViews */
/* 18.3.1.87 sheetView CT_SheetView */
function write_ws_xml_sheetviews(ws, opts, idx, wb)/*:string*/ {
return writextag("sheetViews", writextag("sheetView", null, {workbookViewId:"0"}), {});
var sview = {workbookViewId:"0"};
// $FlowIgnore
if( (((wb||{}).Workbook||{}).Views||[])[0] ) sview.rightToLeft = wb.Workbook.Views[0].RTL ? "1" : "0";
return writextag("sheetViews", writextag("sheetView", null, sview), {});
}
function write_ws_xml_cell(cell, ref, ws, opts, idx, wb) {
@ -12534,9 +12538,12 @@ function write_BrtMargins(margins/*:Margins*/, o) {
}
/* [MS-XLSB] 2.4.292 BrtBeginWsView */
function write_BrtBeginWsView(ws, o) {
function write_BrtBeginWsView(ws, Workbook, o) {
if(o == null) o = new_buf(30);
o.write_shift(2, 924); // bit flag
var f = 0x39c;
// $FlowIgnore
if((((Workbook||{}).Views||[])[0]||{}).RTL) f |= 0x20;
o.write_shift(2, f); // bit flag
o.write_shift(4, 0);
o.write_shift(4, 0); // view first row
o.write_shift(4, 0); // view first col
@ -12947,11 +12954,11 @@ function write_AUTOFILTER(ba, ws) {
write_record(ba, "BrtEndAFilter");
}
function write_WSVIEWS2(ba, ws) {
function write_WSVIEWS2(ba, ws, Workbook) {
write_record(ba, "BrtBeginWsViews");
{ /* 1*WSVIEW2 */
/* [ACUID] */
write_record(ba, "BrtBeginWsView", write_BrtBeginWsView(ws));
write_record(ba, "BrtBeginWsView", write_BrtBeginWsView(ws, Workbook));
/* [BrtPane] */
/* *4BrtSel */
/* *4SXSELECT */
@ -12984,7 +12991,7 @@ function write_ws_bin(idx/*:number*/, opts, wb/*:Workbook*/, rels) {
write_record(ba, "BrtBeginSheet");
write_record(ba, "BrtWsProp", write_BrtWsProp(c));
write_record(ba, "BrtWsDim", write_BrtWsDim(r));
write_WSVIEWS2(ba, ws);
write_WSVIEWS2(ba, ws, wb.Workbook);
write_WSFMTINFO(ba, ws);
write_COLINFOS(ba, ws, idx, opts, wb);
write_CELLTABLE(ba, ws, idx, opts, wb);
@ -17436,7 +17443,6 @@ var HTML_ = (function() {
var m = cell, cc = 0;
/* TODO: parse styles etc */
while(m.charAt(0) == "<" && (cc = m.indexOf(">")) > -1) m = m.slice(cc+1);
while(m.indexOf(">") > -1) m = m.slice(0, m.lastIndexOf("<"));
var tag = parsexmltag(cell.slice(0, cell.indexOf(">")));
CS = tag.colspan ? +tag.colspan : 1;
if((RS = +tag.rowspan)>0 || CS>1) merges.push({s:{r:R,c:C},e:{r:R + (RS||1) - 1, c:C + CS - 1}});

22
xlsx.js generated
View File

@ -4,7 +4,7 @@
/*global global, exports, module, require:false, process:false, Buffer:false */
var XLSX = {};
(function make_xlsx(XLSX){
XLSX.version = '0.11.14';
XLSX.version = '0.11.15';
var current_codepage = 1200;
/*global cptable:true */
if(typeof module !== "undefined" && typeof require !== 'undefined') {
@ -3385,6 +3385,7 @@ var CT_LIST = (function(){
xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml",
xlsm: "application/vnd.ms-excel.sheet.macroEnabled.main+xml",
xlsb: "application/vnd.ms-excel.sheet.binary.macroEnabled.main",
xlam: "application/vnd.ms-excel.addin.macroEnabled.main+xml",
xltx: "application/vnd.openxmlformats-officedocument.spreadsheetml.template.main+xml"
},
strs: { /* Shared Strings */
@ -11747,7 +11748,10 @@ function write_ws_xml_autofilter(data) {
/* 18.3.1.88 sheetViews CT_SheetViews */
/* 18.3.1.87 sheetView CT_SheetView */
function write_ws_xml_sheetviews(ws, opts, idx, wb) {
return writextag("sheetViews", writextag("sheetView", null, {workbookViewId:"0"}), {});
var sview = {workbookViewId:"0"};
// $FlowIgnore
if( (((wb||{}).Workbook||{}).Views||[])[0] ) sview.rightToLeft = wb.Workbook.Views[0].RTL ? "1" : "0";
return writextag("sheetViews", writextag("sheetView", null, sview), {});
}
function write_ws_xml_cell(cell, ref, ws, opts, idx, wb) {
@ -12445,9 +12449,12 @@ function write_BrtMargins(margins, o) {
}
/* [MS-XLSB] 2.4.292 BrtBeginWsView */
function write_BrtBeginWsView(ws, o) {
function write_BrtBeginWsView(ws, Workbook, o) {
if(o == null) o = new_buf(30);
o.write_shift(2, 924); // bit flag
var f = 0x39c;
// $FlowIgnore
if((((Workbook||{}).Views||[])[0]||{}).RTL) f |= 0x20;
o.write_shift(2, f); // bit flag
o.write_shift(4, 0);
o.write_shift(4, 0); // view first row
o.write_shift(4, 0); // view first col
@ -12857,11 +12864,11 @@ function write_AUTOFILTER(ba, ws) {
write_record(ba, "BrtEndAFilter");
}
function write_WSVIEWS2(ba, ws) {
function write_WSVIEWS2(ba, ws, Workbook) {
write_record(ba, "BrtBeginWsViews");
{ /* 1*WSVIEW2 */
/* [ACUID] */
write_record(ba, "BrtBeginWsView", write_BrtBeginWsView(ws));
write_record(ba, "BrtBeginWsView", write_BrtBeginWsView(ws, Workbook));
/* [BrtPane] */
/* *4BrtSel */
/* *4SXSELECT */
@ -12894,7 +12901,7 @@ function write_ws_bin(idx, opts, wb, rels) {
write_record(ba, "BrtBeginSheet");
write_record(ba, "BrtWsProp", write_BrtWsProp(c));
write_record(ba, "BrtWsDim", write_BrtWsDim(r));
write_WSVIEWS2(ba, ws);
write_WSVIEWS2(ba, ws, wb.Workbook);
write_WSFMTINFO(ba, ws);
write_COLINFOS(ba, ws, idx, opts, wb);
write_CELLTABLE(ba, ws, idx, opts, wb);
@ -17335,7 +17342,6 @@ var HTML_ = (function() {
var m = cell, cc = 0;
/* TODO: parse styles etc */
while(m.charAt(0) == "<" && (cc = m.indexOf(">")) > -1) m = m.slice(cc+1);
while(m.indexOf(">") > -1) m = m.slice(0, m.lastIndexOf("<"));
var tag = parsexmltag(cell.slice(0, cell.indexOf(">")));
CS = tag.colspan ? +tag.colspan : 1;
if((RS = +tag.rowspan)>0 || CS>1) merges.push({s:{r:R,c:C},e:{r:R + (RS||1) - 1, c:C + CS - 1}});