Add rowBreaks, colBreaks, scale, showGridLines

This commit is contained in:
Pieter Sheth-Voss 2015-12-05 16:45:13 -05:00
commit f984bd6479
14 changed files with 173 additions and 91 deletions

@ -429,8 +429,11 @@ Special worksheet keys (accessible as `worksheet[key]`, each starting with `!`):
will write all cells in the merge range if they exist, so be sure that only
the first cell (upper-left) in the range is set.
The following properties are currently used when generating an XLSX file, but not yet parsed:
- `ws['!rowBreaks']`: array of row break points, e.g. `[16,32]`
- `ws['!colBreaks']`: array of col break points, e.g. `[8,16]`
- `ws['!pageSetup']`: `{scale: '100', orientation: 'portrait'||'landscape'}
### Workbook Object
@ -439,8 +442,15 @@ Special worksheet keys (accessible as `worksheet[key]`, each starting with `!`):
`wb.Sheets[sheetname]` returns an object representing the worksheet.
`wb.Props` is an object storing the standard properties. `wb.Custprops` stores
custom properties. Since the XLS standard properties deviate from the XLSX
`wb.Props` is an object storing the standard properties. The following properties are currently used when
generating an XLSX file, but not yet parsed:
- `title`
- `subject`
- `description`
- `keywords`
- `creator`
`wb.Custprops` stores custom properties. Since the XLS standard properties deviate from the XLSX
standard, XLS parsing stores core properties in both places. .
@ -492,7 +502,7 @@ The exported `write` and `writeFile` functions accept an options argument:
| cellDates | false | Store dates as type `d` (default is `n`) |
| bookSST | false | Generate Shared String Table ** |
| bookType | 'xlsx' | Type of Workbook ("xlsx" or "xlsm" or "xlsb") |
| showGridLines | true | Show gridlines on all pages |
| showGridLines | true | Show gridlines on all pages |
| tabSelected | '1' | Initial tab selected |
- `bookSST` is slower and more memory intensive, but has better compatibility
@ -503,6 +513,7 @@ The exported `write` and `writeFile` functions accept an options argument:
- `cellDates` only applies to XLSX output and is not guaranteed to work with
third-party readers. Excel itself does not usually write cells with type `d`
so non-Excel tools may ignore the data or blow up in the presence of dates.
- showGridLines and tabSelected are currently used when generating an XLSX file but not yet parse.
## Cell Styles

@ -1 +1 @@
XLSX.version = '0.8.6';
XLSX.version = '0.8.8';

@ -60,13 +60,20 @@ function cp_doit(f, g, h, o, p) {
function write_core_props(cp, opts) {
var o = [XML_HEADER, CORE_PROPS_XML_ROOT], p = {};
if(!cp) return o.join("");
if (opts && opts.Props) {
if (opts.Props.title) o[o.length] = '<dc:title>' + opts.Props.title + '</dc:title>';
if (opts.Props.subject) o[o.length] = '<dc:subject>' + opts.Props.subject + '</dc:subject>';
if (opts.Props.creator) o[o.length] = '<dc:creator>' + opts.Props.creator + '</dc:creator>';
if (opts.Props.keywords) o[o.length] = '<cp:keywords>' + opts.Props.keywords + '</cp:keywords>';
if (opts.Props.description) o[o.length] = '<dc:description>' + opts.Props.description + '</dc:description>';
}
if(cp) {
if(cp.CreatedDate != null) cp_doit("dcterms:created", typeof cp.CreatedDate === "string" ? cp.CreatedDate : write_w3cdtf(cp.CreatedDate, opts.WTF), {"xsi:type":"dcterms:W3CDTF"}, o, p);
if(cp.ModifiedDate != null) cp_doit("dcterms:modified", typeof cp.ModifiedDate === "string" ? cp.ModifiedDate : write_w3cdtf(cp.ModifiedDate, opts.WTF), {"xsi:type":"dcterms:W3CDTF"}, o, p);
if(cp.CreatedDate != null) cp_doit("dcterms:created", typeof cp.CreatedDate === "string" ? cp.CreatedDate : write_w3cdtf(cp.CreatedDate, opts.WTF), {"xsi:type":"dcterms:W3CDTF"}, o, p);
if(cp.ModifiedDate != null) cp_doit("dcterms:modified", typeof cp.ModifiedDate === "string" ? cp.ModifiedDate : write_w3cdtf(cp.ModifiedDate, opts.WTF), {"xsi:type":"dcterms:W3CDTF"}, o, p);
for(var i = 0; i != CORE_PROPS.length; ++i) { var f = CORE_PROPS[i]; cp_doit(f[0], cp[f[1]], null, o, p); }
if(o.length>2){ o[o.length] = ('</cp:coreProperties>'); o[1]=o[1].replace("/>",">"); }
return o.join("");
for(var i = 0; i != CORE_PROPS.length; ++i) { var f = CORE_PROPS[i]; cp_doit(f[0], cp[f[1]], null, o, p); }
}
if(o.length>2){ o[o.length] = ('</cp:coreProperties>'); o[1]=o[1].replace("/>",">"); }
return o.join("");
}

@ -70,15 +70,16 @@ function write_ws_xml_merges(merges) {
return o + '</mergeCells>';
}
//<pageSetup scale="90" orientation="portrait" horizontalDpi="4294967292" verticalDpi="4294967292"/>
//<rowBreaks count="1" manualBreakCount="1">
// <brk id="8" max="16383" man="1"/>
//</rowBreaks>
//<colBreaks count="1" manualBreakCount="1">
// <brk id="8" max="1048575" man="1"/>
//</colBreaks>
function write_ws_xml_pagesetup(setup) {
var pageSetup = writextag('pageSetup', null, {
scale: setup.scale || '100',
orientation: setup.orientation || 'portrait',
horizontalDpi : setup.horizontalDpi || '4294967292',
verticalDpi : setup.verticalDpi || '4294967292'
})
console.log(pageSetup);
return pageSetup;
}
function parse_ws_xml_hlinks(s, data, rels) {
@ -324,6 +325,7 @@ function write_ws_xml(idx, opts, wb) {
if(ws['!merges'] !== undefined && ws['!merges'].length > 0) o[o.length] = (write_ws_xml_merges(ws['!merges']));
if (ws['!pageSetup'] !== undefined) o[o.length] = write_ws_xml_pagesetup(ws['!pageSetup'])
if (ws['!rowBreaks'] !== undefined) o[o.length] = write_ws_xml_row_breaks(ws['!rowBreaks'])
if (ws['!colBreaks'] !== undefined) o[o.length] = write_ws_xml_col_breaks(ws['!colBreaks'])
@ -346,8 +348,8 @@ function write_ws_xml_col_breaks(breaks) {
var brk = [];
for (var i=0; i<breaks.length; i++) {
var thisBreak = ''+ (breaks[i]);
var nextBreak = '' + (breaks[i+1] || '16383');
var nextBreak = '' + (breaks[i+1] || '1048575');
brk.push(writextag('brk', null, {id: thisBreak, max: nextBreak, man: '1'}))
}
return writextag('colBreaks', brk.join(' '), {count: brk.length, manualBreakCount: brk.length})
}
}

@ -1,8 +1,8 @@
{
"name": "js-xlsx-style",
"homepage": "https://github.com/protobi/js-xlsx",
"name": "js-xlsx",
"homepage": "https://github.com/SheetJS/js-xlsx",
"main": "dist/xlsx.js",
"version": "0.8.7",
"version": "0.8.8",
"ignore": [
"bin",
"bits",

25
dist/xlsx.core.min.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

26
dist/xlsx.full.min.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

69
dist/xlsx.js vendored

@ -4,7 +4,7 @@
/*jshint funcscope:true, eqnull:true */
var XLSX = {};
(function make_xlsx(XLSX){
XLSX.version = '0.8.6';
XLSX.version = '0.8.8';
var current_codepage = 1200, current_cptable;
if(typeof module !== "undefined" && typeof require !== 'undefined') {
if(typeof cptable === 'undefined') cptable = require('./dist/cpexcel');
@ -2602,15 +2602,22 @@ function cp_doit(f, g, h, o, p) {
function write_core_props(cp, opts) {
var o = [XML_HEADER, CORE_PROPS_XML_ROOT], p = {};
if(!cp) return o.join("");
if (opts && opts.Props) {
if (opts.Props.title) o[o.length] = '<dc:title>' + opts.Props.title + '</dc:title>';
if (opts.Props.subject) o[o.length] = '<dc:subject>' + opts.Props.subject + '</dc:subject>';
if (opts.Props.creator) o[o.length] = '<dc:creator>' + opts.Props.creator + '</dc:creator>';
if (opts.Props.keywords) o[o.length] = '<cp:keywords>' + opts.Props.keywords + '</cp:keywords>';
if (opts.Props.description) o[o.length] = '<dc:description>' + opts.Props.description + '</dc:description>';
}
if(cp) {
if(cp.CreatedDate != null) cp_doit("dcterms:created", typeof cp.CreatedDate === "string" ? cp.CreatedDate : write_w3cdtf(cp.CreatedDate, opts.WTF), {"xsi:type":"dcterms:W3CDTF"}, o, p);
if(cp.ModifiedDate != null) cp_doit("dcterms:modified", typeof cp.ModifiedDate === "string" ? cp.ModifiedDate : write_w3cdtf(cp.ModifiedDate, opts.WTF), {"xsi:type":"dcterms:W3CDTF"}, o, p);
if(cp.CreatedDate != null) cp_doit("dcterms:created", typeof cp.CreatedDate === "string" ? cp.CreatedDate : write_w3cdtf(cp.CreatedDate, opts.WTF), {"xsi:type":"dcterms:W3CDTF"}, o, p);
if(cp.ModifiedDate != null) cp_doit("dcterms:modified", typeof cp.ModifiedDate === "string" ? cp.ModifiedDate : write_w3cdtf(cp.ModifiedDate, opts.WTF), {"xsi:type":"dcterms:W3CDTF"}, o, p);
for(var i = 0; i != CORE_PROPS.length; ++i) { var f = CORE_PROPS[i]; cp_doit(f[0], cp[f[1]], null, o, p); }
if(o.length>2){ o[o.length] = ('</cp:coreProperties>'); o[1]=o[1].replace("/>",">"); }
return o.join("");
for(var i = 0; i != CORE_PROPS.length; ++i) { var f = CORE_PROPS[i]; cp_doit(f[0], cp[f[1]], null, o, p); }
}
if(o.length>2){ o[o.length] = ('</cp:coreProperties>'); o[1]=o[1].replace("/>",">"); }
return o.join("");
}
/* 15.2.12.3 Extended File Properties Part */
/* [MS-OSHARED] 2.3.3.2.[1-2].1 (PIDSI/PIDDSI) */
@ -7497,7 +7504,7 @@ function get_cell_style_csf(cellXf) {
}
return s;
return JSON.parse(JSON.stringify(s));
}
return null;
}
@ -7595,6 +7602,18 @@ function write_ws_xml_merges(merges) {
return o + '</mergeCells>';
}
function write_ws_xml_pagesetup(setup) {
var pageSetup = writextag('pageSetup', null, {
scale: setup.scale || '100',
orientation: setup.orientation || 'portrait',
horizontalDpi : setup.horizontalDpi || '4294967292',
verticalDpi : setup.verticalDpi || '4294967292'
})
console.log(pageSetup);
return pageSetup;
}
function parse_ws_xml_hlinks(s, data, rels) {
for(var i = 0; i != data.length; ++i) {
var val = parsexmltag(data[i], true);
@ -7821,6 +7840,13 @@ function write_ws_xml(idx, opts, wb) {
var ref = ws['!ref']; if(ref === undefined) ref = 'A1';
o[o.length] = (writextag('dimension', null, {'ref': ref}));
var sheetView = writextag('sheetView', null, {
showGridLines: opts.showGridLines == false ? '0' : '1',
tabSelected: opts.tabSelected === undefined ? '1' : opts.tabSelected,
workbookViewId: opts.workbookViewId === undefined ? '0' : opts.workbookViewId
});
o[o.length] = writextag('sheetViews', sheetView);
if(ws['!cols'] !== undefined && ws['!cols'].length > 0) o[o.length] = (write_ws_xml_cols(ws, ws['!cols']));
o[sidx = o.length] = '<sheetData/>';
if(ws['!ref'] !== undefined) {
@ -7831,10 +7857,35 @@ function write_ws_xml(idx, opts, wb) {
if(ws['!merges'] !== undefined && ws['!merges'].length > 0) o[o.length] = (write_ws_xml_merges(ws['!merges']));
if (ws['!pageSetup'] !== undefined) o[o.length] = write_ws_xml_pagesetup(ws['!pageSetup'])
if (ws['!rowBreaks'] !== undefined) o[o.length] = write_ws_xml_row_breaks(ws['!rowBreaks'])
if (ws['!colBreaks'] !== undefined) o[o.length] = write_ws_xml_col_breaks(ws['!colBreaks'])
if(o.length>2) { o[o.length] = ('</worksheet>'); o[1]=o[1].replace("/>",">"); }
return o.join("");
}
function write_ws_xml_row_breaks(breaks) {
console.log("Writing breaks")
var brk = [];
for (var i=0; i<breaks.length; i++) {
var thisBreak = ''+ (breaks[i]);
var nextBreak = '' + (breaks[i+1] || '16383');
brk.push(writextag('brk', null, {id: thisBreak, max: nextBreak, man: '1'}))
}
return writextag('rowBreaks', brk.join(' '), {count: brk.length, manualBreakCount: brk.length})
}
function write_ws_xml_col_breaks(breaks) {
console.log("Writing breaks");
var brk = [];
for (var i=0; i<breaks.length; i++) {
var thisBreak = ''+ (breaks[i]);
var nextBreak = '' + (breaks[i+1] || '1048575');
brk.push(writextag('brk', null, {id: thisBreak, max: nextBreak, man: '1'}))
}
return writextag('colBreaks', brk.join(' '), {count: brk.length, manualBreakCount: brk.length})
}
/* [MS-XLSB] 2.4.718 BrtRowHdr */
function parse_BrtRowHdr(data, length) {
var z = [];

20
dist/xlsx.min.js vendored

File diff suppressed because one or more lines are too long

2
dist/xlsx.min.map vendored

File diff suppressed because one or more lines are too long

@ -1,6 +1,6 @@
{
"name": "xlsx-style",
"version": "0.8.7",
"version": "0.8.8",
"author": "sheetjs",
"description": "Excel (XLSB/XLSX/XLSM/XLS/XML) and ODS spreadsheet parser and writer (extended to enable read/write of cell formats with xlsx files)",
"keywords": [ "excel", "xls", "xlsx", "xlsb", "xlsm", "ods", "office", "spreadsheet" ],

46
xlsx.js

@ -4,7 +4,7 @@
/*jshint funcscope:true, eqnull:true */
var XLSX = {};
(function make_xlsx(XLSX){
XLSX.version = '0.8.6';
XLSX.version = '0.8.8';
var current_codepage = 1200, current_cptable;
if(typeof module !== "undefined" && typeof require !== 'undefined') {
if(typeof cptable === 'undefined') cptable = require('./dist/cpexcel');
@ -2602,15 +2602,22 @@ function cp_doit(f, g, h, o, p) {
function write_core_props(cp, opts) {
var o = [XML_HEADER, CORE_PROPS_XML_ROOT], p = {};
if(!cp) return o.join("");
if (opts && opts.Props) {
if (opts.Props.title) o[o.length] = '<dc:title>' + opts.Props.title + '</dc:title>';
if (opts.Props.subject) o[o.length] = '<dc:subject>' + opts.Props.subject + '</dc:subject>';
if (opts.Props.creator) o[o.length] = '<dc:creator>' + opts.Props.creator + '</dc:creator>';
if (opts.Props.keywords) o[o.length] = '<cp:keywords>' + opts.Props.keywords + '</cp:keywords>';
if (opts.Props.description) o[o.length] = '<dc:description>' + opts.Props.description + '</dc:description>';
}
if(cp) {
if(cp.CreatedDate != null) cp_doit("dcterms:created", typeof cp.CreatedDate === "string" ? cp.CreatedDate : write_w3cdtf(cp.CreatedDate, opts.WTF), {"xsi:type":"dcterms:W3CDTF"}, o, p);
if(cp.ModifiedDate != null) cp_doit("dcterms:modified", typeof cp.ModifiedDate === "string" ? cp.ModifiedDate : write_w3cdtf(cp.ModifiedDate, opts.WTF), {"xsi:type":"dcterms:W3CDTF"}, o, p);
if(cp.CreatedDate != null) cp_doit("dcterms:created", typeof cp.CreatedDate === "string" ? cp.CreatedDate : write_w3cdtf(cp.CreatedDate, opts.WTF), {"xsi:type":"dcterms:W3CDTF"}, o, p);
if(cp.ModifiedDate != null) cp_doit("dcterms:modified", typeof cp.ModifiedDate === "string" ? cp.ModifiedDate : write_w3cdtf(cp.ModifiedDate, opts.WTF), {"xsi:type":"dcterms:W3CDTF"}, o, p);
for(var i = 0; i != CORE_PROPS.length; ++i) { var f = CORE_PROPS[i]; cp_doit(f[0], cp[f[1]], null, o, p); }
if(o.length>2){ o[o.length] = ('</cp:coreProperties>'); o[1]=o[1].replace("/>",">"); }
return o.join("");
for(var i = 0; i != CORE_PROPS.length; ++i) { var f = CORE_PROPS[i]; cp_doit(f[0], cp[f[1]], null, o, p); }
}
if(o.length>2){ o[o.length] = ('</cp:coreProperties>'); o[1]=o[1].replace("/>",">"); }
return o.join("");
}
/* 15.2.12.3 Extended File Properties Part */
/* [MS-OSHARED] 2.3.3.2.[1-2].1 (PIDSI/PIDDSI) */
@ -7595,15 +7602,16 @@ function write_ws_xml_merges(merges) {
return o + '</mergeCells>';
}
//<pageSetup scale="90" orientation="portrait" horizontalDpi="4294967292" verticalDpi="4294967292"/>
//<rowBreaks count="1" manualBreakCount="1">
// <brk id="8" max="16383" man="1"/>
//</rowBreaks>
//<colBreaks count="1" manualBreakCount="1">
// <brk id="8" max="1048575" man="1"/>
//</colBreaks>
function write_ws_xml_pagesetup(setup) {
var pageSetup = writextag('pageSetup', null, {
scale: setup.scale || '100',
orientation: setup.orientation || 'portrait',
horizontalDpi : setup.horizontalDpi || '4294967292',
verticalDpi : setup.verticalDpi || '4294967292'
})
console.log(pageSetup);
return pageSetup;
}
function parse_ws_xml_hlinks(s, data, rels) {
@ -7849,6 +7857,7 @@ function write_ws_xml(idx, opts, wb) {
if(ws['!merges'] !== undefined && ws['!merges'].length > 0) o[o.length] = (write_ws_xml_merges(ws['!merges']));
if (ws['!pageSetup'] !== undefined) o[o.length] = write_ws_xml_pagesetup(ws['!pageSetup'])
if (ws['!rowBreaks'] !== undefined) o[o.length] = write_ws_xml_row_breaks(ws['!rowBreaks'])
if (ws['!colBreaks'] !== undefined) o[o.length] = write_ws_xml_col_breaks(ws['!colBreaks'])
@ -7871,11 +7880,12 @@ function write_ws_xml_col_breaks(breaks) {
var brk = [];
for (var i=0; i<breaks.length; i++) {
var thisBreak = ''+ (breaks[i]);
var nextBreak = '' + (breaks[i+1] || '16383');
var nextBreak = '' + (breaks[i+1] || '1048575');
brk.push(writextag('brk', null, {id: thisBreak, max: nextBreak, man: '1'}))
}
return writextag('colBreaks', brk.join(' '), {count: brk.length, manualBreakCount: brk.length})
}
/* [MS-XLSB] 2.4.718 BrtRowHdr */
function parse_BrtRowHdr(data, length) {
var z = [];