forked from sheetjs/sheetjs
more lotus 1-2-3 formula functions
This commit is contained in:
parent
2ff31276b0
commit
e43071fc64
@ -164,10 +164,10 @@ These scripts are also available on the CDN:
|
||||
</details>
|
||||
|
||||
|
||||
[Bower](https://bower.io/search/?q=js-xlsx) will pull the entire repo:
|
||||
[Bower](https://bower.io/) plays nice with the CDN tarballs:
|
||||
|
||||
```bash
|
||||
$ bower install js-xlsx
|
||||
$ npx bower install https://cdn.sheetjs.com/xlsx-0.18.7/xlsx-0.18.7.tgz
|
||||
```
|
||||
|
||||
Bower will place the standalone scripts in `bower_components/js-xlsx/dist/`
|
||||
@ -2591,7 +2591,7 @@ XLSX.write(wb, {Props:{Author:"SheetJS"}});
|
||||
<details>
|
||||
<summary><b>Format Support</b> (click to show)</summary>
|
||||
|
||||
**Defined Names**: XLSX/M, XLSB, BIFF8 XLS, XLML, SYLK
|
||||
**Defined Names**: XLSX/M, XLSB, BIFF8 XLS, XLML, SYLK
|
||||
|
||||
**Unicode Defined Names**: XLSX/M, XLSB, BIFF8 XLS, XLML
|
||||
|
||||
|
@ -30,10 +30,10 @@ var RELS = ({
|
||||
XLMETA: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sheetMetadata",
|
||||
TCMNT: "http://schemas.microsoft.com/office/2017/10/relationships/threadedComment",
|
||||
PEOPLE: "http://schemas.microsoft.com/office/2017/10/relationships/person",
|
||||
CONN: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/connections",
|
||||
VBA: "http://schemas.microsoft.com/office/2006/relationships/vbaProject"
|
||||
}/*:any*/);
|
||||
|
||||
|
||||
/* 9.3.3 Representing Relationships */
|
||||
function get_rels_path(file/*:string*/)/*:string*/ {
|
||||
var n = file.lastIndexOf("/");
|
||||
|
@ -403,16 +403,88 @@ var WK_ = /*#__PURE__*/(function() {
|
||||
]; */
|
||||
/* TODO: flesh out */
|
||||
var FuncTab = {
|
||||
0x1F: ["NA", 0],
|
||||
// 0x20: ["ERR", 0],
|
||||
0x21: ["ABS", 1],
|
||||
0x22: ["TRUNC", 1],
|
||||
0x23: ["SQRT", 1],
|
||||
0x24: ["LOG", 1],
|
||||
0x25: ["LN", 1],
|
||||
0x26: ["PI", 0],
|
||||
0x27: ["SIN", 1],
|
||||
0x28: ["COS", 1],
|
||||
0x29: ["TAN", 1],
|
||||
0x2A: ["ATAN2", 2],
|
||||
0x2B: ["ATAN", 1],
|
||||
0x2C: ["ASIN", 1],
|
||||
0x2D: ["ACOS", 1],
|
||||
0x2E: ["EXP", 1],
|
||||
0x2F: ["MOD", 2],
|
||||
// 0x30
|
||||
0x31: ["ISNA", 1],
|
||||
0x32: ["ISERR", 1],
|
||||
0x33: ["FALSE", 0],
|
||||
0x34: ["TRUE", 0],
|
||||
0x35: ["RAND", 0],
|
||||
// 0x36 DATE
|
||||
// 0x37 NOW
|
||||
// 0x38 PMT
|
||||
// 0x39 PV
|
||||
// 0x3A FV
|
||||
// 0x3B IF
|
||||
// 0x3C DAY
|
||||
// 0x3D MONTH
|
||||
// 0x3E YEAR
|
||||
0x3F: ["ROUND", 2],
|
||||
// 0x40 TIME
|
||||
// 0x41 HOUR
|
||||
// 0x42 MINUTE
|
||||
// 0x43 SECOND
|
||||
0x44: ["ISNUMBER", 1],
|
||||
0x45: ["ISTEXT", 1],
|
||||
0x46: ["LEN", 1],
|
||||
0x47: ["VALUE", 1],
|
||||
// 0x48: ["FIXED", ?? 1],
|
||||
0x49: ["MID", 3],
|
||||
0x4A: ["CHAR", 1],
|
||||
// 0x4B
|
||||
// 0x4C FIND
|
||||
// 0x4D DATEVALUE
|
||||
// 0x4E TIMEVALUE
|
||||
// 0x4F CELL
|
||||
0x50: ["SUM", 69],
|
||||
0x51: ["AVERAGEA", 69],
|
||||
0x52: ["COUNTA", 69],
|
||||
0x53: ["MINA", 69],
|
||||
0x54: ["MAXA", 69],
|
||||
// 0x55 VLOOKUP
|
||||
// 0x56 NPV
|
||||
// 0x57 VAR
|
||||
// 0x58 STD
|
||||
// 0x59 IRR
|
||||
// 0x5A HLOOKUP
|
||||
// 0x5B DSUM
|
||||
// 0x5C DAVERAGE
|
||||
// 0x5D DCOUNTA
|
||||
// 0x5E DMIN
|
||||
// 0x5F DMAX
|
||||
// 0x60 DVARP
|
||||
// 0x61 DSTDEVP
|
||||
// 0x62 INDEX
|
||||
// 0x63 COLS
|
||||
// 0x64 ROWS
|
||||
// 0x65 REPEAT
|
||||
0x66: ["UPPER", 1],
|
||||
0x67: ["LOWER", 1],
|
||||
// 0x68 LEFT
|
||||
// 0x69 RIGHT
|
||||
// 0x6A REPLACE
|
||||
0x6B: ["PROPER", 1],
|
||||
// 0x6C CELL
|
||||
0x6D: ["TRIM", 1],
|
||||
// 0x6E CLEAN
|
||||
0x6F: ["T", 1]
|
||||
// 0x70 V
|
||||
};
|
||||
var BinOpTab = [
|
||||
"", "", "", "", "", "", "", "", // eslint-disable-line no-mixed-spaces-and-tabs
|
||||
|
@ -1,8 +1,7 @@
|
||||
.PHONY: tfjs
|
||||
tfjs:
|
||||
npm install @tensorflow/tfjs
|
||||
node tf.js
|
||||
.PHONY: init
|
||||
init:
|
||||
npm i
|
||||
|
||||
.PHONY: propel
|
||||
propel:
|
||||
node propel.js
|
||||
.PHONY: tfjs
|
||||
tfjs: init
|
||||
node tf.js
|
||||
|
@ -104,30 +104,6 @@ function array_to_sheet(farray, shape, headers) {
|
||||
}
|
||||
```
|
||||
|
||||
#### Tensor Operations with Propel ML
|
||||
|
||||
[Propel ML](http://propelml.org/) `tensor` objects can be transposed:
|
||||
|
||||
```js
|
||||
var tensor = pr.tensor(aoa).transpose();
|
||||
var col1 = tensor.slice(0, 1);
|
||||
var col2 = tensor.slice(1, 1);
|
||||
```
|
||||
|
||||
To export to a worksheet, `dataSync` generates a `Float32Array` that can be
|
||||
re-shaped in JS:
|
||||
|
||||
```js
|
||||
/* extract shape and float array */
|
||||
var tensor = pr.concat([col1, col2]).transpose();
|
||||
var shape = tensor.shape;
|
||||
var farray = tensor.dataSync();
|
||||
var ws = array_to_sheet(farray, shape, ["header1", "header2"]);
|
||||
```
|
||||
|
||||
The demo generates a sample dataset and uses Propel to calculate the OLS linear
|
||||
regression coefficients. Afterwards, the tensors are exported to a new file.
|
||||
|
||||
#### TensorFlow
|
||||
|
||||
[TensorFlow](https://js.tensorflow.org/) `tensor` objects can be created from
|
||||
|
6
demos/array/package.json
Normal file
6
demos/array/package.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"@tensorflow/tfjs": "^3.16.0",
|
||||
"xlsx": "https://cdn.sheetjs.com/xlsx-latest/xlsx-latest.tgz"
|
||||
}
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
/* xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com */
|
||||
/* eslint-env node */
|
||||
var XLSX = require('xlsx');
|
||||
var pr = require('propel');
|
||||
var linest = require('./linest');
|
||||
|
||||
/* generate linreg.xlsx with 100 random points */
|
||||
linest.generate_random_file(100);
|
||||
|
||||
/* get the first worksheet as an array of arrays, skip the first row */
|
||||
var wb = XLSX.readFile('linreg.xlsx');
|
||||
var ws = wb.Sheets[wb.SheetNames[0]];
|
||||
var aoa = XLSX.utils.sheet_to_json(ws, {header:1, raw:true}).slice(1);
|
||||
|
||||
/* calculate the coefficients in JS */
|
||||
(function(aoa) {
|
||||
var x_ = 0, y_ = 0, xx = 0, xy = 0, n = aoa.length;
|
||||
for(var i = 0; i < n; ++i) {
|
||||
x_ += aoa[i][0] / n;
|
||||
y_ += aoa[i][1] / n;
|
||||
xx += aoa[i][0] * aoa[i][0];
|
||||
xy += aoa[i][0] * aoa[i][1];
|
||||
}
|
||||
var m = Math.fround((xy - n * x_ * y_)/(xx - n * x_ * x_));
|
||||
console.log(m, Math.fround(y_ - m * x_), "JS Post");
|
||||
})(aoa);
|
||||
|
||||
/* build X and Y vectors */
|
||||
var tensor = pr.tensor(aoa).transpose();
|
||||
var xs = tensor.slice(0, 1);
|
||||
var ys = tensor.slice(1, 1);
|
||||
|
||||
/* compute the coefficient */
|
||||
var n = xs.size;
|
||||
var x_ = Math.fround(xs.reduceMean().dataSync()[0]);
|
||||
var y_ = Math.fround(ys.reduceMean().dataSync()[0]);
|
||||
var xx = Math.fround(xs.dot(xs.transpose()).dataSync()[0]);
|
||||
var xy = Math.fround(xs.dot(ys.transpose()).dataSync()[0]);
|
||||
var m = Math.fround((xy - n * x_ * y_)/(xx - n * x_ * x_));
|
||||
var b_ = Math.fround(y_ - m * x_);
|
||||
console.log(m, b_, "Propel");
|
||||
var yh = xs.mul(m).add(b_);
|
||||
|
||||
/* export data to aoa */
|
||||
var prdata = pr.concat([xs, ys, yh]).transpose();
|
||||
var shape = prdata.shape;
|
||||
var prarr = prdata.dataSync();
|
||||
var praoa = [];
|
||||
for(var j = 0; j < shape[0]; ++j) {
|
||||
praoa[j] = [];
|
||||
for(var i = 0; i < shape[1]; ++i) praoa[j][i] = prarr[j * shape[1] + i];
|
||||
}
|
||||
|
||||
/* add headers and export */
|
||||
praoa.unshift(["x", "y", "pred"]);
|
||||
var new_ws = XLSX.utils.aoa_to_sheet(praoa);
|
||||
var new_wb = XLSX.utils.book_new();
|
||||
XLSX.utils.book_append_sheet(new_wb, new_ws, "Sheet1");
|
||||
XLSX.writeFile(new_wb, "propel.xls");
|
@ -1,7 +1,7 @@
|
||||
# Electron
|
||||
|
||||
This library is compatible with Electron and should just work out of the box.
|
||||
The demonstration uses Electron 17.1.0. The library is added via `require` from
|
||||
The demonstration uses Electron 18.2.0. The library is added via `require` from
|
||||
the renderer process.
|
||||
|
||||
The library can also be required from the main process, as shown in this demo
|
||||
|
@ -4,8 +4,8 @@
|
||||
"version": "0.0.0",
|
||||
"main": "main.js",
|
||||
"dependencies": {
|
||||
"@electron/remote": "^2.0.5",
|
||||
"electron": "^17.1.0",
|
||||
"@electron/remote": "^2.0.8",
|
||||
"electron": "^18.2.0",
|
||||
"xlsx": "https://cdn.sheetjs.com/xlsx-latest/xlsx-latest.tgz"
|
||||
},
|
||||
"scripts": {
|
||||
|
1
demos/parcel/.gitignore
vendored
1
demos/parcel/.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
.cache
|
||||
.parcel-cache
|
||||
dist
|
||||
|
@ -1,7 +1,12 @@
|
||||
.PHONY: app
|
||||
app:
|
||||
app: init
|
||||
npx parcel build index.html
|
||||
|
||||
.PHONY: init
|
||||
init:
|
||||
mkdir -p node_modules
|
||||
npm i
|
||||
|
||||
.PHONY: ctest
|
||||
ctest:
|
||||
ctest: init
|
||||
npx parcel index.html
|
||||
|
@ -1 +1,10 @@
|
||||
{ "source": "index.html", "scripts": { "build": "parcel build" } }
|
||||
{
|
||||
"source":"index.html",
|
||||
"scripts": {
|
||||
"build":"parcel build"
|
||||
},
|
||||
"dependencies": {
|
||||
"parcel": "^2.5.0",
|
||||
"xlsx":"https://cdn.sheetjs.com/xlsx-latest/xlsx-latest.tgz"
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com */
|
||||
var SheetJSFT = [
|
||||
"xlsx", "xlsb", "xlsm", "xls", "xml", "csv", "txt", "ods", "fods", "uos", "sylk", "dif", "dbf", "prn", "qpw", "123", "wb*", "wq*", "html", "htm"
|
||||
"xlsx", "xlsb", "xlsm", "xls", "xml", "csv", "txt", "ods", "fods", "uos", "sylk", "dif", "dbf", "prn", "qpw", "123", "wb*", "wq*", "html", "htm", "numbers"
|
||||
].map(function(x) { return "." + x; }).join(",");
|
||||
|
||||
var SJSTemplate = [
|
||||
|
@ -2,6 +2,6 @@
|
||||
"dependencies": {
|
||||
"@nuxt/content": "1.15.1",
|
||||
"nuxt": "2.15.8",
|
||||
"xlsx": "^0.18.3"
|
||||
"xlsx": "https://cdn.sheetjs.com/xlsx-latest/xlsx-latest.tgz"
|
||||
}
|
||||
}
|
||||
|
@ -45,10 +45,10 @@ These scripts are also available on the CDN:
|
||||
</details>
|
||||
|
||||
|
||||
[Bower](https://bower.io/search/?q=js-xlsx) will pull the entire repo:
|
||||
[Bower](https://bower.io/) plays nice with the CDN tarballs:
|
||||
|
||||
```bash
|
||||
$ bower install js-xlsx
|
||||
$ npx bower install https://cdn.sheetjs.com/xlsx-0.18.7/xlsx-0.18.7.tgz
|
||||
```
|
||||
|
||||
Bower will place the standalone scripts in `bower_components/js-xlsx/dist/`
|
||||
|
@ -158,10 +158,10 @@ These scripts are also available on the CDN:
|
||||
|
||||
|
||||
|
||||
[Bower](https://bower.io/search/?q=js-xlsx) will pull the entire repo:
|
||||
[Bower](https://bower.io/) plays nice with the CDN tarballs:
|
||||
|
||||
```bash
|
||||
$ bower install js-xlsx
|
||||
$ npx bower install https://cdn.sheetjs.com/xlsx-0.18.7/xlsx-0.18.7.tgz
|
||||
```
|
||||
|
||||
Bower will place the standalone scripts in `bower_components/js-xlsx/dist/`
|
||||
@ -2439,7 +2439,7 @@ XLSX.write(wb, {Props:{Author:"SheetJS"}});
|
||||
#### Defined Names
|
||||
|
||||
|
||||
**Defined Names**: XLSX/M, XLSB, BIFF8 XLS, XLML, SYLK
|
||||
**Defined Names**: XLSX/M, XLSB, BIFF8 XLS, XLML, SYLK
|
||||
|
||||
**Unicode Defined Names**: XLSX/M, XLSB, BIFF8 XLS, XLML
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user