Add freeze pane option

This commit is contained in:
Pieter Sheth-Voss 2017-04-02 22:53:03 -04:00
parent 1903cff791
commit 9edf279467
14 changed files with 193 additions and 58 deletions

@ -437,6 +437,15 @@ The following properties are currently used when generating an XLSX file, but no
- `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'}
- `ws['!printHeader']`: array of first and last row indexes for repeat header on printing, e.g. `[1,1]` to repeat just first row
- `ws['!freeze']`: string cell reference for breakpoint, e.g. the following will freeze the first row and first column:
{
xSplit: "1",
ySplit: "1",
topLeftCell: "B2",
activePane: "bottomRight",
state: "frozen"
}
### Workbook Object
@ -540,21 +549,21 @@ top-level attributes: `fill`, `font`, `numFmt`, `alignment`, and `border`.
| font | name | `"Calibri"` // default
| | sz | `"11"` // font size in points
| | color | `COLOR_SPEC`
| | bold | `true || false`
| | underline | `true || false`
| | italic | `true || false`
| | strike | `true || false`
| | outline | `true || false`
| | shadow | `true || false`
| | vertAlign | `true || false`
| | bold | `true` or `false`
| | underline | `true` or `false`
| | italic | `true` or `false`
| | strike | `true` or `false`
| | outline | `true` or `false`
| | shadow | `true` or `false`
| | vertAlign | `true` or `false`
| numFmt | | `"0"` // integer index to built in formats, see StyleBuilder.SSF property
| | | `"0.00%"` // string matching a built-in format, see StyleBuilder.SSF
| | | `"0.0%"` // string specifying a custom format
| | | `"0.00%;\\(0.00%\\);\\-;@"` // string specifying a custom format, escaping special characters
| | | `"m/dd/yy"` // string a date format using Excel's format notation
| alignment | vertical | `"bottom"||"center"||"top"`
| | horizontal | `"bottom"||"center"||"top"`
| | wrapText | `true || false`
| alignment | vertical | `"bottom"` or `"center"` or `"top"`
| | horizontal | `"bottom"` or `"center"` or `"top"`
| | wrapText | `true ` or ` false`
| | readingOrder | `2` // for right-to-left
| | textRotation | Number from `0` to `180` or `255` (default is `0`)
| | | `90` is rotated up 90 degrees
@ -567,8 +576,8 @@ top-level attributes: `fill`, `font`, `numFmt`, `alignment`, and `border`.
| | left | `{ style: BORDER_STYLE, color: COLOR_SPEC }`
| | right | `{ style: BORDER_STYLE, color: COLOR_SPEC }`
| | diagonal | `{ style: BORDER_STYLE, color: COLOR_SPEC }`
| | diagonalUp | `true||false`
| | diagonalDown | `true||false`
| | diagonalUp | `true` or `false`
| | diagonalDown | `true` or `false`
**COLOR_SPEC**: Colors for `fill`, `font`, and `border` are specified as objects, either:

@ -1 +1 @@
XLSX.version = '0.8.16';
XLSX.version = '0.8.17';

@ -238,7 +238,7 @@ return function parse_ws_xml_data(sdata, s, opts, guess) {
if(isNaN(p.v)) p.v = "" // we don't want NaN if p.v is null
break;
case 's':
if (!p.hasOwnProperty('v')) continue;
// if (!p.hasOwnProperty('v')) continue;
sstr = strs[parseInt(p.v, 10)];
p.v = sstr.t;
p.r = sstr.r;
@ -308,7 +308,12 @@ 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, {
var pane = '';
if (ws['!freeze']) {
pane = writextag('pane',null, ws['!freeze'])
}
var sheetView = writextag('sheetView', pane, {
showGridLines: opts.showGridLines == false ? '0' : '1',
tabSelected: opts.tabSelected === undefined ? '0' : opts.tabSelected, // see issue #26, need to set WorkbookViews if this is set
workbookViewId: opts.workbookViewId === undefined ? '0' : opts.workbookViewId

@ -2,7 +2,7 @@
"name": "js-xlsx",
"homepage": "https://github.com/SheetJS/js-xlsx",
"main": "dist/xlsx.js",
"version": "0.8.16",
"version": "0.8.17",
"ignore": [
"bin",
"bits",

18
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

22
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

21
dist/xlsx.js vendored

@ -4,7 +4,7 @@
/*jshint funcscope:true, eqnull:true */
var XLSX = {};
(function make_xlsx(XLSX){
XLSX.version = '0.8.16';
XLSX.version = '0.8.17';
var current_codepage = 1200, current_cptable;
if(typeof module !== "undefined" && typeof require !== 'undefined') {
if(typeof cptable === 'undefined') cptable = require('./dist/cpexcel');
@ -1314,8 +1314,14 @@ function getdata(data) {
function safegetzipfile(zip, file) {
var f = file; if(zip.files[f]) return zip.files[f];
f = file.toLowerCase(); if(zip.files[f]) return zip.files[f];
f = f.replace(/\//g,'\\'); if(zip.files[f]) return zip.files[f];
var lowerCaseFiles = {};
for (var key in zip.files) {
lowerCaseFiles[key.toLowerCase()] = zip.files[key];
}
f = file.toLowerCase(); if(lowerCaseFiles[f]) return lowerCaseFiles[f];
f = f.replace(/\//g,'\\'); if(lowerCaseFiles[f]) return lowerCaseFiles[f];
return null;
}
@ -7770,7 +7776,7 @@ return function parse_ws_xml_data(sdata, s, opts, guess) {
if(isNaN(p.v)) p.v = "" // we don't want NaN if p.v is null
break;
case 's':
if (!p.hasOwnProperty('v')) continue;
// if (!p.hasOwnProperty('v')) continue;
sstr = strs[parseInt(p.v, 10)];
p.v = sstr.t;
p.r = sstr.r;
@ -7840,7 +7846,12 @@ 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, {
var pane = '';
if (ws['!freeze']) {
pane = writextag('pane',null, ws['!freeze'])
}
var sheetView = writextag('sheetView', pane, {
showGridLines: opts.showGridLines == false ? '0' : '1',
tabSelected: opts.tabSelected === undefined ? '0' : opts.tabSelected, // see issue #26, need to set WorkbookViews if this is set
workbookViewId: opts.workbookViewId === undefined ? '0' : opts.workbookViewId

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",
"version": "0.8.16",
"version": "0.8.17",
"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" ],

105
tests/test-freeze.js Normal file

@ -0,0 +1,105 @@
var XLSX = require('../.');
var JSZip = require('jszip');
var fs = require('fs');
var cheerio = require('cheerio');
var assert = require('assert');
function JSDateToExcelDate(inDate) {
return 25569.0 + ((inDate.getTime() - (inDate.getTimezoneOffset() * 60 * 1000)) / (1000 * 60 * 60 * 24));
}
var defaultCellStyle = { font: { name: "Verdana", sz: 11, color: "FF00FF88"}, fill: {fgColor: {rgb: "FFFFAA00"}}};
//"A1": {v: "Header", s: { border: { top: { style: 'medium', color: { rgb: "FFFFAA00"}}, left: { style: 'medium', color: { rgb: "FFFFAA00"}} }}},
var workbook = {
SheetNames : ["Sheet1"],
Sheets: {
"Sheet1": {
"A1": {v: "Header"},
"A2": {v: "Anchorage"},
"A3": {v: "Anchorage"},
"A4": {v: "Boston"},
"A5": {v: "Chicago"},
"A6": {v: "Dayton"},
"A7": {v: "East Lansing"},
"A8": {v: "Fargo"},
"A9": {v: "Galena"},
"A10": {v: "Iowa City"},
"A11": {v: "Jacksonville"},
"A12": {v: "Jacksonville"},
"A13": {v: "Jacksonville"},
"A14": {v: "Jacksonville"},
"A15": {v: "Jacksonville"},
"A16": {v: "Jacksonville"},
"A17": {v: "Jacksonville"},
"A18": {v: "Jacksonville"},
"A19": {v: "Jacksonville"},
"A20": {v: "Jacksonville"},
"A21": {v: "Jacksonville"},
"A22": {v: "Jacksonville"},
"A23": {v: "Jacksonville"},
"A24": {v: "Jacksonville"},
"A25": {v: "Jacksonville"},
"A26": {v: "Jacksonville"},
"A27": {v: "Jacksonville"},
"A28": {v: "Jacksonville"},
"A29": {v: "Jacksonville"},
"A30": {v: "Jacksonville"},
"A31": {v: "Jacksonville"},
"A32": {v: "Jacksonville"},
"A33": {v: "Jacksonville"},
"A34": {v: "Jacksonville"},
"A35": {v: "Jacksonville"},
"A36": {v: "Jacksonville"},
"A37": {v: "Jacksonville"},
"A38": {v: "Jacksonville"},
"A39": {v: "Jacksonville"},
"A40": {v: "Jacksonville"},
"A41": {v: "Jacksonville"},
"A42": {v: "Jacksonville"},
"A43": {v: "Jacksonville"},
"A44": {v: "Jacksonville"},
"A45": {v: "Jacksonville"},
"A46": {v: "Jacksonville"},
"A47": {v: "Jacksonville"},
"A48": {v: "Jacksonville"},
"A49": {v: "Jacksonville"},
"A50": {v: "Jacksonville"},
"A51": {v: "Jacksonville"},
"A52": {v: "Jacksonville"},
"A53": {v: "Jacksonville"},
"A54": {v: "Jacksonville"},
"A55": {v: "Jacksonville"},
"A56": {v: "Jacksonville"},
"A57": {v: "Jacksonville"},
"A58": {v: "Jacksonville"},
"A59": {v: "Jacksonville"},
"!ref":"A1:A59",
"!printHeader":[1,1],
"!freeze":{
xSplit: "1",
ySplit: "1",
topLeftCell: "B2",
activePane: "bottomRight",
state: "frozen"
}
}
}
};
describe('repeats header', function () {
it ('repeats header', function() {
var OUTFILE = '/tmp/freeze.xlsx';
var OUTFILE = './lab/freeze/freeze.xlsx'
// write the file and read it back...
XLSX.writeFile(workbook, OUTFILE, {bookType: 'xlsx', bookSST: false});
console.log("open \""+OUTFILE+"\"")
});
});

11
xlsx.js

@ -4,7 +4,7 @@
/*jshint funcscope:true, eqnull:true */
var XLSX = {};
(function make_xlsx(XLSX){
XLSX.version = '0.8.16';
XLSX.version = '0.8.17';
var current_codepage = 1200, current_cptable;
if(typeof module !== "undefined" && typeof require !== 'undefined') {
if(typeof cptable === 'undefined') cptable = require('./dist/cpexcel');
@ -7776,7 +7776,7 @@ return function parse_ws_xml_data(sdata, s, opts, guess) {
if(isNaN(p.v)) p.v = "" // we don't want NaN if p.v is null
break;
case 's':
if (!p.hasOwnProperty('v')) continue;
// if (!p.hasOwnProperty('v')) continue;
sstr = strs[parseInt(p.v, 10)];
p.v = sstr.t;
p.r = sstr.r;
@ -7846,7 +7846,12 @@ 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, {
var pane = '';
if (ws['!freeze']) {
pane = writextag('pane',null, ws['!freeze'])
}
var sheetView = writextag('sheetView', pane, {
showGridLines: opts.showGridLines == false ? '0' : '1',
tabSelected: opts.tabSelected === undefined ? '0' : opts.tabSelected, // see issue #26, need to set WorkbookViews if this is set
workbookViewId: opts.workbookViewId === undefined ? '0' : opts.workbookViewId