forked from sheetjs/sheetjs
- export `sheet_to_txt` (fixes #905 h/t @aj4mq) - BIFF4 Format Record aligned to BIFF 2/3 (fixes #909 h/t @ToujouAya) - updated CFB to 1.0.1 - typescript standalone demo - nexe / pkg xlsx.njs demo
1.8 KiB
1.8 KiB
Working with the Workbook
The full object format is described later in this README.
Reading a specific cell (click to show)
This example extracts the value stored in cell A1 from the first worksheet:
var first_sheet_name = workbook.SheetNames[0];
var address_of_cell = 'A1';
/* Get worksheet */
var worksheet = workbook.Sheets[first_sheet_name];
/* Find desired cell */
var desired_cell = worksheet[address_of_cell];
/* Get the value */
var desired_value = (desired_cell ? desired_cell.v : undefined);
Adding a new worksheet to a workbook (click to show)
This example uses XLSX.utils.aoa_to_sheet to make a
worksheet and appends the new worksheet to the workbook:
var new_ws_name = "SheetJS";
/* make worksheet */
var ws_data = [
[ "S", "h", "e", "e", "t", "J", "S" ],
[ 1 , 2 , 3 , 4 , 5 ]
];
var ws = XLSX.utils.aoa_to_sheet(ws_data);
/* Add the sheet name to the list */
wb.SheetNames.push(ws_name);
/* Load the worksheet object */
wb.Sheets[ws_name] = ws;
Parsing and Writing Examples
-
http://sheetjs.com/demos/modify.html read + modify + write files
-
https://github.com/SheetJS/js-xlsx/blob/master/bin/xlsx.njs node
The node version installs a command line tool xlsx which can read spreadsheet
files and output the contents in various formats. The source is available at
xlsx.njs in the bin directory.
Some helper functions in XLSX.utils generate different views of the sheets:
XLSX.utils.sheet_to_csvgenerates CSVXLSX.utils.sheet_to_txtgenerates UTF16 Formatted TextXLSX.utils.sheet_to_htmlgenerates HTMLXLSX.utils.sheet_to_jsongenerates an array of objectsXLSX.utils.sheet_to_formulaegenerates a list of formulae