forked from sheetjs/sheetjs
		
	numbers OperationStorage iwa warning
This commit is contained in:
		
							parent
							
								
									ba94ffba35
								
							
						
					
					
						commit
						d55b7a3063
					
				| @ -443,6 +443,8 @@ var SYLK = /*#__PURE__*/(function() { | ||||
| 				} | ||||
| 				wb.Workbook.Names.push(nn); | ||||
| 			} break; | ||||
| 			// case 'NE': // ??
 | ||||
| 			// case 'NU': // ??
 | ||||
| 			case 'C': /* cell */ | ||||
| 			var C_seen_K = false, C_seen_X = false, C_seen_S = false, C_seen_E = false, _R = -1, _C = -1, formula = "", cell_t = "z"; | ||||
| 			for(rj=1; rj<record.length; ++rj) switch(record[rj].charAt(0)) { | ||||
| @ -476,6 +478,8 @@ var SYLK = /*#__PURE__*/(function() { | ||||
| 				case 'G': break; // unknown
 | ||||
| 				case 'R': _R = parseInt(record[rj].slice(1), 10)-1; break; | ||||
| 				case 'C': _C = parseInt(record[rj].slice(1), 10)-1; break; | ||||
| 				// case 'P': // ??
 | ||||
| 				// case 'D': // ??
 | ||||
| 				default: if(opts && opts.WTF) throw new Error("SYLK bad record " + rstr); | ||||
| 			} | ||||
| 			if(C_seen_K) { | ||||
| @ -529,6 +533,8 @@ var SYLK = /*#__PURE__*/(function() { | ||||
| 					if(Mval > 0) { rowinfo[R].hpt = Mval; rowinfo[R].hpx = pt2px(Mval); } | ||||
| 					else if(Mval === 0) rowinfo[R].hidden = true; | ||||
| 					break; | ||||
| 				// case 'K': // ??
 | ||||
| 				// case 'E': // ??
 | ||||
| 				default: if(opts && opts.WTF) throw new Error("SYLK bad record " + rstr); | ||||
| 			} | ||||
| 			if(F_seen < 1) next_cell_format = null; break; | ||||
|  | ||||
| @ -827,6 +827,8 @@ function parse_numbers_iwa(cfb, opts) { | ||||
|   cfb.FileIndex.forEach(function(s) { | ||||
|     if (!s.name.match(/\.iwa$/)) | ||||
|       return; | ||||
|     if (s.content[0] == 98) | ||||
|       return; | ||||
|     var o; | ||||
|     try { | ||||
|       o = decompress_iwa_file(s.content); | ||||
|  | ||||
| @ -26,12 +26,12 @@ can be installed with Bash on Windows or with `cygwin`. | ||||
| - [`IndexedDB`](https://docs.sheetjs.com/docs/getting-started/demos/database#indexeddb) | ||||
| 
 | ||||
| **Frameworks** | ||||
| - [`angularjs`](angular/) | ||||
| - [`angular and ionic`](angular2/) | ||||
| - [`knockout`](knockout/) | ||||
| - [`meteor`](meteor/) | ||||
| - [`react, react-native, next`](react/) | ||||
| - [`vue 2.x, weex, nuxt`](vue/) | ||||
| - [`Angular.JS`](angular/) | ||||
| - [`Angular 2+ and Ionic`](angular2/) | ||||
| - [`Knockout`](https://docs.sheetjs.com/docs/getting-started/demos/legacy#knockoutjs) | ||||
| - [`Meteor`](meteor/) | ||||
| - [`React, React Native and NextJS`](react/) | ||||
| - [`VueJS, WeeX and NuxtJS`](vue/) | ||||
| 
 | ||||
| **Front-End UI Components** | ||||
| - [`canvas-datagrid`](datagrid/) | ||||
| @ -42,16 +42,16 @@ can be installed with Bash on Windows or with `cygwin`. | ||||
| **Platforms and Integrations** | ||||
| - [`NodeJS Server-Side Processing`](server/) | ||||
| - [`Deno`](deno/) | ||||
| - [`electron application`](electron/) | ||||
| - [`Electron`](electron/) | ||||
| - [`NW.js`](nwjs/) | ||||
| - [`Chrome / Chromium extensions`](chrome/) | ||||
| - [`Chrome / Chromium Extension`](chrome/) | ||||
| - [`Google Sheets API`](https://docs.sheetjs.com/docs/getting-started/demos/gsheet) | ||||
| - [`ExtendScript for Adobe Apps`](https://docs.sheetjs.com/docs/getting-started/demos/extendscript) | ||||
| - [`NetSuite SuiteScript`](https://docs.sheetjs.com/docs/getting-started/demos/netsuite) | ||||
| - [`SalesForce Lightning Web Components`](https://docs.sheetjs.com/docs/getting-started/demos/salesforce) | ||||
| - [`Excel JavaScript API`](https://docs.sheetjs.com/docs/getting-started/demos/excel) | ||||
| - [`Headless Automation`](https://docs.sheetjs.com/docs/getting-started/demos/headless) | ||||
| - [`Swift JSC and other engines`](altjs/) | ||||
| - [`Swift JSC and Other JavaScript Engines`](altjs/) | ||||
| - [`"serverless" functions`](function/) | ||||
| - [`databases and key/value stores`](database/) | ||||
| - [`Databases and Structured Data Stores`](https://docs.sheetjs.com/docs/getting-started/demos/database) | ||||
| @ -63,12 +63,15 @@ can be installed with Bash on Windows or with `cygwin`. | ||||
| - [`bun`](https://docs.sheetjs.com/docs/getting-started/demos/bundler#bun) | ||||
| - [`esbuild`](https://docs.sheetjs.com/docs/getting-started/demos/bundler#esbuild) | ||||
| - [`parcel`](https://docs.sheetjs.com/docs/getting-started/demos/bundler#parcel) | ||||
| - [`requirejs`](requirejs/) | ||||
| - [`rollup`](rollup/) | ||||
| - [`requirejs`](https://docs.sheetjs.com/docs/getting-started/demos/bundler#requirejs) | ||||
| - [`rollup`](https://docs.sheetjs.com/docs/getting-started/demos/bundler#rollup) | ||||
| - [`snowpack`](https://docs.sheetjs.com/docs/getting-started/demos/bundler#snowpack) | ||||
| - [`swc`](https://docs.sheetjs.com/docs/getting-started/demos/bundler#swc) | ||||
| - [`systemjs`](systemjs/) | ||||
| - [`typescript`](typescript/) | ||||
| - [`vite`](https://docs.sheetjs.com/docs/getting-started/demos/bundler#vite) | ||||
| - [`webpack 2.x`](webpack/) | ||||
| - [`wmr`](https://docs.sheetjs.com/docs/getting-started/demos/bundler#wmr) | ||||
| 
 | ||||
| Other examples are included in the [showcase](demos/showcase/). | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										1
									
								
								demos/deno/.gitignore
									
									
									
									
										vendored
									
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										1
									
								
								demos/deno/.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -1 +0,0 @@ | ||||
| sheet2csv | ||||
| @ -1,24 +0,0 @@ | ||||
| TESTS= x mjs | ||||
| UNSTABLE= node | ||||
| TEST_FILES=number_format_greek.xls | ||||
| 
 | ||||
| .PHONY: test | ||||
| test: $(UNSTABLE) $(TESTS) | ||||
| 
 | ||||
| .PHONY: sheet2csv | ||||
| sheet2csv: sheet2csv.ts | ||||
| 	deno compile -r --allow-read $< | ||||
| 
 | ||||
| $(TESTS): %: %.ts doit.ts $(TEST_FILES) | ||||
| 	deno run --allow-read --allow-write $< | ||||
| 
 | ||||
| # --unstable is required, see https://github.com/denoland/deno_std/issues/1900
 | ||||
| $(UNSTABLE): %: %.ts doit.ts $(TEST_FILES) | ||||
| 	deno run --allow-read --allow-write --unstable --allow-env $< | ||||
| 
 | ||||
| .PHONY: stream | ||||
| stream: stream.ts | ||||
| 	deno run $< | ||||
| 
 | ||||
| number_format_greek.xls: | ||||
| 	cp ../../test_files/biff5/number_format_greek.xls . | ||||
| @ -1,88 +1,13 @@ | ||||
| # Deno | ||||
| 
 | ||||
| Deno is a runtime capable of running JS code including this library.  There are | ||||
| a few different builds and recommended use cases as covered in this demo. | ||||
| 
 | ||||
| Due to ongoing stability and sync issues with the Deno registry, scripts should | ||||
| use [the CDN build](https://cdn.sheetjs.com/xlsx-latest/package/xlsx.mjs): | ||||
| 
 | ||||
| ```js | ||||
| // @deno-types="https://cdn.sheetjs.com/xlsx-latest/package/types/index.d.ts" | ||||
| import * as XLSX from 'https://cdn.sheetjs.com/xlsx-latest/package/xlsx.mjs'; | ||||
| 
 | ||||
| /* load the codepage support library for extended support with older formats  */ | ||||
| import * as cptable from 'https://cdn.sheetjs.com/xlsx-latest/package/dist/cpexcel.full.mjs'; | ||||
| XLSX.set_cptable(cptable); | ||||
| ``` | ||||
| 
 | ||||
| 
 | ||||
| ## Reading and Writing Files | ||||
| 
 | ||||
| In general, the command-line flag `--allow-read` must be passed to enable file | ||||
| reading.  The flag `--allow-write` must be passed to enable file writing. | ||||
| 
 | ||||
| _Reading a File_ | ||||
| 
 | ||||
| ```ts | ||||
| const workbook = XLSX.readFile("test.xlsx"); | ||||
| ``` | ||||
| 
 | ||||
| _Writing a File_ | ||||
| 
 | ||||
| Older versions of the library did not properly detect features from Deno, so the | ||||
| `buffer` export would return an array of bytes.  Since `Deno.writeFileSync` does | ||||
| not handle byte arrays, user code must generate a `Uint8Array` first: | ||||
| 
 | ||||
| ```ts | ||||
| XLSX.writeFile(workbook, "test.xlsb"); | ||||
| ``` | ||||
| 
 | ||||
| ## Demos | ||||
| 
 | ||||
| **Complete Examples** | ||||
| 
 | ||||
| `sheet2csv.ts` is a complete command-line tool for generating CSV text from | ||||
| workbooks.  Building the application is incredibly straightforward: | ||||
| 
 | ||||
| ```bash | ||||
| $ deno compile -r --allow-read sheet2csv.ts  # build the sheet2csv binary | ||||
| $ ./sheet2csv test.xlsx                      # print the first worksheet as CSV | ||||
| $ ./sheet2csv test.xlsx s5s                  # print worksheet "s5s" as CSV | ||||
| ``` | ||||
| 
 | ||||
| The [`server` demo](../server) includes a sample Deno server for parsing uploads | ||||
| and generating HTML TABLE previews. | ||||
| 
 | ||||
| 
 | ||||
| **Module Import Scenarios** | ||||
| 
 | ||||
| All demos attempt to read a file and write a new file.  [`doit.ts`](./doit.ts) | ||||
| accepts the `XLSX` module as an argument. | ||||
| 
 | ||||
| - `x` imports the ESM build without the codepage library: | ||||
| 
 | ||||
| ```ts | ||||
| // @deno-types="https://cdn.sheetjs.com/xlsx-latest/package/types/index.d.ts" | ||||
| import * as XLSX from 'https://cdn.sheetjs.com/xlsx-latest/package/xlsx.mjs'; | ||||
| ``` | ||||
| 
 | ||||
| - `mjs` imports the ESM build and the associated codepage library: | ||||
| 
 | ||||
| ```ts | ||||
| import * as XLSX from '../../xlsx.mjs'; | ||||
| /* recommended for reading XLS files */ | ||||
| import * as cptable from '../../dist/cptable.full.mjs'; | ||||
| XLSX.set_cptable(cptable); | ||||
| ``` | ||||
| 
 | ||||
| - `node` uses the node compatibility layer: | ||||
| 
 | ||||
| ```ts | ||||
| import { createRequire } from 'https://deno.land/std/node/module.ts'; | ||||
| const require = createRequire(import.meta.url); | ||||
| const XLSX = require('../../'); | ||||
| ``` | ||||
| Deno is a runtime capable of running JS code including this library. | ||||
| 
 | ||||
| Demos have been integrated in the [documentation](https://docs.sheetjs.com) : | ||||
| 
 | ||||
| - <https://docs.sheetjs.com/docs/installation/deno> installation | ||||
| - <https://docs.sheetjs.com/docs/example> writing JS data to a spreadsheet | ||||
| - <https://docs.sheetjs.com/docs/solutions/input> input strategies | ||||
| - <https://docs.sheetjs.com/docs/solutions/output> output strategies | ||||
| - <https://docs.sheetjs.com/docs/getting-started/demos/cli#deno> `deno compile` | ||||
| 
 | ||||
| [](https://github.com/SheetJS/js-xlsx) | ||||
|  | ||||
| @ -1,43 +0,0 @@ | ||||
| const bts = [ | ||||
| 	"xlsx", | ||||
| 	"xlsb", | ||||
| 	"xls", | ||||
| 	"csv", | ||||
| 	"fods", | ||||
| 	"xlml", | ||||
| 	"slk" | ||||
| ]; | ||||
| export default function doit(XLSX: any, tag: string) { | ||||
| 	const path = "number_format_greek.xls"; | ||||
| 	let workbook: any; | ||||
| 
 | ||||
| 	/* read file */ | ||||
| 	try { | ||||
| 		workbook = XLSX.readFile(path); | ||||
| 	} catch(e) { | ||||
| 		console.log(e); | ||||
| 		console.error("Cannot use readFile, falling back to read"); | ||||
| 		const rawdata = Deno.readFileSync(path); | ||||
| 		workbook = XLSX.read(rawdata, {type: "buffer"}); | ||||
| 	} | ||||
| 
 | ||||
| 	/* write file */ | ||||
| 	try { | ||||
| 		bts.forEach(bt => { | ||||
| 			console.log(bt); | ||||
| 			XLSX.writeFile(workbook, `${tag}.${bt}`); | ||||
| 		}); | ||||
| 	} catch(e) { | ||||
| 		console.log(e); | ||||
| 		console.error("Cannot use writeFile, falling back to write"); | ||||
| 		bts.forEach(bt => { | ||||
| 			console.log(bt); | ||||
| 			const buf = XLSX.write(workbook, {type: "buffer", bookType: bt}); | ||||
| 			if(typeof buf == "string") { | ||||
| 				const nbuf = new Uint8Array(buf.length); | ||||
| 				for(let i = 0; i < buf.length; ++i) nbuf[i] = buf.charCodeAt(i); | ||||
| 				Deno.writeFileSync(`${tag}.${bt}`, nbuf); | ||||
| 			} else Deno.writeFileSync(`${tag}.${bt}`, new Uint8Array(buf)); | ||||
| 		}); | ||||
| 	} | ||||
| } | ||||
| @ -1,6 +0,0 @@ | ||||
| import * as XLSX from '../../xlsx.mjs'; | ||||
| import * as cpexcel from '../../dist/cpexcel.full.mjs'; | ||||
| XLSX.set_cptable(cpexcel); | ||||
| 
 | ||||
| import doit from './doit.ts'; | ||||
| doit(XLSX, "mjs"); | ||||
| @ -1,6 +0,0 @@ | ||||
| import { createRequire } from 'https://deno.land/std/node/module.ts'; | ||||
| const require = createRequire(import.meta.url); | ||||
| const XLSX = require('../../'); | ||||
| 
 | ||||
| import doit from './doit.ts'; | ||||
| doit(XLSX, "node"); | ||||
| @ -1,21 +0,0 @@ | ||||
| /*! sheetjs (C) 2013-present SheetJS -- http://sheetjs.com */ | ||||
| // @deno-types="https://cdn.sheetjs.com/xlsx-latest/package/types/index.d.ts"
 | ||||
| import * as XLSX from 'https://cdn.sheetjs.com/xlsx-latest/package/xlsx.mjs'; | ||||
| import * as cptable from 'https://cdn.sheetjs.com/xlsx-latest/package/dist/cpexcel.full.mjs'; | ||||
| XLSX.set_cptable(cptable); | ||||
| 
 | ||||
| const filename = Deno.args[0]; | ||||
| if(!filename) { | ||||
| 	console.error("usage: sheet2csv <filename> [sheetname]"); | ||||
| 	Deno.exit(1); | ||||
| } | ||||
| 
 | ||||
| const workbook = XLSX.readFile(filename); | ||||
| const sheetname = Deno.args[1] || workbook.SheetNames[0]; | ||||
| 
 | ||||
| if(!workbook.Sheets[sheetname]) { | ||||
| 	console.error(`error: workbook missing sheet ${sheetname}`); | ||||
| 	Deno.exit(1); | ||||
| } | ||||
| 
 | ||||
| console.log(XLSX.utils.sheet_to_csv(workbook.Sheets[sheetname])); | ||||
| @ -1,32 +0,0 @@ | ||||
| import {utils, stream, set_cptable} from '../../xlsx.mjs'; | ||||
| import * as cpexcel from '../../dist/cpexcel.full.mjs'; | ||||
| set_cptable(cpexcel); | ||||
| 
 | ||||
| function NodeReadableCB(cb:(d:any)=>void) { | ||||
| 	var rd = { | ||||
| 		__done: false, | ||||
| 		_read: function() {}, | ||||
| 		push: function(d: any) { if(!this.__done) cb(d); if(d == null) this.__done = true; }, | ||||
| 		resume: function pump() {for(var i = 0; i < 10000 && !this.__done; ++i) rd._read(); if(!rd.__done) setTimeout(pump, 0); } | ||||
| 	}; | ||||
| 	return rd; | ||||
| } | ||||
| 
 | ||||
| function NodeReadable(rd: any) { return function() { return rd; }; } | ||||
| 
 | ||||
| const L = 1_000_000; | ||||
| const W = 30; | ||||
| 
 | ||||
| console.time("prep"); | ||||
| const ws = utils.aoa_to_sheet([Array.from({length: W}, (_, C) => utils.encode_col(C))], {dense: true}); | ||||
| for(let l = 1; l < L; ++l) utils.sheet_add_aoa(ws, [Array.from({length: W}, (_,j) => j == 0 ? String(l) : l+j)], {origin: -1}); | ||||
| console.timeEnd("prep"); | ||||
| 
 | ||||
| console.time("stream"); | ||||
| var cnt = 0; | ||||
| const rt = NodeReadableCB((d: any) => { | ||||
| 	++cnt; if((cnt%10000) == 0) console.log(cnt); if(d == null) console.timeEnd("stream"); | ||||
| }); | ||||
| stream.set_readable(NodeReadable(rt)); | ||||
| const rd = stream.to_csv(ws); | ||||
| rd.resume(); | ||||
| @ -1,5 +0,0 @@ | ||||
| // @deno-types="https://cdn.sheetjs.com/xlsx-latest/package/types/index.d.ts"
 | ||||
| import * as XLSX from 'https://cdn.sheetjs.com/xlsx-latest/package/xlsx.mjs'; | ||||
| 
 | ||||
| import doit from './doit.ts'; | ||||
| doit(XLSX, "x"); | ||||
| @ -1,68 +1,7 @@ | ||||
| # Knockout  | ||||
| # Knockout | ||||
| 
 | ||||
| The `xlsx.core.min.js` and `xlsx.full.min.js` scripts are designed to be dropped | ||||
| into web pages with script tags: | ||||
| 
 | ||||
| ```html | ||||
| <script src="xlsx.full.min.js"></script> | ||||
| ``` | ||||
| 
 | ||||
| Strictly speaking, there should be no need for a Knockout demo!  You can proceed | ||||
| as you would with any other browser-friendly library. | ||||
| 
 | ||||
| 
 | ||||
| ## Array of Arrays | ||||
| 
 | ||||
| A common data table is often stored as an array of arrays: | ||||
| 
 | ||||
| ```js | ||||
| var aoa = [ [1,2], [3,4] ]; | ||||
| ``` | ||||
| 
 | ||||
| This neatly maps to a table with `data-bind="foreach: ..."`: | ||||
| 
 | ||||
| ```html | ||||
| <table data-bind="foreach: aoa"> | ||||
|   <tr data-bind="foreach: $data"> | ||||
|     <td><span data-bind="text: $data"></span></td> | ||||
|   </tr> | ||||
| </table> | ||||
| ``` | ||||
| 
 | ||||
| The `sheet_to_json` utility function can generate array of arrays for model use: | ||||
| 
 | ||||
| ```js | ||||
| /* starting from a `wb` workbook object, pull first worksheet */ | ||||
| var ws = wb.Sheets[wb.SheetNames[0]]; | ||||
| /* convert the worksheet to an array of arrays */ | ||||
| var aoa = XLSX.utils.sheet_to_json(ws, {header:1}); | ||||
| /* update model */ | ||||
| model.aoa(aoa); | ||||
| ``` | ||||
| 
 | ||||
| 
 | ||||
| ## Demo | ||||
| 
 | ||||
| The easiest observable representation is an `observableArray`: | ||||
| 
 | ||||
| ```js | ||||
| var ViewModel = function() { this.aoa = ko.observableArray([[1,2],[3,4]]); }; | ||||
| var model = new ViewModel(); | ||||
| ko.applyBindings(model); | ||||
| ``` | ||||
| 
 | ||||
| Unfortunately the nested `"foreach: $data"` binding is read-only.  A two-way | ||||
| binding is possible using the `$parent` and `$index` binding context properties: | ||||
| 
 | ||||
| ```html | ||||
| <table data-bind="foreach: aoa"> | ||||
|   <tr data-bind="foreach: $data"> | ||||
|     <td><input data-bind="value: $parent[$index()]" /></td> | ||||
|   </tr> | ||||
| </table> | ||||
| ``` | ||||
| 
 | ||||
| The demo shows reading worksheets into a view model and writing models to XLSX. | ||||
| [The new demo](https://docs.sheetjs.com/docs/getting-started/demos/legacy#knockoutjs) | ||||
| includes a live example and improved explanations. | ||||
| 
 | ||||
| 
 | ||||
| [](https://github.com/SheetJS/js-xlsx) | ||||
|  | ||||
| @ -1,109 +0,0 @@ | ||||
| <!DOCTYPE html> | ||||
| <!-- xlsx.js (C) 2013-present  SheetJS http://sheetjs.com --> | ||||
| <!-- vim: set ts=2: --> | ||||
| <html ng-app="sjs"> | ||||
| <head> | ||||
|   <title>SheetJS + KnockoutJS</title> | ||||
|   <!-- KnockoutJS --> | ||||
|   <script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.2/knockout-min.js"></script> | ||||
| 
 | ||||
|   <!-- SheetJS js-xlsx library --> | ||||
|   <script src="shim.js"></script> | ||||
|   <script src="xlsx.full.min.js"></script> | ||||
| </head> | ||||
| <body> | ||||
| <pre> | ||||
| <b><a href="https://sheetjs.com">SheetJS + KnockoutJS demo</a></b> | ||||
| 
 | ||||
| The core library can be used as-is in KnockoutJS applications. | ||||
| The <a href="https://github.com/sheetjs/js-xlsx">Community Edition README</a> details some common use cases. | ||||
| We also have some <a href="http://sheetjs.com/demos/">more public demos</a> | ||||
| 
 | ||||
| This demo shows: | ||||
| - view model backed by an array of arrays | ||||
| - file import that refreshes the model | ||||
| - table of editable `input` elements that are bound to the model | ||||
| - file export based on the model | ||||
| 
 | ||||
| <a href="https://sheetjs.com/pres.xlsx">Sample Spreadsheet</a> | ||||
| </pre> | ||||
| 
 | ||||
| <input name="xlfile" id="xlf"  class="left" style="width: 200px;" type="file"> | ||||
| <table data-bind="foreach: aoa"> | ||||
|     <tr data-bind="foreach: $data"> | ||||
|       <td><input data-bind="value: $parent[$index()]"/></td> | ||||
|     </tr> | ||||
| </table> | ||||
| <script id='aoa' type="text/html"></script> | ||||
| <button id="export">Export Sheet to XLSX</button> | ||||
| 
 | ||||
| </div> | ||||
| 
 | ||||
| <script> | ||||
| /* knockout setup */ | ||||
| var ViewModel = function() { | ||||
|   /* use an array of arrays */ | ||||
|   this.aoa = ko.observableArray([ | ||||
|     [1,2], | ||||
|     [3,4] | ||||
|   ]); | ||||
| }; | ||||
| 
 | ||||
| var model = new ViewModel(); | ||||
| ko.applyBindings(model); | ||||
| /* do an update to confirm KO was loaded properly */ | ||||
| model.aoa([[1,2,3],[4,5,6]]); | ||||
| model.aoa.push([7,8,9]); | ||||
| 
 | ||||
| /* set up file input handler */ | ||||
| (function() { | ||||
|   var input_dom_element = document.getElementById('xlf'); | ||||
|   function handleFile(e) { | ||||
|     var files = e.target.files, f = files[0]; | ||||
|     var reader = new FileReader(); | ||||
|     reader.onload = function(e) { | ||||
|       var data = e.target.result; | ||||
|       data = new Uint8Array(data); | ||||
|       var workbook = XLSX.read(data, {type: 'array'}); | ||||
|       process_wb(workbook); | ||||
|     }; | ||||
|     reader.readAsArrayBuffer(f); | ||||
|   } | ||||
|   input_dom_element.addEventListener('change', handleFile, false); | ||||
| })(); | ||||
| 
 | ||||
| /* update model */ | ||||
| function process_wb(wb) { | ||||
|   /* pull first worksheet */ | ||||
|   var ws = wb.Sheets[wb.SheetNames[0]]; | ||||
|   /* convert to AOA */ | ||||
|   var aoa = XLSX.utils.sheet_to_json(ws, {header:1}); | ||||
|   /* update model */ | ||||
|   model.aoa(aoa); | ||||
| } | ||||
| 
 | ||||
| document.getElementById("export").onclick = function() { | ||||
|   /* get array of arrays */ | ||||
|   var data = model.aoa(); | ||||
|   /* convert to worksheet */ | ||||
|   var ws = XLSX.utils.aoa_to_sheet(data); | ||||
|   /* build new workbook */ | ||||
|   var wb = XLSX.utils.book_new(); XLSX.utils.book_append_sheet(wb, ws, "Sheet1"); | ||||
|   /* write file */ | ||||
|   XLSX.writeFile(wb, "knockout.xlsx") | ||||
| }; | ||||
| </script> | ||||
| <script type="text/javascript"> | ||||
| /* eslint no-use-before-define:0 */ | ||||
|   var _gaq = _gaq || []; | ||||
|   _gaq.push(['_setAccount', 'UA-36810333-1']); | ||||
|   _gaq.push(['_trackPageview']); | ||||
| 
 | ||||
|   (function() { | ||||
|     var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; | ||||
|     ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; | ||||
|     var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); | ||||
|   })(); | ||||
| </script> | ||||
| </body> | ||||
| </html> | ||||
| @ -1 +0,0 @@ | ||||
| ../../shim.js | ||||
							
								
								
									
										1
									
								
								demos/knockout/xlsx.full.min.js
									
									
									
									
										vendored
									
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										1
									
								
								demos/knockout/xlsx.full.min.js
									
									
									
									
										vendored
									
									
								
							| @ -1 +0,0 @@ | ||||
| ../../dist/xlsx.full.min.js | ||||
							
								
								
									
										4
									
								
								demos/requirejs/.gitignore
									
									
									
									
										vendored
									
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										4
									
								
								demos/requirejs/.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -1,4 +0,0 @@ | ||||
| xlsx.full* | ||||
| r.js | ||||
| require.js | ||||
| app-built.js | ||||
| @ -1,10 +0,0 @@ | ||||
| TOOL=requirejs | ||||
| .PHONY: all | ||||
| all: $(TOOL).js | ||||
| 
 | ||||
| .PHONY: $(TOOL).js | ||||
| $(TOOL).js: | ||||
| 	if [ ! -e require.js ]; then curl -LO http://requirejs.org/docs/release/2.3.3/comments/require.js; fi | ||||
| 	if [ ! -e r.js ]; then curl -LO http://requirejs.org/docs/release/2.3.3/r.js; fi | ||||
| 	rm -f xlsx.full.min.js; ln -s ../../dist/xlsx.full.min.js | ||||
| 	node r.js -o build.js paths.requireLib=./require include=requireLib | ||||
| @ -1,67 +1,7 @@ | ||||
| # RequireJS | ||||
| 
 | ||||
| The module complies with the AMD `define` semantics, enabling use in RequireJS | ||||
| out of the box. | ||||
| [The new demo](https://docs.sheetjs.com/docs/getting-started/demos/bundler#requirejs) | ||||
| includes a live example and improved explanations. | ||||
| 
 | ||||
| The require config should set `xlsx` path to the appropriate dist file: | ||||
| 
 | ||||
| ```js | ||||
| 	paths: { | ||||
| 		xlsx: "xlsx.full.min" | ||||
| 	}, | ||||
| ``` | ||||
| 
 | ||||
| Once that is set, app code can freely require `"xlsx"`: | ||||
| 
 | ||||
| ```js | ||||
| require(["xlsx"], function(XLSX) { | ||||
| 	/* use XLSX here */ | ||||
| }); | ||||
| ``` | ||||
| 
 | ||||
| ## Deployments | ||||
| 
 | ||||
| `browser.html` demonstrates a dynamic deployment, using the in-browser config: | ||||
| 
 | ||||
| ```html | ||||
| <script src="require.js"></script> | ||||
| <script> | ||||
| require.config({ | ||||
| 	baseUrl: ".", | ||||
| 	name: "app", | ||||
| 	paths: { | ||||
| 		xlsx: "xlsx.full.min" | ||||
| 	} | ||||
| }); | ||||
| </script> | ||||
| <script src="app.js"></script> | ||||
| ``` | ||||
| 
 | ||||
| `optimizer.html` demonstrates an optimized deployment using `build.js` config: | ||||
| 
 | ||||
| ```js | ||||
| /* build config */ | ||||
| ({ | ||||
| 	baseUrl: ".", | ||||
| 	name: "app", | ||||
| 	paths: { | ||||
| 		xlsx: "xlsx.full.min" | ||||
| 	}, | ||||
| 	out: "app-built.js" | ||||
| }) | ||||
| ``` | ||||
| 
 | ||||
| The optimizer is invoked with: | ||||
| 
 | ||||
| ```bash | ||||
| node r.js -o build.js paths.requireLib=./require include=requireLib | ||||
| ``` | ||||
| 
 | ||||
| That step creates a file `app-built.js` that can be included in a page: | ||||
| 
 | ||||
| ```html | ||||
| <!-- final bundle includes require.js, library and app code --> | ||||
| <script src="app-built.js"></script> | ||||
| ``` | ||||
| 
 | ||||
| [](https://github.com/SheetJS/js-xlsx) | ||||
|  | ||||
| @ -1,147 +0,0 @@ | ||||
| /* xlsx.js (C) 2013-present  SheetJS -- http://sheetjs.com */ | ||||
| require(["xlsx"], function(XLSX2) { | ||||
| 
 | ||||
| var global_wb; | ||||
| 
 | ||||
| var process_wb = (function() { | ||||
| 	var OUT = document.getElementById('out'); | ||||
| 	var HTMLOUT = document.getElementById('htmlout'); | ||||
| 
 | ||||
| 	var get_format = (function() { | ||||
| 		var radios = document.getElementsByName( "format" ); | ||||
| 		return function() { | ||||
| 			for(var i = 0; i < radios.length; ++i) if(radios[i].checked || radios.length === 1) return radios[i].value; | ||||
| 		}; | ||||
| 	})(); | ||||
| 
 | ||||
| 	var to_json = function to_json(workbook) { | ||||
| 		var result = {}; | ||||
| 		workbook.SheetNames.forEach(function(sheetName) { | ||||
| 			var roa = XLSX2.utils.sheet_to_json(workbook.Sheets[sheetName]); | ||||
| 			if(roa.length) result[sheetName] = roa; | ||||
| 		}); | ||||
| 		return JSON.stringify(result, 2, 2); | ||||
| 	}; | ||||
| 
 | ||||
| 	var to_csv = function to_csv(workbook) { | ||||
| 		var result = []; | ||||
| 		workbook.SheetNames.forEach(function(sheetName) { | ||||
| 			var csv = XLSX2.utils.sheet_to_csv(workbook.Sheets[sheetName]); | ||||
| 			if(csv.length){ | ||||
| 				result.push("SHEET: " + sheetName); | ||||
| 				result.push(""); | ||||
| 				result.push(csv); | ||||
| 			} | ||||
| 		}); | ||||
| 		return result.join("\n"); | ||||
| 	}; | ||||
| 
 | ||||
| 	var to_fmla = function to_fmla(workbook) { | ||||
| 		var result = []; | ||||
| 		workbook.SheetNames.forEach(function(sheetName) { | ||||
| 			var formulae = XLSX2.utils.get_formulae(workbook.Sheets[sheetName]); | ||||
| 			if(formulae.length){ | ||||
| 				result.push("SHEET: " + sheetName); | ||||
| 				result.push(""); | ||||
| 				result.push(formulae.join("\n")); | ||||
| 			} | ||||
| 		}); | ||||
| 		return result.join("\n"); | ||||
| 	}; | ||||
| 
 | ||||
| 	var to_html = function to_html(workbook) { | ||||
| 		HTMLOUT.innerHTML = ""; | ||||
| 		workbook.SheetNames.forEach(function(sheetName) { | ||||
| 			var htmlstr = XLSX2.write(workbook, {sheet:sheetName, type:'string', bookType:'html'}); | ||||
| 			HTMLOUT.innerHTML += htmlstr; | ||||
| 		}); | ||||
| 		return ""; | ||||
| 	}; | ||||
| 
 | ||||
| 	return function process_wb(wb) { | ||||
| 		global_wb = wb; | ||||
| 		var output = ""; | ||||
| 		switch(get_format()) { | ||||
| 			case "form": output = to_fmla(wb); break; | ||||
| 			case "html": output = to_html(wb); break; | ||||
| 			case "json": output = to_json(wb); break; | ||||
| 			default: output = to_csv(wb); | ||||
| 		} | ||||
| 		if(OUT.innerText === undefined) OUT.textContent = output; | ||||
| 		else OUT.innerText = output; | ||||
| 		if(typeof console !== 'undefined') console.log("output", new Date()); | ||||
| 	}; | ||||
| })(); | ||||
| 
 | ||||
| var setfmt = window.setfmt = function setfmt() { if(global_wb) process_wb(global_wb); }; | ||||
| 
 | ||||
| var b64it = window.b64it = (function() { | ||||
| 	var tarea = document.getElementById('b64data'); | ||||
| 	return function b64it() { | ||||
| 		if(typeof console !== 'undefined') console.log("onload", new Date()); | ||||
| 		var wb = XLSX2.read(tarea.value, {type:'base64', WTF:false}); | ||||
| 		process_wb(wb); | ||||
| 	}; | ||||
| })(); | ||||
| 
 | ||||
| var do_file = (function() { | ||||
| 	var use_worker = false && typeof Worker !== 'undefined'; | ||||
| 	var domwork = document.getElementsByName("useworker")[0]; | ||||
| 	if(!use_worker) domwork.disabled = !(domwork.checked = false); | ||||
| 
 | ||||
| 	var xw = function xw(data, cb) { | ||||
| 		var worker = new Worker(XW.worker); | ||||
| 		worker.onmessage = function(e) { | ||||
| 			switch(e.data.t) { | ||||
| 				case 'ready': break; | ||||
| 				case 'e': console.error(e.data.d); break; | ||||
| 				case XW.msg: cb(JSON.parse(e.data.d)); break; | ||||
| 			} | ||||
| 		}; | ||||
| 		worker.postMessage({d:data,b:'array'}); | ||||
| 	}; | ||||
| 
 | ||||
| 	return function do_file(files) { | ||||
| 		use_worker = domwork.checked; | ||||
| 		var f = files[0]; | ||||
| 		var reader = new FileReader(); | ||||
| 		reader.onload = function(e) { | ||||
| 			if(typeof console !== 'undefined') console.log("onload", new Date(), use_worker); | ||||
| 			var data = e.target.result; | ||||
| 			data = new Uint8Array(data); | ||||
| 			if(use_worker) xw(data, process_wb); | ||||
| 			else process_wb(XLSX2.read(data, {type: 'array'})); | ||||
| 		}; | ||||
| 		reader.readAsArrayBuffer(f); | ||||
| 	}; | ||||
| })(); | ||||
| 
 | ||||
| (function() { | ||||
| 	var drop = document.getElementById('drop'); | ||||
| 	if(!drop.addEventListener) return; | ||||
| 
 | ||||
| 	function handleDrop(e) { | ||||
| 		e.stopPropagation(); | ||||
| 		e.preventDefault(); | ||||
| 		do_file(e.dataTransfer.files); | ||||
| 	} | ||||
| 
 | ||||
| 	function handleDragover(e) { | ||||
| 		e.stopPropagation(); | ||||
| 		e.preventDefault(); | ||||
| 		e.dataTransfer.dropEffect = 'copy'; | ||||
| 	} | ||||
| 
 | ||||
| 	drop.addEventListener('dragenter', handleDragover, false); | ||||
| 	drop.addEventListener('dragover', handleDragover, false); | ||||
| 	drop.addEventListener('drop', handleDrop, false); | ||||
| })(); | ||||
| 
 | ||||
| (function() { | ||||
| 	var xlf = document.getElementById('xlf'); | ||||
| 	if(!xlf.addEventListener) return; | ||||
| 	function handleFile(e) { do_file(e.target.files); } | ||||
| 	xlf.addEventListener('change', handleFile, false); | ||||
| })(); | ||||
| 
 | ||||
| }); | ||||
| @ -1,68 +0,0 @@ | ||||
| <!DOCTYPE html> | ||||
| <!-- xlsx.js (C) 2013-present  SheetJS http://sheetjs.com --> | ||||
| <!-- vim: set ts=2: --> | ||||
| <html> | ||||
| <head> | ||||
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||||
| <title>SheetJS Live Demo</title> | ||||
| <style> | ||||
| #drop{ | ||||
| 	border:2px dashed #bbb; | ||||
| 	-moz-border-radius:5px; | ||||
| 	-webkit-border-radius:5px; | ||||
| 	border-radius:5px; | ||||
| 	padding:25px; | ||||
| 	text-align:center; | ||||
| 	font:20pt bold,"Vollkorn";color:#bbb | ||||
| } | ||||
| #b64data{ | ||||
| 	width:100%; | ||||
| } | ||||
| a { text-decoration: none } | ||||
| </style> | ||||
| </head> | ||||
| <body> | ||||
| <pre> | ||||
| <b><a href="http://sheetjs.com">SheetJS Data Preview Live Demo</a></b> | ||||
| (Base64 text works back to IE6; drag and drop works back to IE10) | ||||
| 
 | ||||
| <a href="https://github.com/SheetJS/js-xlsx">Source Code Repo</a> | ||||
| <a href="https://github.com/SheetJS/js-xlsx/issues">Issues?  Something look weird?  Click here and report an issue</a> | ||||
| Output Format: <select name="format" onchange="setfmt()"> | ||||
| <option value="csv" selected> CSV</option> | ||||
| <option value="json"> JSON</option> | ||||
| <option value="form"> FORMULAE</option> | ||||
| <option value="html"> HTML</option> | ||||
| </select><br /> | ||||
| <div id="drop">Drop a spreadsheet file here to see sheet data</div> | ||||
| <input type="file" name="xlfile" id="xlf" /> ... or click here to select a file | ||||
| 
 | ||||
| <textarea id="b64data">... or paste a base64-encoding here</textarea> | ||||
| <input type="button" id="dotext" value="Click here to process the base64 text" onclick="b64it();"/><br /> | ||||
| <b>Advanced Demo Options:</b> | ||||
| Use Web Workers: (when available) <input type="checkbox" name="useworker" checked> | ||||
| </pre> | ||||
| <pre id="out"></pre> | ||||
| <div id="htmlout"></div> | ||||
| <br /> | ||||
| <script> | ||||
| var XW = { | ||||
| 	/* worker message */ | ||||
| 	msg: 'xlsx', | ||||
| 	/* worker scripts */ | ||||
| 	worker: './xlsxworker.js' | ||||
| }; | ||||
| </script> | ||||
| <script src="require.js"></script> | ||||
| <script> | ||||
| require.config({ | ||||
| 	baseUrl: ".", | ||||
| 	name: "app", | ||||
| 	paths: { | ||||
| 		xlsx: "xlsx.full.min" | ||||
| 	} | ||||
| }); | ||||
| </script> | ||||
| <script src="app.js"></script> | ||||
| </body> | ||||
| </html> | ||||
| @ -1,9 +0,0 @@ | ||||
| /* xlsx.js (C) 2013-present  SheetJS -- http://sheetjs.com */ | ||||
| ({ | ||||
| 	baseUrl: ".", | ||||
| 	name: "app", | ||||
| 	paths: { | ||||
| 		xlsx: "xlsx.full.min" | ||||
| 	}, | ||||
| 	out: "app-built.js" | ||||
| }) | ||||
| @ -1,58 +0,0 @@ | ||||
| <!DOCTYPE html> | ||||
| <!-- xlsx.js (C) 2013-present  SheetJS http://sheetjs.com --> | ||||
| <!-- vim: set ts=2: --> | ||||
| <html> | ||||
| <head> | ||||
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||||
| <title>SheetJS Live Demo</title> | ||||
| <style> | ||||
| #drop{ | ||||
| 	border:2px dashed #bbb; | ||||
| 	-moz-border-radius:5px; | ||||
| 	-webkit-border-radius:5px; | ||||
| 	border-radius:5px; | ||||
| 	padding:25px; | ||||
| 	text-align:center; | ||||
| 	font:20pt bold,"Vollkorn";color:#bbb | ||||
| } | ||||
| #b64data{ | ||||
| 	width:100%; | ||||
| } | ||||
| a { text-decoration: none } | ||||
| </style> | ||||
| </head> | ||||
| <body> | ||||
| <pre> | ||||
| <b><a href="http://sheetjs.com">SheetJS Data Preview Live Demo</a></b> | ||||
| (Base64 text works back to IE6; drag and drop works back to IE10) | ||||
| 
 | ||||
| <a href="https://github.com/SheetJS/js-xlsx">Source Code Repo</a> | ||||
| <a href="https://github.com/SheetJS/js-xlsx/issues">Issues?  Something look weird?  Click here and report an issue</a> | ||||
| Output Format: <select name="format" onchange="setfmt()"> | ||||
| <option value="csv" selected> CSV</option> | ||||
| <option value="json"> JSON</option> | ||||
| <option value="form"> FORMULAE</option> | ||||
| <option value="html"> HTML</option> | ||||
| </select><br /> | ||||
| <div id="drop">Drop a spreadsheet file here to see sheet data</div> | ||||
| <input type="file" name="xlfile" id="xlf" /> ... or click here to select a file | ||||
| 
 | ||||
| <textarea id="b64data">... or paste a base64-encoding here</textarea> | ||||
| <input type="button" id="dotext" value="Click here to process the base64 text" onclick="b64it();"/><br /> | ||||
| <b>Advanced Demo Options:</b> | ||||
| Use Web Workers: (when available) <input type="checkbox" name="useworker" checked> | ||||
| </pre> | ||||
| <pre id="out"></pre> | ||||
| <div id="htmlout"></div> | ||||
| <br /> | ||||
| <script> | ||||
| var XW = { | ||||
| 	/* worker message */ | ||||
| 	msg: 'xlsx', | ||||
| 	/* worker scripts */ | ||||
| 	worker: './xlsxworker.js' | ||||
| }; | ||||
| </script> | ||||
| <script src="app-built.js"></script> | ||||
| </body> | ||||
| </html> | ||||
| @ -1,23 +0,0 @@ | ||||
| TOOL=rollup | ||||
| .PHONY: all | ||||
| all: $(TOOL).min.js worker.min.js | ||||
| 
 | ||||
| $(TOOL).min.js: $(TOOL).js | ||||
| 	uglifyjs $< > $@ | ||||
| 
 | ||||
| .PHONY: $(TOOL).js | ||||
| $(TOOL).js: | ||||
| 	# node | ||||
| 	rollup -c rollup.config.node.js | ||||
| 	node -e 'require("./rollup.node")' | ||||
| 	# browser | ||||
| 	rollup -c | ||||
| 	rollup -c rollup.config.worker.js | ||||
| 
 | ||||
| worker.min.js: worker.js | ||||
| 	uglifyjs $< > $@ | ||||
| 
 | ||||
| .PHONY: init | ||||
| init: | ||||
| 	#@npm install @rollup/plugin-node-resolve @rollup/plugin-commonjs | ||||
| 	@mkdir -p node_modules; cd node_modules; if [ ! -e xlsx ]; then ln -s ../../../ xlsx; fi; cd - | ||||
| @ -1,46 +1,7 @@ | ||||
| # Rollup | ||||
| 
 | ||||
| This library has a proper ESM build that is enabled by default: | ||||
| [The new demo](https://docs.sheetjs.com/docs/getting-started/demos/bundler#rollup) | ||||
| includes a simple example and improved explanations. | ||||
| 
 | ||||
| ```js | ||||
| import { read, utils } from 'xlsx'; | ||||
| ``` | ||||
| 
 | ||||
| This sample demonstrates a bundle for browser as well as for node. | ||||
| 
 | ||||
| This demo uses the `import` form to expose the whole library, enabling client | ||||
| code to access the library with `import XLSX from 'xlsx'`.  The JS code from | ||||
| the root demo was moved to a separate `app.js` script. | ||||
| 
 | ||||
| ## Required Plugins | ||||
| 
 | ||||
| The `rollup-plugin-node-resolve` plugin is used: | ||||
| 
 | ||||
| ```js | ||||
| import resolve from 'rollup-plugin-node-resolve'; | ||||
| export default { | ||||
| 	/* ... */ | ||||
| 	plugins: [ | ||||
| 		resolve({ | ||||
| 			module: false, // <-- this library is not an ES6 module | ||||
| 			browser: true, // <-- suppress node-specific features | ||||
| 		}) | ||||
| 	], | ||||
| 	/* ... */ | ||||
| }; | ||||
| ``` | ||||
| 
 | ||||
| For the browser deployments, the output format is `'iife'`.  For node, the | ||||
| output format is `'cjs'`. | ||||
| 
 | ||||
| ### Worker Scripts | ||||
| 
 | ||||
| Rollup can also bundle worker scripts!  Instead of using `importScripts`, the | ||||
| worker script should import the module: | ||||
| 
 | ||||
| ```diff | ||||
| -importScripts('dist/xlsx.full.min.js'); | ||||
| +import * as XLSX from 'xlsx'; // or do named imports | ||||
| ``` | ||||
| 
 | ||||
| [](https://github.com/SheetJS/js-xlsx) | ||||
|  | ||||
| @ -1,146 +0,0 @@ | ||||
| /* xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com */ | ||||
| /*jshint browser:true */ | ||||
| import { read, write, utils } from 'xlsx'; | ||||
| 
 | ||||
| var global_wb; | ||||
| 
 | ||||
| var process_wb = (function() { | ||||
| 	var OUT = document.getElementById('out'); | ||||
| 	var HTMLOUT = document.getElementById('htmlout'); | ||||
| 
 | ||||
| 	var get_format = (function() { | ||||
| 		var radios = document.getElementsByName( "format" ); | ||||
| 		return function() { | ||||
| 			for(var i = 0; i < radios.length; ++i) if(radios[i].checked || radios.length === 1) return radios[i].value; | ||||
| 		}; | ||||
| 	})(); | ||||
| 
 | ||||
| 	var to_json = function to_json(workbook) { | ||||
| 		var result = {}; | ||||
| 		workbook.SheetNames.forEach(function(sheetName) { | ||||
| 			var roa = utils.sheet_to_json(workbook.Sheets[sheetName]); | ||||
| 			if(roa.length) result[sheetName] = roa; | ||||
| 		}); | ||||
| 		return JSON.stringify(result, 2, 2); | ||||
| 	}; | ||||
| 
 | ||||
| 	var to_csv = function to_csv(workbook) { | ||||
| 		var result = []; | ||||
| 		workbook.SheetNames.forEach(function(sheetName) { | ||||
| 			var csv = utils.sheet_to_csv(workbook.Sheets[sheetName]); | ||||
| 			if(csv.length){ | ||||
| 				result.push("SHEET: " + sheetName); | ||||
| 				result.push(""); | ||||
| 				result.push(csv); | ||||
| 			} | ||||
| 		}); | ||||
| 		return result.join("\n"); | ||||
| 	}; | ||||
| 
 | ||||
| 	var to_fmla = function to_fmla(workbook) { | ||||
| 		var result = []; | ||||
| 		workbook.SheetNames.forEach(function(sheetName) { | ||||
| 			var formulae = utils.get_formulae(workbook.Sheets[sheetName]); | ||||
| 			if(formulae.length){ | ||||
| 				result.push("SHEET: " + sheetName); | ||||
| 				result.push(""); | ||||
| 				result.push(formulae.join("\n")); | ||||
| 			} | ||||
| 		}); | ||||
| 		return result.join("\n"); | ||||
| 	}; | ||||
| 
 | ||||
| 	var to_html = function to_html(workbook) { | ||||
| 		HTMLOUT.innerHTML = ""; | ||||
| 		workbook.SheetNames.forEach(function(sheetName) { | ||||
| 			var htmlstr = write(workbook, {sheet:sheetName, type:'string', bookType:'html'}); | ||||
| 			HTMLOUT.innerHTML += htmlstr; | ||||
| 		}); | ||||
| 		return ""; | ||||
| 	}; | ||||
| 
 | ||||
| 	return function process_wb(wb) { | ||||
| 		global_wb = wb; | ||||
| 		var output = ""; | ||||
| 		switch(get_format()) { | ||||
| 			case "form": output = to_fmla(wb); break; | ||||
| 			case "html": output = to_html(wb); break; | ||||
| 			case "json": output = to_json(wb); break; | ||||
| 			default: output = to_csv(wb); | ||||
| 		} | ||||
| 		if(OUT.innerText === undefined) OUT.textContent = output; | ||||
| 		else OUT.innerText = output; | ||||
| 		if(typeof console !== 'undefined') console.log("output", new Date()); | ||||
| 	}; | ||||
| })(); | ||||
| 
 | ||||
| var setfmt = window.setfmt = function setfmt() { if(global_wb) process_wb(global_wb); }; | ||||
| 
 | ||||
| var b64it = window.b64it = (function() { | ||||
| 	var tarea = document.getElementById('b64data'); | ||||
| 	return function b64it() { | ||||
| 		if(typeof console !== 'undefined') console.log("onload", new Date()); | ||||
| 		var wb = read(tarea.value, {type:'base64', WTF:false}); | ||||
| 		process_wb(wb); | ||||
| 	}; | ||||
| })(); | ||||
| 
 | ||||
| var do_file = (function() { | ||||
| 	var use_worker = typeof Worker !== 'undefined'; | ||||
| 	var domwork = document.getElementsByName("useworker")[0]; | ||||
| 	if(!use_worker) domwork.disabled = !(domwork.checked = false); | ||||
| 
 | ||||
| 	var xw = function xw(data, cb) { | ||||
| 		var worker = new Worker('./worker.js'); | ||||
| 		worker.onmessage = function(e) { | ||||
| 			switch(e.data.t) { | ||||
| 				case 'ready': break; | ||||
| 				case 'e': console.error(e.data.d); break; | ||||
| 				case 'xlsx': cb(JSON.parse(e.data.d)); break; | ||||
| 			} | ||||
| 		}; | ||||
| 		worker.postMessage({d:data,b:'array'}); | ||||
| 	}; | ||||
| 
 | ||||
| 	return function do_file(files) { | ||||
| 		use_worker = domwork.checked; | ||||
| 		var f = files[0]; | ||||
| 		var reader = new FileReader(); | ||||
| 		reader.onload = function(e) { | ||||
| 			if(typeof console !== 'undefined') console.log("onload", new Date(), use_worker); | ||||
| 			var data = e.target.result; | ||||
| 			data = new Uint8Array(data); | ||||
| 			if(use_worker) xw(data, process_wb); | ||||
| 			else process_wb(read(data, {type: 'array'})); | ||||
| 		}; | ||||
| 		reader.readAsArrayBuffer(f); | ||||
| 	}; | ||||
| })(); | ||||
| 
 | ||||
| (function() { | ||||
| 	var drop = document.getElementById('drop'); | ||||
| 	if(!drop.addEventListener) return; | ||||
| 
 | ||||
| 	function handleDrop(e) { | ||||
| 		e.stopPropagation(); | ||||
| 		e.preventDefault(); | ||||
| 		do_file(e.dataTransfer.files); | ||||
| 	} | ||||
| 
 | ||||
| 	function handleDragover(e) { | ||||
| 		e.stopPropagation(); | ||||
| 		e.preventDefault(); | ||||
| 		e.dataTransfer.dropEffect = 'copy'; | ||||
| 	} | ||||
| 
 | ||||
| 	drop.addEventListener('dragenter', handleDragover, false); | ||||
| 	drop.addEventListener('dragover', handleDragover, false); | ||||
| 	drop.addEventListener('drop', handleDrop, false); | ||||
| })(); | ||||
| 
 | ||||
| (function() { | ||||
| 	var xlf = document.getElementById('xlf'); | ||||
| 	if(!xlf.addEventListener) return; | ||||
| 	function handleFile(e) { do_file(e.target.files); } | ||||
| 	xlf.addEventListener('change', handleFile, false); | ||||
| })(); | ||||
| @ -1,3 +0,0 @@ | ||||
| /* xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com */ | ||||
| import * as XLSX from 'xlsx'; | ||||
| export default XLSX; | ||||
| @ -1,16 +0,0 @@ | ||||
| /* xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com */ | ||||
| import resolve from '@rollup/plugin-node-resolve'; | ||||
| export default { | ||||
| 	input: 'app.js', | ||||
| 	output: { | ||||
| 		file: 'rollup.js', | ||||
| 		format: 'iife' | ||||
| 	}, | ||||
| 	//dest: 'rollup.js',
 | ||||
| 	plugins: [ | ||||
| 		resolve({ | ||||
| 			module: false, | ||||
| 			browser: true, | ||||
| 		}), | ||||
| 	], | ||||
| }; | ||||
| @ -1,16 +0,0 @@ | ||||
| /* xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com */ | ||||
| import resolve from '@rollup/plugin-node-resolve'; | ||||
| export default { | ||||
| 	input: 'main.js', | ||||
| 	output: { | ||||
| 		file: 'rollup.node.js', | ||||
| 		format: 'cjs' | ||||
| 	}, | ||||
| 	//dest: 'rollup.node.js',
 | ||||
| 	plugins: [ | ||||
| 		resolve({ | ||||
| 			module: false, | ||||
| 			browser: true, | ||||
| 		}) | ||||
| 	], | ||||
| }; | ||||
| @ -1,16 +0,0 @@ | ||||
| /* xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com */ | ||||
| import resolve from '@rollup/plugin-node-resolve'; | ||||
| export default { | ||||
| 	input: 'xlsxworker.js', | ||||
| 	output: { | ||||
| 		file: 'worker.js', | ||||
| 		format: 'iife' | ||||
| 	}, | ||||
| 	//dest: 'worker.js',
 | ||||
| 	plugins: [ | ||||
| 		resolve({ | ||||
| 			module: false, | ||||
| 			browser: true, | ||||
| 		}), | ||||
| 	], | ||||
| }; | ||||
| @ -1,50 +0,0 @@ | ||||
| <!DOCTYPE html> | ||||
| <!-- xlsx.js (C) 2013-present  SheetJS http://sheetjs.com --> | ||||
| <!-- vim: set ts=2: --> | ||||
| <html> | ||||
| <head> | ||||
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||||
| <title>SheetJS Live Demo</title> | ||||
| <style> | ||||
| #drop{ | ||||
| 	border:2px dashed #bbb; | ||||
| 	-moz-border-radius:5px; | ||||
| 	-webkit-border-radius:5px; | ||||
| 	border-radius:5px; | ||||
| 	padding:25px; | ||||
| 	text-align:center; | ||||
| 	font:20pt bold,"Vollkorn";color:#bbb | ||||
| } | ||||
| #b64data{ | ||||
| 	width:100%; | ||||
| } | ||||
| a { text-decoration: none } | ||||
| </style> | ||||
| </head> | ||||
| <body> | ||||
| <pre> | ||||
| <b><a href="http://sheetjs.com">SheetJS Data Preview Live Demo</a></b> | ||||
| (Base64 text works back to IE6; drag and drop works back to IE10) | ||||
| 
 | ||||
| <a href="https://github.com/SheetJS/js-xlsx">Source Code Repo</a> | ||||
| <a href="https://github.com/SheetJS/js-xlsx/issues">Issues?  Something look weird?  Click here and report an issue</a> | ||||
| Output Format: <select name="format" onchange="setfmt()"> | ||||
| <option value="csv" selected> CSV</option> | ||||
| <option value="json"> JSON</option> | ||||
| <option value="form"> FORMULAE</option> | ||||
| <option value="html"> HTML</option> | ||||
| </select><br /> | ||||
| <div id="drop">Drop a spreadsheet file here to see sheet data</div> | ||||
| <input type="file" name="xlfile" id="xlf" /> ... or click here to select a file | ||||
| 
 | ||||
| <textarea id="b64data">... or paste a base64-encoding here</textarea> | ||||
| <input type="button" id="dotext" value="Click here to process the base64 text" onclick="b64it();"/><br /> | ||||
| <b>Advanced Demo Options:</b> | ||||
| Use Web Workers: (when available) <input type="checkbox" name="useworker" checked> | ||||
| </pre> | ||||
| <pre id="out"></pre> | ||||
| <div id="htmlout"></div> | ||||
| <br /> | ||||
| <script src="rollup.min.js"></script> | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										11
									
								
								demos/rollup/xlsxworker.js
									
									
									
										generated
									
									
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										11
									
								
								demos/rollup/xlsxworker.js
									
									
									
										generated
									
									
									
								
							| @ -1,11 +0,0 @@ | ||||
| /* xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com */ | ||||
| import { read } from 'xlsx'; | ||||
| postMessage({t:"ready"}); | ||||
| 
 | ||||
| onmessage = function (evt) { | ||||
|   var v; | ||||
|   try { | ||||
|     v = read(evt.data.d, {type: evt.data.b}); | ||||
| postMessage({t:"xlsx", d:JSON.stringify(v)}); | ||||
|   } catch(e) { postMessage({t:"e",d:e.stack||e}); } | ||||
| }; | ||||
| @ -827,6 +827,8 @@ function parse_numbers_iwa(cfb, opts) { | ||||
|   cfb.FileIndex.forEach(function(s) { | ||||
|     if (!s.name.match(/\.iwa$/)) | ||||
|       return; | ||||
|     if (s.content[0] == 98) | ||||
|       return; | ||||
|     var o; | ||||
|     try { | ||||
|       o = decompress_iwa_file(s.content); | ||||
|  | ||||
| @ -717,6 +717,7 @@ function parse_numbers_iwa(cfb: CFB$Container, opts?: ParsingOptions ): WorkBook | ||||
| 	/* collect entire message space */ | ||||
| 	cfb.FileIndex.forEach(s => { | ||||
| 		if(!s.name.match(/\.iwa$/)) return; | ||||
| 		if(s.content[0] == 98) return; // TODO: OperationStorage.iwa
 | ||||
| 		var o: Uint8Array; | ||||
| 		try { o = decompress_iwa_file(s.content as Uint8Array); } catch(e) { return console.log("?? " + s.content.length + " " + (e.message || e)); } | ||||
| 		var packets: IWAArchiveInfo[]; | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user