forked from sheetjs/sheetjs
ODS XML Parse nit
This commit is contained in:
parent
4a31cb9810
commit
ee8b37b3a6
36
.github/workflows/deno.yml
vendored
36
.github/workflows/deno.yml
vendored
@ -3,26 +3,9 @@ name: 'Tests: deno 1.x'
|
||||
on: [pull_request, push]
|
||||
|
||||
jobs:
|
||||
# small test
|
||||
misc:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
FMTS: misc
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: denoland/setup-deno@main
|
||||
with:
|
||||
deno-version: v1.x
|
||||
- uses: ljharb/actions/node/install@main
|
||||
with:
|
||||
node-version: '16.'
|
||||
- run: sudo curl -Lo /usr/bin/rooster https://github.com/SheetJS/rooster/releases/download/v0.2.0/rooster-v0.2.0-linux-amd64
|
||||
- run: sudo chmod a+x /usr/bin/rooster
|
||||
- run: make init
|
||||
- run: 'cd test_files; make all; cd -'
|
||||
- run: deno test --allow-env --allow-read --allow-write --config misc/test.deno.jsonc test.ts
|
||||
# full test
|
||||
full:
|
||||
name: 'full (with codepage)'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
@ -37,3 +20,20 @@ jobs:
|
||||
- run: make init
|
||||
- run: 'cd test_files; make all; cd -'
|
||||
- run: deno test --allow-env --allow-read --allow-write --config misc/test.deno.jsonc test.ts
|
||||
# full test (no codepage)
|
||||
fullnocp:
|
||||
name: 'full (no codepage)'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: denoland/setup-deno@main
|
||||
with:
|
||||
deno-version: v1.x
|
||||
- uses: ljharb/actions/node/install@main
|
||||
with:
|
||||
node-version: '16.'
|
||||
- run: sudo curl -Lo /usr/bin/rooster https://github.com/SheetJS/rooster/releases/download/v0.2.0/rooster-v0.2.0-linux-amd64
|
||||
- run: sudo chmod a+x /usr/bin/rooster
|
||||
- run: make init
|
||||
- run: 'cd test_files; make all; cd -'
|
||||
- run: deno test --allow-env --allow-read --allow-write --config misc/test.deno.jsonc testnocp.ts
|
||||
|
4
Makefile
4
Makefile
@ -148,6 +148,10 @@ test.ts: test.mts
|
||||
test-deno: test.ts ## Run Deno test suite
|
||||
deno test --allow-env --allow-read --allow-write --config misc/test.deno.jsonc $<
|
||||
|
||||
.PHONY: test-denocp
|
||||
test-denocp: testnocp.ts ## Run Deno test suite (without codepage)
|
||||
deno test --allow-env --allow-read --allow-write --config misc/test.deno.jsonc $<
|
||||
|
||||
#* To run tests for one format, make test_<fmt>
|
||||
#* To run the core test suite, make test_misc
|
||||
TESTFMT=$(patsubst %,test_%,$(FMT))
|
||||
|
@ -19,6 +19,32 @@ function Base64_encode(input) {
|
||||
}
|
||||
return o;
|
||||
}
|
||||
function Base64_encode_pass(input) {
|
||||
var o = "";
|
||||
var c1 = 0, c2 = 0, c3 = 0, e1 = 0, e2 = 0, e3 = 0, e4 = 0;
|
||||
for (var i = 0; i < input.length; ) {
|
||||
c1 = input.charCodeAt(i++);
|
||||
if (c1 > 255)
|
||||
c1 = 95;
|
||||
e1 = c1 >> 2;
|
||||
c2 = input.charCodeAt(i++);
|
||||
if (c2 > 255)
|
||||
c2 = 95;
|
||||
e2 = (c1 & 3) << 4 | c2 >> 4;
|
||||
c3 = input.charCodeAt(i++);
|
||||
if (c3 > 255)
|
||||
c3 = 95;
|
||||
e3 = (c2 & 15) << 2 | c3 >> 6;
|
||||
e4 = c3 & 63;
|
||||
if (isNaN(c2)) {
|
||||
e3 = e4 = 64;
|
||||
} else if (isNaN(c3)) {
|
||||
e4 = 64;
|
||||
}
|
||||
o += Base64_map.charAt(e1) + Base64_map.charAt(e2) + Base64_map.charAt(e3) + Base64_map.charAt(e4);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
function Base64_decode(input) {
|
||||
var o = "";
|
||||
var c1 = 0, c2 = 0, c3 = 0, e1 = 0, e2 = 0, e3 = 0, e4 = 0;
|
||||
|
@ -184,9 +184,7 @@ function fuzzydate(s/*:string*/)/*:Date*/ {
|
||||
lower = lower.replace(/[^a-z]/g,"").replace(/([^a-z]|^)[ap]m?([^a-z]|$)/,"");
|
||||
if(lower.length > 3 && lower_months.indexOf(lower) == -1) return n;
|
||||
} else if(lower.replace(/[ap]m?/, "").match(/[a-z]/)) return n;
|
||||
if(y < 0 || y > 8099) return n;
|
||||
if((m > 0 || d > 1) && y != 101) return o;
|
||||
if(s.match(/[^-0-9:,\/\\]/)) return n;
|
||||
if(y < 0 || y > 8099 || s.match(/[^-0-9:,\/\\]/)) return n;
|
||||
return o;
|
||||
}
|
||||
|
||||
|
@ -246,7 +246,7 @@ function xlml_normalize(d)/*:string*/ {
|
||||
throw new Error("Bad input format: expected Buffer or string");
|
||||
}
|
||||
/* UOS uses CJK in tags */
|
||||
var xlmlregex = /<(\/?)([^\s?><!\/:]*:|)([^\s?<>:\/]+)(?:[\s?:\/][^>]*)?>/mg;
|
||||
var xlmlregex = /<(\/?)([^\s?><!\/:]*:|)([^\s?<>:\/]+)(?:[\s?:\/](?:[^>=]|="[^"]*?")*)?>/mg;
|
||||
//var xlmlregex = /<(\/?)([a-z0-9]*:|)(\w+)[^>]*>/mg;
|
||||
|
||||
var XMLNS = ({
|
||||
|
@ -81,7 +81,7 @@ function write_string_type(out/*:string*/, opts/*:WriteOpts*/, bom/*:?string*/)/
|
||||
|
||||
function write_stxt_type(out/*:string*/, opts/*:WriteOpts*/)/*:any*/ {
|
||||
switch(opts.type) {
|
||||
case "base64": return Base64_encode(out);
|
||||
case "base64": return Base64_encode_pass(out);
|
||||
case "binary": return out;
|
||||
case "string": return out; /* override in sheet_to_txt */
|
||||
case "file": return write_dl(opts.file, out, 'binary');
|
||||
|
@ -29,6 +29,27 @@ can be installed with Bash on Windows or with `cygwin`.
|
||||
- [`databases and key/value stores`](database/)
|
||||
- [`typed arrays and math`](array/)
|
||||
|
||||
**Front-End UI Components**
|
||||
- [`canvas-datagrid`](datagrid/)
|
||||
- [`x-spreadsheet`](xspreadsheet/)
|
||||
- [`react-data-grid`](react/modify/)
|
||||
- [`vue3-table-light`](/vue/modify/)
|
||||
|
||||
**Platforms and Integrations**
|
||||
- [`deno`](deno/)
|
||||
- [`electron application`](electron/)
|
||||
- [`nw.js application`](nwjs/)
|
||||
- [`Chrome / Chromium extensions`](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 Browsers`](headless/)
|
||||
- [`Swift JSC and other engines`](altjs/)
|
||||
- [`"serverless" functions`](function/)
|
||||
- [`internet explorer`](oldie/)
|
||||
|
||||
**Bundlers and Tooling**
|
||||
- [`browserify`](browserify/)
|
||||
- [`parcel`](parcel/)
|
||||
@ -38,23 +59,6 @@ can be installed with Bash on Windows or with `cygwin`.
|
||||
- [`typescript`](typescript/)
|
||||
- [`webpack 2.x`](webpack/)
|
||||
|
||||
**Platforms and Integrations**
|
||||
- [`deno`](deno/)
|
||||
- [`electron application`](electron/)
|
||||
- [`nw.js application`](nwjs/)
|
||||
- [`Chrome / Chromium extensions`](chrome/)
|
||||
- [`Google Sheets API`](https://docs.sheetjs.com/docs/getting-started/demos/gsheet)
|
||||
- [`Adobe Apps`](https://docs.sheetjs.com/docs/getting-started/demos/extendscript)
|
||||
- [`Excel JavaScript API`](https://docs.sheetjs.com/docs/getting-started/demos/excel)
|
||||
- [`Headless Browsers`](headless/)
|
||||
- [`canvas-datagrid`](datagrid/)
|
||||
- [`x-spreadsheet`](xspreadsheet/)
|
||||
- [`react-data-grid`](react/modify/)
|
||||
- [`vue3-table-light`](/vue/modify/)
|
||||
- [`Swift JSC and other engines`](altjs/)
|
||||
- [`"serverless" functions`](function/)
|
||||
- [`internet explorer`](oldie/)
|
||||
|
||||
Other examples are included in the [showcase](demos/showcase/).
|
||||
|
||||
[![Analytics](https://ga-beacon.appspot.com/UA-36810333-1/SheetJS/js-xlsx?pixel)](https://github.com/SheetJS/js-xlsx)
|
||||
|
@ -48,13 +48,13 @@ The `sheet_to_json` helper function generates arrays of JS objects that can be
|
||||
scanned to determine the column "types", and there are third-party connectors
|
||||
that can push arrays of JS objects to database tables.
|
||||
|
||||
The [`sexql`](http://sheetjs.com/sexql) browser demo uses WebSQL, which is
|
||||
The [`sql`](http://sheetjs.com/sql) browser demo uses WebSQL, which is
|
||||
limited to the SQLite fundamental types.
|
||||
|
||||
<details>
|
||||
<summary><b>Implementation details</b> (click to show)</summary>
|
||||
|
||||
The `sexql` schema builder scans the first row to find headers:
|
||||
The `sql` schema builder scans the first row to find headers:
|
||||
|
||||
```js
|
||||
if(!ws || !ws['!ref']) return;
|
||||
@ -202,11 +202,11 @@ function object_to_workbook(obj) {
|
||||
|
||||
#### WebSQL
|
||||
|
||||
WebSQL is a popular SQL-based in-browser database available on Chrome / Safari.
|
||||
In practice, it is powered by SQLite, and most simple SQLite-compatible queries
|
||||
WebSQL is a popular SQL-based in-browser database available on Chrome. In
|
||||
practice, it is powered by SQLite, and most simple SQLite-compatible queries
|
||||
work as-is in WebSQL.
|
||||
|
||||
The public demo <http://sheetjs.com/sexql> generates a database from workbook.
|
||||
The public demo <http://sheetjs.com/sql> generates a database from workbook.
|
||||
|
||||
#### LocalStorage and SessionStorage
|
||||
|
||||
@ -259,9 +259,9 @@ the `sheetj5` database and verifies the tables are preserved.
|
||||
|
||||
#### PostgreSQL
|
||||
|
||||
[The `pg` module](https://www.npmjs.com/package/pg) supplies a Promise wrapper.
|
||||
Like with `mysql2`, `Client#query` runs a statement and returns a result object.
|
||||
The `rows` key of the object is an array of JS objects.
|
||||
[The `pg` module](https://node-postgres.com/) supplies a Promise wrapper.
|
||||
`Client#query` runs a statement and returns a result object. The `rows` key of
|
||||
the object is an array of JS objects.
|
||||
|
||||
`PgSQLTest.js` connects to the PostgreSQL server on `localhost`, builds two
|
||||
tables in the `sheetjs` database, exports to XLSX, imports the new XLSX file to
|
||||
|
1
demos/electron/.gitignore
vendored
Normal file
1
demos/electron/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
out/
|
@ -10,3 +10,6 @@ lint:
|
||||
run:
|
||||
npm i
|
||||
npx electron .
|
||||
.PHONY: build
|
||||
build:
|
||||
npm run make
|
||||
|
@ -15,6 +15,12 @@ The core data in this demo is an editable HTML table. The readers build up the
|
||||
table using `sheet_to_html` (with `editable:true` option) and the writers scrape
|
||||
the table using `table_to_book`.
|
||||
|
||||
The demo project is structured for `electron-forge`:
|
||||
- `npm start` will start the app.
|
||||
- `npm run make` will build a standalone app.
|
||||
|
||||
The standalone app was tested on an Intel Mac (`darwin-x64`).
|
||||
|
||||
## Reading and Writing Files
|
||||
|
||||
Since electron provides an `fs` implementation, `readFile` and `writeFile` can
|
||||
|
@ -40,7 +40,7 @@ const handleReadBtn = async function() {
|
||||
|
||||
const exportXlsx = async function() {
|
||||
const HTMLOUT = document.getElementById('htmlout');
|
||||
const wb = XLSX.utils.table_to_book(HTMLOUT);
|
||||
const wb = XLSX.utils.table_to_book(HTMLOUT.getElementsByTagName("TABLE")[0]);
|
||||
const o = await electron.dialog.showSaveDialog({
|
||||
title: 'Save file as',
|
||||
filters: [{
|
||||
|
@ -1,14 +1,51 @@
|
||||
{
|
||||
"name": "sheetjs-electron",
|
||||
"author": "sheetjs",
|
||||
"version": "0.0.0",
|
||||
"main": "main.js",
|
||||
"dependencies": {
|
||||
"@electron/remote": "^2.0.8",
|
||||
"electron": "^18.2.0",
|
||||
"xlsx": "https://cdn.sheetjs.com/xlsx-latest/xlsx-latest.tgz"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "electron ."
|
||||
}
|
||||
"name": "sheetjs-electron",
|
||||
"author": "sheetjs",
|
||||
"version": "0.0.0",
|
||||
"main": "main.js",
|
||||
"dependencies": {
|
||||
"@electron/remote": "2.0.8",
|
||||
"electron-squirrel-startup": "^1.0.0",
|
||||
"xlsx": "https://cdn.sheetjs.com/xlsx-latest/xlsx-latest.tgz"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "electron-forge start",
|
||||
"package": "electron-forge package",
|
||||
"make": "electron-forge make"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@electron-forge/cli": "^6.0.0-beta.64",
|
||||
"@electron-forge/maker-deb": "^6.0.0-beta.64",
|
||||
"@electron-forge/maker-rpm": "^6.0.0-beta.64",
|
||||
"@electron-forge/maker-squirrel": "^6.0.0-beta.64",
|
||||
"@electron-forge/maker-zip": "^6.0.0-beta.64",
|
||||
"electron": "19.0.5"
|
||||
},
|
||||
"config": {
|
||||
"forge": {
|
||||
"packagerConfig": {},
|
||||
"makers": [
|
||||
{
|
||||
"name": "@electron-forge/maker-squirrel",
|
||||
"config": {
|
||||
"name": "sheetjs_electron"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "@electron-forge/maker-zip",
|
||||
"platforms": [
|
||||
"darwin"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "@electron-forge/maker-deb",
|
||||
"config": {}
|
||||
},
|
||||
{
|
||||
"name": "@electron-forge/maker-rpm",
|
||||
"config": {}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,32 @@ function Base64_encode(input) {
|
||||
}
|
||||
return o;
|
||||
}
|
||||
function Base64_encode_pass(input) {
|
||||
var o = "";
|
||||
var c1 = 0, c2 = 0, c3 = 0, e1 = 0, e2 = 0, e3 = 0, e4 = 0;
|
||||
for (var i = 0; i < input.length; ) {
|
||||
c1 = input.charCodeAt(i++);
|
||||
if (c1 > 255)
|
||||
c1 = 95;
|
||||
e1 = c1 >> 2;
|
||||
c2 = input.charCodeAt(i++);
|
||||
if (c2 > 255)
|
||||
c2 = 95;
|
||||
e2 = (c1 & 3) << 4 | c2 >> 4;
|
||||
c3 = input.charCodeAt(i++);
|
||||
if (c3 > 255)
|
||||
c3 = 95;
|
||||
e3 = (c2 & 15) << 2 | c3 >> 6;
|
||||
e4 = c3 & 63;
|
||||
if (isNaN(c2)) {
|
||||
e3 = e4 = 64;
|
||||
} else if (isNaN(c3)) {
|
||||
e4 = 64;
|
||||
}
|
||||
o += Base64_map.charAt(e1) + Base64_map.charAt(e2) + Base64_map.charAt(e3) + Base64_map.charAt(e4);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
function Base64_decode(input) {
|
||||
var o = "";
|
||||
var c1 = 0, c2 = 0, c3 = 0, e1 = 0, e2 = 0, e3 = 0, e4 = 0;
|
||||
|
@ -18,6 +18,25 @@ function Base64_encode(input: string): string {
|
||||
}
|
||||
return o;
|
||||
}
|
||||
function Base64_encode_pass(input: string): string {
|
||||
var o = "";
|
||||
var c1=0, c2=0, c3=0, e1=0, e2=0, e3=0, e4=0;
|
||||
for(var i = 0; i < input.length; ) {
|
||||
c1 = input.charCodeAt(i++); if(c1 > 0xFF) c1 = 0x5F;
|
||||
e1 = (c1 >> 2);
|
||||
|
||||
c2 = input.charCodeAt(i++); if(c2 > 0xFF) c2 = 0x5F;
|
||||
e2 = ((c1 & 3) << 4) | (c2 >> 4);
|
||||
|
||||
c3 = input.charCodeAt(i++); if(c3 > 0xFF) c3 = 0x5F;
|
||||
e3 = ((c2 & 15) << 2) | (c3 >> 6);
|
||||
e4 = (c3 & 63);
|
||||
if (isNaN(c2)) { e3 = e4 = 64; }
|
||||
else if (isNaN(c3)) { e4 = 64; }
|
||||
o += Base64_map.charAt(e1) + Base64_map.charAt(e2) + Base64_map.charAt(e3) + Base64_map.charAt(e4);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
function Base64_decode(input: string): string {
|
||||
var o = "";
|
||||
var c1=0, c2=0, c3=0, e1=0, e2=0, e3=0, e4=0;
|
||||
|
@ -924,7 +924,7 @@ function write_numbers_iwa(wb: WorkBook, opts: any): CFB$Container {
|
||||
for(var R = 0; R <= range.e.r; ++R) {
|
||||
cruids[4].push({type: 2, data: write_shallow([ [],
|
||||
[ { type: 0, data: write_varint49(R + 726270)} ],
|
||||
[ { type: 0, data: write_varint49(R + 726270)} ]
|
||||
[ { type: 0, data: write_varint49(R + 726270)} ]
|
||||
])});
|
||||
cruids[5].push({type: 0, data: write_varint49(R)});
|
||||
cruids[6].push({type: 0, data: write_varint49(R)});
|
||||
@ -1007,7 +1007,7 @@ function write_numbers_iwa(wb: WorkBook, opts: any): CFB$Container {
|
||||
{
|
||||
sstdata[3] = [];
|
||||
SST.forEach((str, i) => {
|
||||
sstdata[3].push({type: 2, data: write_shallow([ [],
|
||||
sstdata[3].push({type: 2, data: write_shallow([ [],
|
||||
[ { type: 0, data: write_varint49(i) } ],
|
||||
[ { type: 0, data: write_varint49(1) } ],
|
||||
[ { type: 2, data: stru8(str) } ]
|
||||
|
2716
testnocp.ts
Normal file
2716
testnocp.ts
Normal file
File diff suppressed because it is too large
Load Diff
45
xlsx.flow.js
45
xlsx.flow.js
@ -104,6 +104,32 @@ function Base64_encode(input) {
|
||||
}
|
||||
return o;
|
||||
}
|
||||
function Base64_encode_pass(input) {
|
||||
var o = "";
|
||||
var c1 = 0, c2 = 0, c3 = 0, e1 = 0, e2 = 0, e3 = 0, e4 = 0;
|
||||
for (var i = 0; i < input.length; ) {
|
||||
c1 = input.charCodeAt(i++);
|
||||
if (c1 > 255)
|
||||
c1 = 95;
|
||||
e1 = c1 >> 2;
|
||||
c2 = input.charCodeAt(i++);
|
||||
if (c2 > 255)
|
||||
c2 = 95;
|
||||
e2 = (c1 & 3) << 4 | c2 >> 4;
|
||||
c3 = input.charCodeAt(i++);
|
||||
if (c3 > 255)
|
||||
c3 = 95;
|
||||
e3 = (c2 & 15) << 2 | c3 >> 6;
|
||||
e4 = c3 & 63;
|
||||
if (isNaN(c2)) {
|
||||
e3 = e4 = 64;
|
||||
} else if (isNaN(c3)) {
|
||||
e4 = 64;
|
||||
}
|
||||
o += Base64_map.charAt(e1) + Base64_map.charAt(e2) + Base64_map.charAt(e3) + Base64_map.charAt(e4);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
function Base64_decode(input) {
|
||||
var o = "";
|
||||
var c1 = 0, c2 = 0, c3 = 0, e1 = 0, e2 = 0, e3 = 0, e4 = 0;
|
||||
@ -3439,9 +3465,7 @@ function fuzzydate(s/*:string*/)/*:Date*/ {
|
||||
lower = lower.replace(/[^a-z]/g,"").replace(/([^a-z]|^)[ap]m?([^a-z]|$)/,"");
|
||||
if(lower.length > 3 && lower_months.indexOf(lower) == -1) return n;
|
||||
} else if(lower.replace(/[ap]m?/, "").match(/[a-z]/)) return n;
|
||||
if(y < 0 || y > 8099) return n;
|
||||
if((m > 0 || d > 1) && y != 101) return o;
|
||||
if(s.match(/[^-0-9:,\/\\]/)) return n;
|
||||
if(y < 0 || y > 8099 || s.match(/[^-0-9:,\/\\]/)) return n;
|
||||
return o;
|
||||
}
|
||||
|
||||
@ -3807,7 +3831,7 @@ function xlml_normalize(d)/*:string*/ {
|
||||
throw new Error("Bad input format: expected Buffer or string");
|
||||
}
|
||||
/* UOS uses CJK in tags */
|
||||
var xlmlregex = /<(\/?)([^\s?><!\/:]*:|)([^\s?<>:\/]+)(?:[\s?:\/][^>]*)?>/mg;
|
||||
var xlmlregex = /<(\/?)([^\s?><!\/:]*:|)([^\s?<>:\/]+)(?:[\s?:\/](?:[^>=]|="[^"]*?")*)?>/mg;
|
||||
//var xlmlregex = /<(\/?)([a-z0-9]*:|)(\w+)[^>]*>/mg;
|
||||
|
||||
var XMLNS = ({
|
||||
@ -7705,7 +7729,7 @@ function dbf_to_aoa(buf, opts)/*:AOA*/ {
|
||||
var ww = l7 ? 32 : 11;
|
||||
while(d.l < hend && d[d.l] != 0x0d) {
|
||||
field = ({}/*:any*/);
|
||||
field.name = $cptable.utils.decode(current_cp, d.slice(d.l, d.l+ww)).replace(/[\u0000\r\n].*$/g,"");
|
||||
field.name = (typeof $cptable !== "undefined" ? $cptable.utils.decode(current_cp, d.slice(d.l, d.l+ww)) : a2s(d.slice(d.l, d.l + ww))).replace(/[\u0000\r\n].*$/g,"");
|
||||
d.l += ww;
|
||||
field.type = String.fromCharCode(d.read_shift(1));
|
||||
if(ft != 0x02 && !l7) field.offset = d.read_shift(4);
|
||||
@ -7759,7 +7783,7 @@ function dbf_to_aoa(buf, opts)/*:AOA*/ {
|
||||
for(C = 0; C != fields.length; ++C) {
|
||||
var dd = d.slice(d.l, d.l+fields[C].len); d.l+=fields[C].len;
|
||||
prep_blob(dd, 0);
|
||||
var s = $cptable.utils.decode(current_cp, dd);
|
||||
var s = typeof $cptable !== "undefined" ? $cptable.utils.decode(current_cp, dd) : a2s(dd);
|
||||
switch(fields[C].type) {
|
||||
case 'C':
|
||||
// NOTE: it is conventional to write ' / / ' for empty dates
|
||||
@ -15401,7 +15425,7 @@ function write_ws_xml_sheetviews(ws, opts, idx, wb)/*:string*/ {
|
||||
|
||||
function write_ws_xml_cell(cell/*:Cell*/, ref, ws, opts/*::, idx, wb*/)/*:string*/ {
|
||||
if(cell.c) ws['!comments'].push([ref, cell.c]);
|
||||
if(cell.v === undefined && typeof cell.f !== "string" || cell.t === 'z' && !cell.f) return "";
|
||||
if((cell.v === undefined || cell.t === "z" && !(opts||{}).sheetStubs) && typeof cell.f !== "string" && typeof cell.z == "undefined") return "";
|
||||
var vv = "";
|
||||
var oldt = cell.t, oldv = cell.v;
|
||||
if(cell.t !== "z") switch(cell.t) {
|
||||
@ -17090,7 +17114,7 @@ function safe1904(wb/*:Workbook*/)/*:string*/ {
|
||||
return parsexmlbool(wb.Workbook.WBProps.date1904) ? "true" : "false";
|
||||
}
|
||||
|
||||
var badchars = /*#__PURE__*/"][*?\/\\".split("");
|
||||
var badchars = /*#__PURE__*/":][*?\/\\".split("");
|
||||
function check_ws_name(n/*:string*/, safe/*:?boolean*/)/*:boolean*/ {
|
||||
if(n.length > 31) { if(safe) return false; throw new Error("Sheet names cannot exceed 31 chars"); }
|
||||
var _good = true;
|
||||
@ -24859,7 +24883,7 @@ function read_plaintext_raw(data/*:RawData*/, o/*:ParseOpts*/)/*:Workbook*/ {
|
||||
function read_utf16(data/*:RawData*/, o/*:ParseOpts*/)/*:Workbook*/ {
|
||||
var d = data;
|
||||
if(o.type == 'base64') d = Base64_decode(d);
|
||||
d = $cptable.utils.decode(1200, d.slice(2), 'str');
|
||||
d = typeof $cptable !== "undefined" ? $cptable.utils.decode(1200, d.slice(2), 'str') : utf16leread(d.slice(2));
|
||||
o.type = "binary";
|
||||
return read_plaintext(d, o);
|
||||
}
|
||||
@ -24876,6 +24900,7 @@ function read_prn(data, d, o, str) {
|
||||
function readSync(data/*:RawData*/, opts/*:?ParseOpts*/)/*:Workbook*/ {
|
||||
reset_cp();
|
||||
var o = opts||{};
|
||||
if(o.codepage && typeof $cptable === "undefined") console.error("Codepage tables are not loaded. Non-ASCII characters may not give expected results");
|
||||
if(typeof ArrayBuffer !== 'undefined' && data instanceof ArrayBuffer) return readSync(new Uint8Array(data), (o = dup(o), o.type = "array", o));
|
||||
if(typeof Uint8Array !== 'undefined' && data instanceof Uint8Array && !o.type) o.type = typeof Deno !== "undefined" ? "buffer" : "array";
|
||||
var d = data, n = [0,0,0,0], str = false;
|
||||
@ -25013,7 +25038,7 @@ function write_string_type(out/*:string*/, opts/*:WriteOpts*/, bom/*:?string*/)/
|
||||
|
||||
function write_stxt_type(out/*:string*/, opts/*:WriteOpts*/)/*:any*/ {
|
||||
switch(opts.type) {
|
||||
case "base64": return Base64_encode(out);
|
||||
case "base64": return Base64_encode_pass(out);
|
||||
case "binary": return out;
|
||||
case "string": return out; /* override in sheet_to_txt */
|
||||
case "file": return write_dl(opts.file, out, 'binary');
|
||||
|
45
xlsx.js
generated
45
xlsx.js
generated
@ -103,6 +103,32 @@ function Base64_encode(input) {
|
||||
}
|
||||
return o;
|
||||
}
|
||||
function Base64_encode_pass(input) {
|
||||
var o = "";
|
||||
var c1 = 0, c2 = 0, c3 = 0, e1 = 0, e2 = 0, e3 = 0, e4 = 0;
|
||||
for (var i = 0; i < input.length; ) {
|
||||
c1 = input.charCodeAt(i++);
|
||||
if (c1 > 255)
|
||||
c1 = 95;
|
||||
e1 = c1 >> 2;
|
||||
c2 = input.charCodeAt(i++);
|
||||
if (c2 > 255)
|
||||
c2 = 95;
|
||||
e2 = (c1 & 3) << 4 | c2 >> 4;
|
||||
c3 = input.charCodeAt(i++);
|
||||
if (c3 > 255)
|
||||
c3 = 95;
|
||||
e3 = (c2 & 15) << 2 | c3 >> 6;
|
||||
e4 = c3 & 63;
|
||||
if (isNaN(c2)) {
|
||||
e3 = e4 = 64;
|
||||
} else if (isNaN(c3)) {
|
||||
e4 = 64;
|
||||
}
|
||||
o += Base64_map.charAt(e1) + Base64_map.charAt(e2) + Base64_map.charAt(e3) + Base64_map.charAt(e4);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
function Base64_decode(input) {
|
||||
var o = "";
|
||||
var c1 = 0, c2 = 0, c3 = 0, e1 = 0, e2 = 0, e3 = 0, e4 = 0;
|
||||
@ -3365,9 +3391,7 @@ function fuzzydate(s) {
|
||||
lower = lower.replace(/[^a-z]/g,"").replace(/([^a-z]|^)[ap]m?([^a-z]|$)/,"");
|
||||
if(lower.length > 3 && lower_months.indexOf(lower) == -1) return n;
|
||||
} else if(lower.replace(/[ap]m?/, "").match(/[a-z]/)) return n;
|
||||
if(y < 0 || y > 8099) return n;
|
||||
if((m > 0 || d > 1) && y != 101) return o;
|
||||
if(s.match(/[^-0-9:,\/\\]/)) return n;
|
||||
if(y < 0 || y > 8099 || s.match(/[^-0-9:,\/\\]/)) return n;
|
||||
return o;
|
||||
}
|
||||
|
||||
@ -3733,7 +3757,7 @@ function xlml_normalize(d) {
|
||||
throw new Error("Bad input format: expected Buffer or string");
|
||||
}
|
||||
/* UOS uses CJK in tags */
|
||||
var xlmlregex = /<(\/?)([^\s?><!\/:]*:|)([^\s?<>:\/]+)(?:[\s?:\/][^>]*)?>/mg;
|
||||
var xlmlregex = /<(\/?)([^\s?><!\/:]*:|)([^\s?<>:\/]+)(?:[\s?:\/](?:[^>=]|="[^"]*?")*)?>/mg;
|
||||
//var xlmlregex = /<(\/?)([a-z0-9]*:|)(\w+)[^>]*>/mg;
|
||||
|
||||
var XMLNS = ({
|
||||
@ -7615,7 +7639,7 @@ var fields = [], field = ({});
|
||||
var ww = l7 ? 32 : 11;
|
||||
while(d.l < hend && d[d.l] != 0x0d) {
|
||||
field = ({});
|
||||
field.name = $cptable.utils.decode(current_cp, d.slice(d.l, d.l+ww)).replace(/[\u0000\r\n].*$/g,"");
|
||||
field.name = (typeof $cptable !== "undefined" ? $cptable.utils.decode(current_cp, d.slice(d.l, d.l+ww)) : a2s(d.slice(d.l, d.l + ww))).replace(/[\u0000\r\n].*$/g,"");
|
||||
d.l += ww;
|
||||
field.type = String.fromCharCode(d.read_shift(1));
|
||||
if(ft != 0x02 && !l7) field.offset = d.read_shift(4);
|
||||
@ -7669,7 +7693,7 @@ var fields = [], field = ({});
|
||||
for(C = 0; C != fields.length; ++C) {
|
||||
var dd = d.slice(d.l, d.l+fields[C].len); d.l+=fields[C].len;
|
||||
prep_blob(dd, 0);
|
||||
var s = $cptable.utils.decode(current_cp, dd);
|
||||
var s = typeof $cptable !== "undefined" ? $cptable.utils.decode(current_cp, dd) : a2s(dd);
|
||||
switch(fields[C].type) {
|
||||
case 'C':
|
||||
// NOTE: it is conventional to write ' / / ' for empty dates
|
||||
@ -15307,7 +15331,7 @@ function write_ws_xml_sheetviews(ws, opts, idx, wb) {
|
||||
|
||||
function write_ws_xml_cell(cell, ref, ws, opts) {
|
||||
if(cell.c) ws['!comments'].push([ref, cell.c]);
|
||||
if(cell.v === undefined && typeof cell.f !== "string" || cell.t === 'z' && !cell.f) return "";
|
||||
if((cell.v === undefined || cell.t === "z" && !(opts||{}).sheetStubs) && typeof cell.f !== "string" && typeof cell.z == "undefined") return "";
|
||||
var vv = "";
|
||||
var oldt = cell.t, oldv = cell.v;
|
||||
if(cell.t !== "z") switch(cell.t) {
|
||||
@ -16995,7 +17019,7 @@ function safe1904(wb) {
|
||||
return parsexmlbool(wb.Workbook.WBProps.date1904) ? "true" : "false";
|
||||
}
|
||||
|
||||
var badchars = "][*?\/\\".split("");
|
||||
var badchars = ":][*?\/\\".split("");
|
||||
function check_ws_name(n, safe) {
|
||||
if(n.length > 31) { if(safe) return false; throw new Error("Sheet names cannot exceed 31 chars"); }
|
||||
var _good = true;
|
||||
@ -24745,7 +24769,7 @@ function read_plaintext_raw(data, o) {
|
||||
function read_utf16(data, o) {
|
||||
var d = data;
|
||||
if(o.type == 'base64') d = Base64_decode(d);
|
||||
d = $cptable.utils.decode(1200, d.slice(2), 'str');
|
||||
d = typeof $cptable !== "undefined" ? $cptable.utils.decode(1200, d.slice(2), 'str') : utf16leread(d.slice(2));
|
||||
o.type = "binary";
|
||||
return read_plaintext(d, o);
|
||||
}
|
||||
@ -24762,6 +24786,7 @@ function read_prn(data, d, o, str) {
|
||||
function readSync(data, opts) {
|
||||
reset_cp();
|
||||
var o = opts||{};
|
||||
if(o.codepage && typeof $cptable === "undefined") console.error("Codepage tables are not loaded. Non-ASCII characters may not give expected results");
|
||||
if(typeof ArrayBuffer !== 'undefined' && data instanceof ArrayBuffer) return readSync(new Uint8Array(data), (o = dup(o), o.type = "array", o));
|
||||
if(typeof Uint8Array !== 'undefined' && data instanceof Uint8Array && !o.type) o.type = typeof Deno !== "undefined" ? "buffer" : "array";
|
||||
var d = data, n = [0,0,0,0], str = false;
|
||||
@ -24898,7 +24923,7 @@ function write_string_type(out, opts, bom) {
|
||||
|
||||
function write_stxt_type(out, opts) {
|
||||
switch(opts.type) {
|
||||
case "base64": return Base64_encode(out);
|
||||
case "base64": return Base64_encode_pass(out);
|
||||
case "binary": return out;
|
||||
case "string": return out; /* override in sheet_to_txt */
|
||||
case "file": return write_dl(opts.file, out, 'binary');
|
||||
|
45
xlsx.mjs
generated
45
xlsx.mjs
generated
@ -103,6 +103,32 @@ function Base64_encode(input) {
|
||||
}
|
||||
return o;
|
||||
}
|
||||
function Base64_encode_pass(input) {
|
||||
var o = "";
|
||||
var c1 = 0, c2 = 0, c3 = 0, e1 = 0, e2 = 0, e3 = 0, e4 = 0;
|
||||
for (var i = 0; i < input.length; ) {
|
||||
c1 = input.charCodeAt(i++);
|
||||
if (c1 > 255)
|
||||
c1 = 95;
|
||||
e1 = c1 >> 2;
|
||||
c2 = input.charCodeAt(i++);
|
||||
if (c2 > 255)
|
||||
c2 = 95;
|
||||
e2 = (c1 & 3) << 4 | c2 >> 4;
|
||||
c3 = input.charCodeAt(i++);
|
||||
if (c3 > 255)
|
||||
c3 = 95;
|
||||
e3 = (c2 & 15) << 2 | c3 >> 6;
|
||||
e4 = c3 & 63;
|
||||
if (isNaN(c2)) {
|
||||
e3 = e4 = 64;
|
||||
} else if (isNaN(c3)) {
|
||||
e4 = 64;
|
||||
}
|
||||
o += Base64_map.charAt(e1) + Base64_map.charAt(e2) + Base64_map.charAt(e3) + Base64_map.charAt(e4);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
function Base64_decode(input) {
|
||||
var o = "";
|
||||
var c1 = 0, c2 = 0, c3 = 0, e1 = 0, e2 = 0, e3 = 0, e4 = 0;
|
||||
@ -3438,9 +3464,7 @@ function fuzzydate(s/*:string*/)/*:Date*/ {
|
||||
lower = lower.replace(/[^a-z]/g,"").replace(/([^a-z]|^)[ap]m?([^a-z]|$)/,"");
|
||||
if(lower.length > 3 && lower_months.indexOf(lower) == -1) return n;
|
||||
} else if(lower.replace(/[ap]m?/, "").match(/[a-z]/)) return n;
|
||||
if(y < 0 || y > 8099) return n;
|
||||
if((m > 0 || d > 1) && y != 101) return o;
|
||||
if(s.match(/[^-0-9:,\/\\]/)) return n;
|
||||
if(y < 0 || y > 8099 || s.match(/[^-0-9:,\/\\]/)) return n;
|
||||
return o;
|
||||
}
|
||||
|
||||
@ -3806,7 +3830,7 @@ function xlml_normalize(d)/*:string*/ {
|
||||
throw new Error("Bad input format: expected Buffer or string");
|
||||
}
|
||||
/* UOS uses CJK in tags */
|
||||
var xlmlregex = /<(\/?)([^\s?><!\/:]*:|)([^\s?<>:\/]+)(?:[\s?:\/][^>]*)?>/mg;
|
||||
var xlmlregex = /<(\/?)([^\s?><!\/:]*:|)([^\s?<>:\/]+)(?:[\s?:\/](?:[^>=]|="[^"]*?")*)?>/mg;
|
||||
//var xlmlregex = /<(\/?)([a-z0-9]*:|)(\w+)[^>]*>/mg;
|
||||
|
||||
var XMLNS = ({
|
||||
@ -7700,7 +7724,7 @@ function dbf_to_aoa(buf, opts)/*:AOA*/ {
|
||||
var ww = l7 ? 32 : 11;
|
||||
while(d.l < hend && d[d.l] != 0x0d) {
|
||||
field = ({}/*:any*/);
|
||||
field.name = $cptable.utils.decode(current_cp, d.slice(d.l, d.l+ww)).replace(/[\u0000\r\n].*$/g,"");
|
||||
field.name = (typeof $cptable !== "undefined" ? $cptable.utils.decode(current_cp, d.slice(d.l, d.l+ww)) : a2s(d.slice(d.l, d.l + ww))).replace(/[\u0000\r\n].*$/g,"");
|
||||
d.l += ww;
|
||||
field.type = String.fromCharCode(d.read_shift(1));
|
||||
if(ft != 0x02 && !l7) field.offset = d.read_shift(4);
|
||||
@ -7754,7 +7778,7 @@ function dbf_to_aoa(buf, opts)/*:AOA*/ {
|
||||
for(C = 0; C != fields.length; ++C) {
|
||||
var dd = d.slice(d.l, d.l+fields[C].len); d.l+=fields[C].len;
|
||||
prep_blob(dd, 0);
|
||||
var s = $cptable.utils.decode(current_cp, dd);
|
||||
var s = typeof $cptable !== "undefined" ? $cptable.utils.decode(current_cp, dd) : a2s(dd);
|
||||
switch(fields[C].type) {
|
||||
case 'C':
|
||||
// NOTE: it is conventional to write ' / / ' for empty dates
|
||||
@ -15396,7 +15420,7 @@ function write_ws_xml_sheetviews(ws, opts, idx, wb)/*:string*/ {
|
||||
|
||||
function write_ws_xml_cell(cell/*:Cell*/, ref, ws, opts/*::, idx, wb*/)/*:string*/ {
|
||||
if(cell.c) ws['!comments'].push([ref, cell.c]);
|
||||
if(cell.v === undefined && typeof cell.f !== "string" || cell.t === 'z' && !cell.f) return "";
|
||||
if((cell.v === undefined || cell.t === "z" && !(opts||{}).sheetStubs) && typeof cell.f !== "string" && typeof cell.z == "undefined") return "";
|
||||
var vv = "";
|
||||
var oldt = cell.t, oldv = cell.v;
|
||||
if(cell.t !== "z") switch(cell.t) {
|
||||
@ -17085,7 +17109,7 @@ function safe1904(wb/*:Workbook*/)/*:string*/ {
|
||||
return parsexmlbool(wb.Workbook.WBProps.date1904) ? "true" : "false";
|
||||
}
|
||||
|
||||
var badchars = /*#__PURE__*/"][*?\/\\".split("");
|
||||
var badchars = /*#__PURE__*/":][*?\/\\".split("");
|
||||
function check_ws_name(n/*:string*/, safe/*:?boolean*/)/*:boolean*/ {
|
||||
if(n.length > 31) { if(safe) return false; throw new Error("Sheet names cannot exceed 31 chars"); }
|
||||
var _good = true;
|
||||
@ -24854,7 +24878,7 @@ function read_plaintext_raw(data/*:RawData*/, o/*:ParseOpts*/)/*:Workbook*/ {
|
||||
function read_utf16(data/*:RawData*/, o/*:ParseOpts*/)/*:Workbook*/ {
|
||||
var d = data;
|
||||
if(o.type == 'base64') d = Base64_decode(d);
|
||||
d = $cptable.utils.decode(1200, d.slice(2), 'str');
|
||||
d = typeof $cptable !== "undefined" ? $cptable.utils.decode(1200, d.slice(2), 'str') : utf16leread(d.slice(2));
|
||||
o.type = "binary";
|
||||
return read_plaintext(d, o);
|
||||
}
|
||||
@ -24871,6 +24895,7 @@ function read_prn(data, d, o, str) {
|
||||
function readSync(data/*:RawData*/, opts/*:?ParseOpts*/)/*:Workbook*/ {
|
||||
reset_cp();
|
||||
var o = opts||{};
|
||||
if(o.codepage && typeof $cptable === "undefined") console.error("Codepage tables are not loaded. Non-ASCII characters may not give expected results");
|
||||
if(typeof ArrayBuffer !== 'undefined' && data instanceof ArrayBuffer) return readSync(new Uint8Array(data), (o = dup(o), o.type = "array", o));
|
||||
if(typeof Uint8Array !== 'undefined' && data instanceof Uint8Array && !o.type) o.type = typeof Deno !== "undefined" ? "buffer" : "array";
|
||||
var d = data, n = [0,0,0,0], str = false;
|
||||
@ -25008,7 +25033,7 @@ function write_string_type(out/*:string*/, opts/*:WriteOpts*/, bom/*:?string*/)/
|
||||
|
||||
function write_stxt_type(out/*:string*/, opts/*:WriteOpts*/)/*:any*/ {
|
||||
switch(opts.type) {
|
||||
case "base64": return Base64_encode(out);
|
||||
case "base64": return Base64_encode_pass(out);
|
||||
case "binary": return out;
|
||||
case "string": return out; /* override in sheet_to_txt */
|
||||
case "file": return write_dl(opts.file, out, 'binary');
|
||||
|
Loading…
Reference in New Issue
Block a user