if(typeof console === 'undefined') console = {log: function(){}};
var ext = typeof process !== 'undefined' && !!process.argv[2];
var data = [ [1, 2, 3], [true, false, null, "sheetjs"], ["foo bar", "baz", new Date("2014-02-19T14:30Z"), "0.3"], ["baz", null, "\u0BEE", 3.14159], ["hidden"], ["visible"]];if(isNaN(data[2][2].getYear())) data[2][2] = new Date(Date.UTC(2014, 1, 19, 14, 30, 0));
var ws_name = "SheetJS";
var wscols = [ {wch: 6}, {wpx: 50}, , {hidden: true} ];
var wsrows = [ {hpt: 12}, {hpx: 16}, , {hpx: 24, level:3}, {hidden: true}, {hidden: false}];
console.log("Sheet Name: " + ws_name);console.log("Data: ");var i = 0;for(i = 0; i !== data.length; ++i) console.log(data[i]);console.log("Columns :");for(i = 0; i !== wscols.length; ++i) console.log(wscols[i]);
if(typeof XLSX === "undefined") { try { XLSX = require('./'); } catch(e) { XLSX = require('../'); } }
var wb = XLSX.utils.book_new();
var ws = XLSX.utils.aoa_to_sheet(data, {cellDates:true});
XLSX.utils.book_append_sheet(wb, ws, ws_name);
ws['C1'].f = "A1+B1";ws['C2'] = {t:'n', f:"A1+B1"};
XLSX.utils.sheet_set_array_formula(ws, 'D1:D1', "SUM(A1:C1*A1:C1)");
XLSX.utils.sheet_set_array_formula(ws, 'E1:E4', "TRANSPOSE(A1:D1)");ws["!ref"] = "A1:E6";
ws['!cols'] = wscols;
ws['!rows'] = wsrows;
XLSX.utils.cell_set_internal_link(ws['A4'], "E2");XLSX.utils.cell_set_hyperlink(ws['A3'], "http://sheetjs.com", "Visit us <SheetJS.com!>");
XLSX.utils.cell_set_number_format(ws['B1'], "0%");
var custfmt = "\"This is \"\\ 0.0";XLSX.utils.cell_set_number_format(ws['C2'], custfmt);
ws['!margins'] = { left:1.0, right:1.0, top:1.0, bottom:1.0, header:0.5, footer:0.5 };
ws['!merges'] = [ XLSX.utils.decode_range("A6:C6") ];
console.log("JSON Data:");console.log(XLSX.utils.sheet_to_json(ws, {header:1}));
var data_2 = ["Hidden".split(""), [1,true,3,'a',,'c'], [2,false,true,'sh33t',,'j5']];XLSX.utils.book_append_sheet(wb, XLSX.utils.aoa_to_sheet(data_2), "Hidden");XLSX.utils.book_set_sheet_visibility(wb, "Hidden", XLSX.utils.consts.SHEET_HIDDEN);
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)};
XLSX.utils.cell_add_comment(ws['A4'], "I'm a little comment, short and stout!\n\nWell, Stout may be the wrong word", "SheetJS");
ws['!protect'] = { password:"password", formatRows:false, formatColumns:false, objects:true, scenarios:true};
if(!wb.Workbook) wb.Workbook = {Sheets:[], WBProps:{}};if(!wb.Workbook.WBProps) wb.Workbook.WBProps = {};wb.Workbook.WBProps.filterPrivacy = true;if(ext) wb.Workbook.Views = [{RTL:true}];
console.log("Worksheet Model:");console.log(ws);
var filenames = [ ['sheetjs.xlsx', {bookSST:true}], ['sheetjs.xlsm'], ['sheetjs.xlsb'], ['sheetjs.xlam'], ['sheetjs.biff8.xls', {bookType:'xls'}], ['sheetjs.biff5.xls', {bookType:'biff5'}], ['sheetjs.biff2.xls', {bookType:'biff2'}], ['sheetjs.xml.xls', {bookType:'xlml'}], ['sheetjs.xla'], ['sheetjs.ods'], ['sheetjs.fods'], ['sheetjs.csv'], ['sheetjs.txt'], ['sheetjs.slk'], ['sheetjs.eth'], ['sheetjs.htm'], ['sheetjs.dif'], ['sheetjs.dbf', {sheet:"Hidden"}], ['sheetjs.rtf'], ['sheetjs.prn']];
var OUT = ["base64", "binary", "string", "array"];if(typeof Buffer !== 'undefined') OUT.push("buffer");filenames.forEach(function(r) { XLSX.writeFile(wb, r[0], r[1]); if(typeof process !== 'undefined') XLSX.readFile(r[0]);
var ext = r[1] && r[1].bookType || r[0].split(".")[1]; ext = {"htm":"html"}[ext] || ext; OUT.forEach(function(type) { if(type == "string" && ["xlsx", "xlsm", "xlsb", "xlam", "biff8", "biff5", "biff2", "xla", "ods", "dbf"].indexOf(ext) > -1) return; if(type == "array" && ["xlsx", "xlsm", "xlsb", "xlam", "ods"].indexOf(ext) > -1 && typeof Uint8Array === 'undefined') return; var datout = XLSX.write(wb, {type: type, bookType: ext, sheet:r[1] && r[1].sheet || null}); XLSX.read(datout, {type:type}); if(type == "array") console.log(ext, datout); });});