| 
									
										
										
										
											2014-06-05 07:06:20 +00:00
										 |  |  | /* writing feature test -- look for TEST: in comments */ | 
					
						
							|  |  |  | /* vim: set ts=2: */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* original data */ | 
					
						
							|  |  |  | var data = [ | 
					
						
							|  |  |  | 	[1,2,3], | 
					
						
							|  |  |  | 	[true, false, null, "sheetjs"], | 
					
						
							|  |  |  | 	["foo","bar",new Date("2014-02-19T14:30Z"), "0.3"], | 
					
						
							| 
									
										
										
										
											2017-03-31 03:57:11 +00:00
										 |  |  | 	["baz", null, "qux", 3.14159], | 
					
						
							|  |  |  | 	["hidden"], | 
					
						
							|  |  |  | 	["visible"] | 
					
						
							| 
									
										
										
										
											2014-06-05 07:06:20 +00:00
										 |  |  | ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var ws_name = "SheetJS"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var wscols = [ | 
					
						
							| 
									
										
										
										
											2017-03-28 22:03:03 +00:00
										 |  |  | 	{wch:6}, // "characters"
 | 
					
						
							|  |  |  | 	{wpx:50}, // "pixels"
 | 
					
						
							| 
									
										
										
										
											2014-06-05 07:06:20 +00:00
										 |  |  | 	{wch:10}, | 
					
						
							| 
									
										
										
										
											2017-03-28 22:03:03 +00:00
										 |  |  | 	{wpx:125} | 
					
						
							| 
									
										
										
										
											2014-06-05 07:06:20 +00:00
										 |  |  | ]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-31 03:57:11 +00:00
										 |  |  | var wsrows = []; | 
					
						
							|  |  |  | wsrows[0] = {hpt: 12}; // "points"
 | 
					
						
							|  |  |  | wsrows[1] = {hpx: 16}; // "pixels"
 | 
					
						
							|  |  |  | wsrows[2] = {hpt: 18}; | 
					
						
							|  |  |  | wsrows[3] = {hpx: 24}; | 
					
						
							|  |  |  | wsrows[4] = {hidden:true}; // hide row
 | 
					
						
							|  |  |  | wsrows[5] = {hidden:false}; | 
					
						
							| 
									
										
										
										
											2014-06-05 07:06:20 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | console.log("Sheet Name: " + ws_name); | 
					
						
							|  |  |  | console.log("Data: "); for(var i=0; i!=data.length; ++i) console.log(data[i]); | 
					
						
							|  |  |  | console.log("Columns :"); for(i=0; i!=wscols.length;++i) console.log(wscols[i]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* require XLSX */ | 
					
						
							|  |  |  | if(typeof XLSX === "undefined") { try { XLSX = require('./'); } catch(e) { XLSX = require('../'); } } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-28 22:03:03 +00:00
										 |  |  | /* blank workbook constructor */ | 
					
						
							|  |  |  | var wb = { SheetNames: [], Sheets: {} }; | 
					
						
							| 
									
										
										
										
											2014-06-05 07:06:20 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* convert an array of arrays in JS to a CSF spreadsheet */ | 
					
						
							| 
									
										
										
										
											2017-04-10 05:10:54 +00:00
										 |  |  | var ws = XLSX.utils.aoa_to_sheet(data, {cellDates:true, dense:false}); | 
					
						
							| 
									
										
										
										
											2014-06-05 07:06:20 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* TEST: add worksheet to workbook */ | 
					
						
							|  |  |  | wb.SheetNames.push(ws_name); | 
					
						
							|  |  |  | wb.Sheets[ws_name] = ws; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-18 00:45:06 +00:00
										 |  |  | /* TEST: simple formula */ | 
					
						
							|  |  |  | ws['C1'].f = "A1+B1"; | 
					
						
							|  |  |  | ws['C2'] = {t:'n', f:"A1+B1"}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* TEST: single-cell array formula */ | 
					
						
							|  |  |  | ws['D1'] = {t:'n', f:"SUM(A1:C1*A1:C1)", F:"D1:D1"}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* TEST: multi-cell array formula */ | 
					
						
							|  |  |  | ws['E1'] = {t:'n', f:"TRANSPOSE(A1:D1)", F:"E1:E4"}; | 
					
						
							|  |  |  | ws['E2'] = {t:'n', F:"E1:E4"}; | 
					
						
							|  |  |  | ws['E3'] = {t:'n', F:"E1:E4"}; | 
					
						
							|  |  |  | ws['E4'] = {t:'n', F:"E1:E4"}; | 
					
						
							| 
									
										
										
										
											2017-03-31 03:57:11 +00:00
										 |  |  | ws["!ref"] = "A1:E6"; | 
					
						
							| 
									
										
										
										
											2017-03-18 00:45:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-31 03:57:11 +00:00
										 |  |  | /* TEST: column props */ | 
					
						
							| 
									
										
										
										
											2014-06-05 07:06:20 +00:00
										 |  |  | ws['!cols'] = wscols; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-31 03:57:11 +00:00
										 |  |  | /* TEST: row props */ | 
					
						
							|  |  |  | ws['!rows'] = wsrows; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-28 22:03:03 +00:00
										 |  |  | /* TEST: hyperlink note: Excel does not automatically style hyperlinks */ | 
					
						
							|  |  |  | ws['A3'].l = { Target: "http://sheetjs.com", Tooltip: "Visit us <SheetJS.com!>" }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* TEST: built-in format */ | 
					
						
							| 
									
										
										
										
											2017-04-03 00:16:03 +00:00
										 |  |  | ws['B1'].z = "0%"; // Format Code 9
 | 
					
						
							| 
									
										
										
										
											2017-03-28 22:03:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* TEST: custom format */ | 
					
						
							|  |  |  | //ws['B2'].z = "0.0"; wb.SSF[60] = "0.0"; // Custom
 | 
					
						
							| 
									
										
										
										
											2017-04-03 00:16:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-13 01:29:38 +00:00
										 |  |  | /* TEST: page margins */ | 
					
						
							|  |  |  | ws['!margins'] =  { left:1.0, right:1.0, top:1.0, bottom:1.0, header:0.5, footer:0.5 }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-03 00:16:03 +00:00
										 |  |  | console.log("JSON Data:");console.log(XLSX.utils.sheet_to_json(ws, {header:1})); | 
					
						
							| 
									
										
										
										
											2017-03-18 00:45:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-31 18:46:42 +00:00
										 |  |  | /* TEST: hidden sheets */ | 
					
						
							|  |  |  | wb.SheetNames.push("Hidden"); | 
					
						
							|  |  |  | wb.Sheets["Hidden"] = XLSX.utils.aoa_to_sheet(["Hidden".split(""), [1,2,3]]); | 
					
						
							|  |  |  | wb.Workbook = {Sheets:[]}; | 
					
						
							|  |  |  | wb.Workbook.Sheets[1] = {Hidden:1}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-01 07:32:12 +00:00
										 |  |  | /* TEST: properties */ | 
					
						
							|  |  |  | wb.Props = { | 
					
						
							|  |  |  | 	Title: "SheetJS Test", | 
					
						
							|  |  |  | 	Subject: "Tests", | 
					
						
							|  |  |  | 	Author: "Devs at SheetJS", | 
					
						
							|  |  |  | 	Manager: "Sheet Manager", | 
					
						
							|  |  |  | 	Company: "SheetJS", | 
					
						
							|  |  |  | 	Category: "Experimentation", | 
					
						
							|  |  |  | 	Keywords: "Test", | 
					
						
							|  |  |  | 	Comments: "Nothing to say here", | 
					
						
							|  |  |  | 	LastAuthor: "Not SheetJS", | 
					
						
							|  |  |  | 	CreatedDate: new Date(2017,1,19) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-02 06:47:25 +00:00
										 |  |  | /* TEST: comments */ | 
					
						
							|  |  |  | ws['A4'].c = []; | 
					
						
							| 
									
										
										
										
											2017-04-03 00:16:03 +00:00
										 |  |  | ws['A4'].c.push({a:"SheetJS",t:"I'm a little comment, short and stout!\n\nWell, Stout may be the wrong word"}); | 
					
						
							| 
									
										
										
										
											2017-04-02 06:47:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-04 18:41:11 +00:00
										 |  |  | /* TEST: sheet protection */ | 
					
						
							|  |  |  | ws['!protect'] = { | 
					
						
							|  |  |  | 	password:"password", | 
					
						
							|  |  |  | 	objects:1, | 
					
						
							|  |  |  | 	scenarios:1 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-02 06:47:25 +00:00
										 |  |  | console.log("Worksheet Model:") | 
					
						
							|  |  |  | console.log(ws); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-05 07:06:20 +00:00
										 |  |  | /* write file */ | 
					
						
							| 
									
										
										
										
											2017-03-18 00:45:06 +00:00
										 |  |  | XLSX.writeFile(wb, 'sheetjs.xlsx', {bookSST:true}); | 
					
						
							| 
									
										
										
										
											2017-02-03 20:50:45 +00:00
										 |  |  | XLSX.writeFile(wb, 'sheetjs.xlsm'); | 
					
						
							| 
									
										
										
										
											2017-03-18 00:45:06 +00:00
										 |  |  | XLSX.writeFile(wb, 'sheetjs.xlsb'); // no formula
 | 
					
						
							|  |  |  | XLSX.writeFile(wb, 'sheetjs.xls', {bookType:'biff2'}); // no formula
 | 
					
						
							|  |  |  | XLSX.writeFile(wb, 'sheetjs.xml.xls', {bookType:'xlml'}); | 
					
						
							| 
									
										
										
										
											2017-02-03 20:50:45 +00:00
										 |  |  | XLSX.writeFile(wb, 'sheetjs.ods'); | 
					
						
							| 
									
										
										
										
											2017-02-22 06:57:59 +00:00
										 |  |  | XLSX.writeFile(wb, 'sheetjs.fods'); | 
					
						
							| 
									
										
										
										
											2017-04-01 07:32:12 +00:00
										 |  |  | XLSX.writeFile(wb, 'sheetjs.slk'); | 
					
						
							| 
									
										
										
										
											2017-02-22 06:57:59 +00:00
										 |  |  | XLSX.writeFile(wb, 'sheetjs.csv'); | 
					
						
							| 
									
										
										
										
											2017-04-03 00:16:03 +00:00
										 |  |  | XLSX.writeFile(wb, 'sheetjs.txt'); | 
					
						
							|  |  |  | XLSX.writeFile(wb, 'sheetjs.prn'); | 
					
						
							| 
									
										
										
										
											2017-04-04 16:09:41 +00:00
										 |  |  | XLSX.writeFile(wb, 'sheetjs.dif'); | 
					
						
							| 
									
										
										
										
											2017-02-24 10:33:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* test by reading back files */ | 
					
						
							|  |  |  | XLSX.readFile('sheetjs.xlsx'); | 
					
						
							|  |  |  | XLSX.readFile('sheetjs.xlsm'); | 
					
						
							|  |  |  | XLSX.readFile('sheetjs.xlsb'); | 
					
						
							|  |  |  | XLSX.readFile('sheetjs.xls'); | 
					
						
							| 
									
										
										
										
											2017-03-18 00:45:06 +00:00
										 |  |  | XLSX.readFile('sheetjs.xml.xls'); | 
					
						
							| 
									
										
										
										
											2017-02-24 10:33:01 +00:00
										 |  |  | XLSX.readFile('sheetjs.ods'); | 
					
						
							|  |  |  | XLSX.readFile('sheetjs.fods'); | 
					
						
							| 
									
										
										
										
											2017-04-01 07:32:12 +00:00
										 |  |  | XLSX.readFile('sheetjs.slk'); | 
					
						
							| 
									
										
										
										
											2017-04-04 16:09:41 +00:00
										 |  |  | XLSX.readFile('sheetjs.csv'); | 
					
						
							|  |  |  | XLSX.readFile('sheetjs.txt'); | 
					
						
							| 
									
										
										
										
											2017-04-03 00:16:03 +00:00
										 |  |  | XLSX.readFile('sheetjs.prn'); | 
					
						
							| 
									
										
										
										
											2017-04-04 16:09:41 +00:00
										 |  |  | XLSX.readFile('sheetjs.dif'); |