@ -54,11 +54,12 @@ var paths = {
cstxlsb : dir + 'comments_stress_test.xlsb' ,
cstods : dir + 'comments_stress_test.ods' ,
cwxls : dir + 'column_width.xls x ',
cwxls : dir + 'column_width.xls ',
cwxls5 : dir + 'column_width.biff5' ,
cwxml : dir + 'column_width.xml' ,
cwxlsx : dir + 'column_width.xlsx' ,
cwxlsb : dir + 'column_width.xlsx' ,
cwxlsb : dir + 'column_width.xlsb' ,
cwslk : dir + 'column_width.slk' ,
dnsxls : dir + 'defined_names_simple.xls' ,
dnsxml : dir + 'defined_names_simple.xml' ,
@ -101,6 +102,13 @@ var paths = {
pmxlsx : dir + 'page_margins_2016.xlsx' ,
pmxlsb : dir + 'page_margins_2016.xlsb' ,
rhxls : dir + 'row_height.xls' ,
rhxls5 : dir + 'row_height.biff5' ,
rhxml : dir + 'row_height.xml' ,
rhxlsx : dir + 'row_height.xlsx' ,
rhxlsb : dir + 'row_height.xlsb' ,
rhslk : dir + 'row_height.slk' ,
svxls : dir + 'sheet_visibility.xls' ,
svxls5 : dir + 'sheet_visibility.xls' ,
svxml : dir + 'sheet_visibility.xml' ,
@ -113,6 +121,10 @@ var paths = {
swcxlsb : dir + '2013/apachepoi_SimpleWithComments.xlsx.xlsb'
} ;
var FSTPaths = [ paths . fstxls , paths . fstxml , paths . fstxlsx , paths . fstxlsb , paths . fstods ] ;
var NFPaths = [ paths . nfxls , paths . nfxml , paths . nfxlsx , paths . nfxlsb ] ;
var DTPaths = [ paths . dtxls , paths . dtxml , paths . dtxlsx , paths . dtxlsb ] ;
var N1 = 'XLSX' ;
var N2 = 'XLSB' ;
var N3 = 'XLS' ;
@ -144,7 +156,7 @@ function parsetest(x, wb, full, ext) {
describe ( x + ext + ' should generate JSON' , function ( ) {
wb . SheetNames . forEach ( function ( ws , i ) {
it ( '#' + i + ' (' + ws + ')' , function ( ) {
X . utils . sheet _to _ row_object _array ( wb . Sheets [ ws ] ) ;
X . utils . sheet _to _ json ( wb . Sheets [ ws ] ) ;
} ) ;
} ) ;
} ) ;
@ -284,7 +296,6 @@ describe('parse options', function() {
if ( typeof before != 'undefined' ) before ( bef ) ;
else it ( 'before' , bef ) ;
describe ( 'cell' , function ( ) {
var FSTPaths = [ paths . fstxls , paths . fstxml , paths . fstxlsx , paths . fstxlsb , paths . fstods ] ;
it ( 'XLSX should generate HTML by default' , function ( ) {
var wb = X . readFile ( paths . cstxlsx ) ;
var ws = wb . Sheets . Sheet1 ;
@ -348,7 +359,7 @@ describe('parse options', function() {
} ) ;
} ) ;
it ( 'should not generate number formats by default' , function ( ) {
[ paths . nfxls , paths . nfxlsx , paths . nfxlsb ] . forEach ( function ( p ) {
NFPaths . forEach ( function ( p ) {
var wb = X . readFile ( p ) ;
wb . SheetNames . forEach ( function ( s ) {
var ws = wb . Sheets [ s ] ;
@ -359,7 +370,7 @@ describe('parse options', function() {
} ) ;
} ) ;
it ( 'should generate number formats when requested' , function ( ) {
[ paths . nfxls , paths . nfxlsx , paths . nfxlsb ] . forEach ( function ( p ) {
NFPaths . forEach ( function ( p ) {
var wb = X . readFile ( p , { cellNF : true } ) ;
wb . SheetNames . forEach ( function ( s ) {
var ws = wb . Sheets [ s ] ;
@ -395,7 +406,7 @@ describe('parse options', function() {
} ) ;
} ) ;
it ( 'should not generate cell dates by default' , function ( ) {
[ paths . dtxlsx , paths . dtxlsb , paths . dtxls , paths . dtxml ] . forEach ( function ( p ) {
DTPaths . forEach ( function ( p ) {
var wb = X . readFile ( p ) ;
wb . SheetNames . forEach ( function ( s ) {
var ws = wb . Sheets [ s ] ;
@ -405,8 +416,8 @@ describe('parse options', function() {
} ) ;
} ) ;
} ) ;
it ( ' XLSX should generate cell dates when requested', function ( ) {
[ paths . dtxlsx , paths . dtxlsb , paths . dtxls , paths . dtxml ] . forEach ( function ( p ) {
it ( ' should generate cell dates when requested', function ( ) {
DTPaths . forEach ( function ( p ) {
var wb = X . readFile ( paths . dtxlsx , { cellDates : true } ) ;
var found = false ;
wb . SheetNames . forEach ( function ( s ) {
@ -818,7 +829,7 @@ describe('parse features', function() {
} ) ;
describe ( 'column properties' , function ( ) {
var wb1 , wb2 , wb3 , wb4 , wb5 ;
var wb1 , wb2 , wb3 , wb4 , wb5 , wb6 ;
var bef = ( function ( ) {
X = require ( modp ) ;
wb1 = X . readFile ( paths . cwxlsx , { cellStyles : true } ) ;
@ -826,21 +837,21 @@ describe('parse features', function() {
wb3 = X . readFile ( paths . cwxls , { cellStyles : true } ) ;
wb4 = X . readFile ( paths . cwxls5 , { cellStyles : true } ) ;
wb5 = X . readFile ( paths . cwxml , { cellStyles : true } ) ;
wb6 = X . readFile ( paths . cwslk , { cellStyles : true } ) ;
} ) ;
if ( typeof before != 'undefined' ) before ( bef ) ;
else it ( 'before' , bef ) ;
it ( 'should have "!cols"' , function ( ) {
assert ( wb1 . Sheets . Sheet1 [ '!cols' ] ) ;
assert ( wb2 . Sheets . Sheet1 [ '!cols' ] ) ;
assert ( wb3 . Sheets . Sheet1 [ '!cols' ] ) ;
assert ( wb4 . Sheets . Sheet1 [ '!cols' ] ) ;
assert ( wb5 . Sheets . Sheet1 [ '!cols' ] ) ;
[ wb1 , wb2 , wb3 , wb4 , wb5 , wb6 ] . forEach ( function ( wb ) { assert ( wb . Sheets . Sheet1 [ '!cols' ] ) ; } ) ;
} ) ;
it ( 'should have correct widths' , function ( ) {
/* SYLK rounds wch so skip non-integral */
[ wb1 , wb2 , wb3 , wb4 , wb5 ] . map ( function ( x ) { return x . Sheets . Sheet1 [ '!cols' ] ; } ) . forEach ( function ( x ) {
assert . equal ( x [ 1 ] . width , 0.1640625 ) ;
assert . equal ( x [ 2 ] . width , 16.6640625 ) ;
assert . equal ( x [ 3 ] . width , 1.6640625 ) ;
} ) ;
[ wb1 , wb2 , wb3 , wb4 , wb5 , wb6 ] . map ( function ( x ) { return x . Sheets . Sheet1 [ '!cols' ] ; } ) . forEach ( function ( x ) {
assert . equal ( x [ 4 ] . width , 4.83203125 ) ;
assert . equal ( x [ 5 ] . width , 8.83203125 ) ;
assert . equal ( x [ 6 ] . width , 12.83203125 ) ;
@ -848,10 +859,13 @@ describe('parse features', function() {
} ) ;
} ) ;
it ( 'should have correct pixels' , function ( ) {
/* SYLK rounds wch so skip non-integral */
[ wb1 , wb2 , wb3 , wb4 , wb5 ] . map ( function ( x ) { return x . Sheets . Sheet1 [ '!cols' ] ; } ) . forEach ( function ( x ) {
assert . equal ( x [ 1 ] . wpx , 1 ) ;
assert . equal ( x [ 2 ] . wpx , 100 ) ;
assert . equal ( x [ 3 ] . wpx , 10 ) ;
} ) ;
[ wb1 , wb2 , wb3 , wb4 , wb5 , wb6 ] . map ( function ( x ) { return x . Sheets . Sheet1 [ '!cols' ] ; } ) . forEach ( function ( x ) {
assert . equal ( x [ 4 ] . wpx , 29 ) ;
assert . equal ( x [ 5 ] . wpx , 53 ) ;
assert . equal ( x [ 6 ] . wpx , 77 ) ;
@ -860,6 +874,39 @@ describe('parse features', function() {
} ) ;
} ) ;
describe ( 'row properties' , function ( ) {
var wb1 , wb2 , wb3 , wb4 , wb5 , wb6 ;
var bef = ( function ( ) {
X = require ( modp ) ;
wb1 = X . readFile ( paths . rhxlsx , { cellStyles : true } ) ;
wb2 = X . readFile ( paths . rhxlsb , { cellStyles : true } ) ;
wb3 = X . readFile ( paths . rhxls , { cellStyles : true } ) ;
wb4 = X . readFile ( paths . rhxls5 , { cellStyles : true } ) ;
wb5 = X . readFile ( paths . rhxml , { cellStyles : true } ) ;
wb6 = X . readFile ( paths . rhslk , { cellStyles : true } ) ;
} ) ;
if ( typeof before != 'undefined' ) before ( bef ) ;
else it ( 'before' , bef ) ;
it ( 'should have "!rows"' , function ( ) {
[ wb1 , wb2 , wb3 , wb4 , wb5 , wb6 ] . forEach ( function ( wb ) { assert ( wb . Sheets . Sheet1 [ '!rows' ] ) ; } ) ;
} ) ;
it ( 'should have correct points' , function ( ) {
[ wb1 , wb2 , wb3 , wb4 , wb5 , wb6 ] . map ( function ( x ) { return x . Sheets . Sheet1 [ '!rows' ] ; } ) . forEach ( function ( x ) {
assert . equal ( x [ 1 ] . hpt , 1 ) ;
assert . equal ( x [ 2 ] . hpt , 10 ) ;
assert . equal ( x [ 3 ] . hpt , 100 ) ;
} ) ;
} ) ;
it ( 'should have correct pixels' , function ( ) {
[ wb1 , wb2 , wb3 , wb4 , wb5 , wb6 ] . map ( function ( x ) { return x . Sheets . Sheet1 [ '!rows' ] ; } ) . forEach ( function ( x ) {
/* note: at 96 PPI hpt == hpx */
assert . equal ( x [ 1 ] . hpx , 1 ) ;
assert . equal ( x [ 2 ] . hpx , 10 ) ;
assert . equal ( x [ 3 ] . hpx , 100 ) ;
} ) ;
} ) ;
} ) ;
describe ( 'merge cells' , function ( ) {
var wb1 , wb2 , wb3 , wb4 , wb5 ;
var bef = ( function ( ) {
@ -910,7 +957,7 @@ describe('parse features', function() {
var sheetName = 'Sheet1' ;
wb = X . readFile ( paths . dtxlsx ) ;
ws = wb . Sheets [ sheetName ] ;
var sheet = X . utils . sheet _to _ row_object _array ( ws ) ;
var sheet = X . utils . sheet _to _ json ( ws ) ;
assert . equal ( sheet [ 3 ] [ 'ใฆใใจ' ] , '2/14/14' ) ;
} ) ;
it ( 'cellDates should not affect formatted text' , function ( ) {
@ -1210,9 +1257,8 @@ describe('roundtrip features', function() {
} ) ;
} ) ; } ) ;
describe ( 'should preserve features' , function ( ) {
it ( 'merge cells' , function ( ) {
[ "xlsx" , "xlsb" , "xlml" , "ods" ] . forEach ( function ( f ) {
describe ( 'should preserve merge cells' , function ( ) {
[ "xlsx" , "xlsb" , "xlml" , "ods" ] . forEach ( function ( f ) { it ( f , function ( ) {
var wb1 = X . readFile ( paths . mcxlsx ) ;
var wb2 = X . read ( X . write ( wb1 , { bookType : f , type : 'binary' } ) , { type : 'binary' } ) ;
var m1 = wb1 . Sheets . Merge [ '!merges' ] . map ( X . utils . encode _range ) ;
@ -1311,6 +1357,39 @@ describe('roundtrip features', function() {
} ) ;
} ) ;
describe ( 'should preserve column properties' , function ( ) { [
'xlml' , /*'biff2', */ 'xlsx' , 'xlsb' , 'slk'
] . forEach ( function ( w ) { it ( w , function ( ) {
var ws1 = X . utils . aoa _to _sheet ( [ [ "hpx12" , "hpt24" , "hpx48" , "hidden" ] ] ) ;
ws1 [ '!cols' ] = [ { wch : 9 } , { wpx : 100 } , { width : 80 } , { hidden : true } ] ;
var wb1 = { SheetNames : [ "Sheet1" ] , Sheets : { Sheet1 : ws1 } } ;
var wb2 = X . read ( X . write ( wb1 , { bookType : w , type : "buffer" } ) , { type : "buffer" , cellStyles : true } ) ;
var ws2 = wb2 . Sheets . Sheet1 ;
assert . equal ( ws2 [ '!cols' ] [ 3 ] . hidden , true ) ;
assert . equal ( ws2 [ '!cols' ] [ 0 ] . wch , 9 ) ;
if ( w == 'slk' ) return ;
assert . equal ( ws2 [ '!cols' ] [ 1 ] . wpx , 100 ) ;
/* xlml stores integral pixels -> approximate width */
if ( w == 'xlml' ) assert . equal ( Math . round ( ws2 [ '!cols' ] [ 2 ] . width ) , 80 ) ;
else assert . equal ( ws2 [ '!cols' ] [ 2 ] . width , 80 ) ;
} ) ; } ) ;
} ) ;
describe ( 'should preserve row properties' , function ( ) { [
'xlml' , /*'biff2', */ 'xlsx' , 'xlsb' , 'slk'
] . forEach ( function ( w ) { it ( w , function ( ) {
var ws1 = X . utils . aoa _to _sheet ( [ [ "hpx12" ] , [ "hpt24" ] , [ "hpx48" ] , [ "hidden" ] ] ) ;
ws1 [ '!rows' ] = [ { hpx : 12 } , { hpt : 24 } , { hpx : 48 } , { hidden : true } ] ;
var wb1 = { SheetNames : [ "Sheet1" ] , Sheets : { Sheet1 : ws1 } } ;
var wb2 = X . read ( X . write ( wb1 , { bookType : w , type : "buffer" } ) , { type : "buffer" , cellStyles : true } ) ;
var ws2 = wb2 . Sheets . Sheet1 ;
assert . equal ( ws2 [ '!rows' ] [ 0 ] . hpx , 12 ) ;
assert . equal ( ws2 [ '!rows' ] [ 1 ] . hpt , 24 ) ;
assert . equal ( ws2 [ '!rows' ] [ 2 ] . hpx , 48 ) ;
assert . equal ( ws2 [ '!rows' ] [ 3 ] . hidden , true ) ;
} ) ; } ) ;
} ) ;
describe ( 'should preserve cell comments' , function ( ) { [
[ 'xlsx' , paths . cstxlsx ] ,
[ 'xlsb' , paths . cstxlsb ] ,