stox skip blank worksheets [ci skip]

This commit is contained in:
SheetJS 2022-08-03 12:37:10 -04:00
parent d55b7a3063
commit c02eb14255
68 changed files with 29 additions and 2720 deletions

@ -26,7 +26,7 @@ can be installed with Bash on Windows or with `cygwin`.
- [`IndexedDB`](https://docs.sheetjs.com/docs/getting-started/demos/database#indexeddb)
**Frameworks**
- [`Angular.JS`](angular/)
- [`Angular.JS`](https://docs.sheetjs.com/docs/getting-started/demos/legacy#angularjs)
- [`Angular 2+ and Ionic`](angular2/)
- [`Knockout`](https://docs.sheetjs.com/docs/getting-started/demos/legacy#knockoutjs)
- [`Meteor`](meteor/)
@ -34,17 +34,19 @@ can be installed with Bash on Windows or with `cygwin`.
- [`VueJS, WeeX and NuxtJS`](vue/)
**Front-End UI Components**
- [`canvas-datagrid`](datagrid/)
- [`canvas-datagrid`](https://docs.sheetjs.com/docs/getting-started/demos/grid#canvas-datagrid)
- [`x-spreadsheet`](xspreadsheet/)
- [`react-data-grid`](react/modify/)
- [`vue3-table-light`](vue/modify/)
- [`angular-ui-grid`](https://docs.sheetjs.com/docs/getting-started/demos/grid#angular-ui-grid)
**Platforms and Integrations**
- [`Command-Line Tools`](https://docs.sheetjs.com/docs/getting-started/demos/cli)
- [`NodeJS Server-Side Processing`](server/)
- [`Deno`](deno/)
- [`Electron`](electron/)
- [`NW.js`](nwjs/)
- [`Chrome / Chromium Extension`](chrome/)
- [`NW.js`](https://docs.sheetjs.com/docs/getting-started/demos/desktop#nwjs)
- [`Chrome / Chromium Extension`](https://docs.sheetjs.com/docs/getting-started/demos/chromium)
- [`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)
@ -53,10 +55,9 @@ can be installed with Bash on Windows or with `cygwin`.
- [`Headless Automation`](https://docs.sheetjs.com/docs/getting-started/demos/headless)
- [`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)
- [`NoSQL, K/V, and Unstructured Data Stores`](https://docs.sheetjs.com/docs/getting-started/demos/nosql)
- [`internet explorer`](oldie/)
- [`Legacy Internet Explorer`](oldie/)
**Bundlers and Tooling**
- [`browserify`](https://docs.sheetjs.com/docs/getting-started/demos/bundler#browserify)
@ -68,7 +69,6 @@ can be installed with Bash on Windows or with `cygwin`.
- [`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)

@ -1,148 +1,10 @@
# AngularJS
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 an Angular demo! You can proceed
as you would with any other browser-friendly library.
This demo uses AngularJS 1.5.0.
## Array of Objects
A common data table is often stored as an array of objects:
```js
$scope.data = [
{ Name: "Bill Clinton", Index: 42 },
{ Name: "GeorgeW Bush", Index: 43 },
{ Name: "Barack Obama", Index: 44 },
{ Name: "Donald Trump", Index: 45 }
];
```
This neatly maps to a table with `ng-repeat`:
```html
<table id="sjs-table">
<tr><th>Name</th><th>Index</th></tr>
<tr ng-repeat="row in data">
<td>{{row.Name}}</td>
<td>{{row.Index}}</td>
</tr>
</table>
```
The `$http` service can request binary data using the `"arraybuffer"` response
type coupled with `XLSX.read` with type `"array"`:
```js
$http({
method:'GET',
url:'https://sheetjs.com/pres.xlsx',
responseType:'arraybuffer'
}).then(function(data) {
var wb = XLSX.read(data.data, {type:"array"});
var d = XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]]);
$scope.data = d;
}, function(err) { console.log(err); });
```
The HTML table can be directly exported with `XLSX.utils.table_to_book`:
```js
var wb = XLSX.utils.table_to_book(document.getElementById('sjs-table'));
XLSX.writeFile(wb, "export.xlsx");
```
## Import Directive
A general import directive is fairly straightforward:
- Define the `importSheetJs` directive in the app:
```js
app.directive("importSheetJs", [SheetJSImportDirective]);
```
- Add the attribute `import-sheet-js=""` to the file input element:
```html
<input type="file" import-sheet-js="" multiple="false" />
```
- Define the directive:
```js
function SheetJSImportDirective() {
return {
scope: { opts: '=' },
link: function ($scope, $elm) {
$elm.on('change', function (changeEvent) {
var reader = new FileReader();
reader.onload = function (e) {
/* read workbook */
var ab = e.target.result;
var workbook = XLSX.read(ab);
/* DO SOMETHING WITH workbook HERE */
};
reader.readAsArrayBuffer(changeEvent.target.files[0]);
});
}
};
}
```
## Export Service
An export can be triggered at any point! Depending on how data is represented,
a workbook object can be built using the utility functions. For example, using
an array of objects:
```js
/* starting from this data */
var data = [
{ name: "Barack Obama", pres: 44 },
{ name: "Donald Trump", pres: 45 }
];
/* generate a worksheet */
var ws = XLSX.utils.json_to_sheet(data);
/* add to workbook */
var wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, "Presidents");
/* write workbook and force a download */
XLSX.writeFile(wb, "sheetjs.xlsx");
```
## Demo
`grid.html` uses `angular-ui-grid` to display a table. The library does not
provide any way to modify the import button, so the demo includes a simple
directive for a HTML File Input control. It also includes a sample service for
export which adds an item to the export menu.
The demo `SheetJSImportDirective` follows the prescription from the README for
File input controls using `readAsArrayBuffer`, converting to a suitable
representation and updating the scope.
`SheetJSExportService` exposes export functions for `XLSB` and `XLSX`. Other
file formats can be exported by changing the `bookType` variable. It grabs
values from the grid, builds an array of arrays, generates a workbook and forces
a download. By setting the `filename` and `sheetname` options in the `ui-grid`
options, the output can be controlled.
The content has been reorganized;
- [The "Legacy Frameworks" section](https://docs.sheetjs.com/docs/getting-started/demos/legacy#angularjs)
covers the AngularJS basics.
- [The "Angular UI Grid" section](https://docs.sheetjs.com/docs/getting-started/demos/legacy#angularjs)
covers the integration with Angular UI Grid.
[![Analytics](https://ga-beacon.appspot.com/UA-36810333-1/SheetJS/js-xlsx?pixel)](https://github.com/SheetJS/js-xlsx)

@ -1,96 +0,0 @@
/* xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com */
/* eslint-env browser */
/* global XLSX */
/* exported SheetJSExportService, SheetJSImportDirective */
function SheetJSExportService(uiGridExporterService) {
function exportSheetJS(gridApi, wopts) {
var columns = uiGridExporterService.getColumnHeaders(gridApi.grid, 'all');
var data = uiGridExporterService.getData(gridApi.grid, 'all', 'all');
var fileName = gridApi.grid.options.filename || 'SheetJS';
fileName += wopts.bookType ? "." + wopts.bookType : '.xlsx';
var sheetName = gridApi.grid.options.sheetname || 'Sheet1';
var wb = XLSX.utils.book_new(), ws = uigrid_to_sheet(data, columns);
XLSX.utils.book_append_sheet(wb, ws, sheetName);
XLSX.writeFile(wb, fileName);
}
var service = {};
service.exportXLSB = function exportXLSB(gridApi) { return exportSheetJS(gridApi, { bookType: 'xlsb', bookSST: true, type: 'array' }); };
service.exportXLSX = function exportXLSX(gridApi) { return exportSheetJS(gridApi, { bookType: 'xlsx', bookSST: true, type: 'array' }); }
return service;
/* utilities */
function uigrid_to_sheet(data, columns) {
var o = [], oo = [], i = 0, j = 0;
/* column headers */
for(j = 0; j < columns.length; ++j) oo.push(get_value(columns[j]));
o.push(oo);
/* table data */
for(i = 0; i < data.length; ++i) {
oo = [];
for(j = 0; j < data[i].length; ++j) oo.push(get_value(data[i][j]));
o.push(oo);
}
/* aoa_to_sheet converts an array of arrays into a worksheet object */
return XLSX.utils.aoa_to_sheet(o);
}
function get_value(col) {
if(!col) return col;
if(col.value) return col.value;
if(col.displayName) return col.displayName;
if(col.name) return col.name;
return null;
}
}
function SheetJSImportDirective() {
return {
scope: { opts: '=' },
link: function($scope, $elm) {
$elm.on('change', function(changeEvent) {
var reader = new FileReader();
reader.onload = function(e) {
/* read workbook */
var ab = e.target.result;
var wb = XLSX.read(ab);
/* grab first sheet */
var wsname = wb.SheetNames[0];
var ws = wb.Sheets[wsname];
/* grab first row and generate column headers */
var aoa = XLSX.utils.sheet_to_json(ws, {header:1, raw:false});
var cols = [];
for(var i = 0; i < aoa[0].length; ++i) cols[i] = { field: aoa[0][i] };
/* generate rest of the data */
var data = [];
for(var r = 1; r < aoa.length; ++r) {
data[r-1] = {};
for(i = 0; i < aoa[r].length; ++i) {
if(aoa[r][i] == null) continue;
data[r-1][aoa[0][i]] = aoa[r][i];
}
}
/* update scope */
$scope.$apply(function() {
$scope.opts.columnDefs = cols;
$scope.opts.data = data;
});
};
reader.readAsArrayBuffer(changeEvent.target.files[0]);
});
}
};
}

45
demos/angular/app.js vendored

@ -1,45 +0,0 @@
/* xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com */
/* eslint-env browser */
/* global angular, SheetJSExportService, SheetJSImportDirective */
var app = angular.module('app', ['ngAnimate', 'ngTouch', 'ui.grid', 'ui.grid.selection', 'ui.grid.exporter']);
/* Inject SheetJSExportService */
app.factory('SheetJSExportService', SheetJSExportService);
SheetJSExportService.inject = ['uiGridExporterService'];
app.controller('MainCtrl', ['$scope', '$http','SheetJSExportService', function($scope, $http, SheetJSExportService) {
$scope.gridOptions = {
columnDefs: [
{ field: 'name' },
{ field: 'gender', visible: false},
{ field: 'company' }
],
enableGridMenu: true,
enableSelectAll: true,
exporterMenuPdf: false,
exporterMenuCsv: false,
showHeader: true,
onRegisterApi: function(gridApi){
$scope.gridApi = gridApi;
},
/* SheetJS Service setup */
filename: "SheetJSAngular",
sheetname: "ng-SheetJS",
gridMenuCustomItems: [
{
title: 'Export all data as XLSX',
action: function() { SheetJSExportService.exportXLSX($scope.gridApi); },
order: 200
},
{
title: 'Export all data as XLSB',
action: function() { SheetJSExportService.exportXLSB($scope.gridApi); },
order: 201
}
]
};
$http.get('https://cdn.rawgit.com/angular-ui/ui-grid.info/gh-pages/data/100.json').success(function(data) { $scope.gridOptions.data = data; });
}]);
app.directive("importSheetJs", [SheetJSImportDirective]);

@ -1,64 +0,0 @@
<!DOCTYPE html>
<!-- xlsx.js (C) 2013-present SheetJS http://sheetjs.com -->
<!-- vim: set ts=2: -->
<html ng-app="app">
<head>
<title>SheetJS + AngularJS + ui-grid</title>
<!-- Angular -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular-touch.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular-animate.js"></script>
<!-- ui-grid -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-grid/4.11.0/ui-grid.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-grid/4.11.0/ui-grid.css"/>
<!-- SheetJS js-xlsx library -->
<script src="shim.js"></script>
<script src="xlsx.full.min.js"></script>
<!-- SheetJS Service -->
<script src="SheetJS-angular.js"></script>
<style>
.grid1 {
width: 500px;
height: 400px;
};
</style>
</head>
<body>
<pre>
<b><a href="http://sheetjs.com">SheetJS + AngularJS demo</a></b>
The core library can be used as-is in AngularJS 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:
- SheetJSExportService: a service for exporting data from a ui-grid
- SheetJSImportDirective: a directive providing a file input button for import
<a href="https://obamawhitehouse.archives.gov/sites/default/files/omb/budget/fy2014/assets/receipts.xls">Sample Spreadsheet</a>
</pre>
<div ng-controller="MainCtrl">
<input type="file" import-sheet-js="" opts="gridOptions" multiple="false" />
<div id="grid1" ui-grid="gridOptions" ui-grid-selection ui-grid-exporter class="grid"></div>
</div>
<script src="app.js"></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,75 +0,0 @@
<!DOCTYPE html>
<!-- xlsx.js (C) 2013-present SheetJS http://sheetjs.com -->
<!-- vim: set ts=2: -->
<html ng-app="sjs">
<head>
<title>SheetJS + AngularJS</title>
<!-- Angular -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.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="http://sheetjs.com">SheetJS + AngularJS demo</a></b>
The core library can be used as-is in AngularJS 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:
- $http request for XLSX file and scope update with data
- HTML table using ng-repeat
- XLSX table export using `XLSX.utils.table_to_book`
<a href="https://sheetjs.com/pres.xlsx">Sample Spreadsheet</a>
</pre>
<div ng-controller="sheetjs">
<table id="sjs-table">
<tr><th>Name</th><th>Index</th></tr>
<tr ng-repeat="row in data">
<td>{{row.Name}}</td>
<td>{{row.Index}}</td>
</tr>
</table>
<button id="exportbtn">Export Table</button>
</div>
<script>
var app = angular.module('sjs', []);
app.controller('sheetjs', function($scope, $http) {
$http({
method:'GET',
url:'https://sheetjs.com/pres.xlsx',
responseType:'arraybuffer'
}).then(function(data) {
var wb = XLSX.read(data.data, {type:"array"});
var d = XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]]);
$scope.data = d;
}, function(err) { console.log(err); });
});
exportbtn.addEventListener('click', function() {
var wb = XLSX.utils.table_to_book(document.getElementById('sjs-table'));
XLSX.writeFile(wb, "export.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 +0,0 @@
../../dist/xlsx.core.min.js

@ -1 +0,0 @@
../../dist/xlsx.full.min.js

@ -1,4 +0,0 @@
browserify.js
browserify.min.js
worker.js
worker.min.js

@ -1,2 +0,0 @@
xlsx.*.js
logo.png

@ -1,8 +0,0 @@
.PHONY: init
init:
cp ../../dist/xlsx.full.min.js .
if [ ! -e logo.png ]; then curl -O https://sheetjs.com/logo.png; fi
.PHONY: lint
lint:
eslint content.js popup.js table.js

@ -1,89 +1,6 @@
# Chrome and Chromium
This library is compatible with Chrome and Chromium extensions and should just
work out of the box. Specific API support is listed in the Chrome extensions
API documentation.
## Generating Downloads
The `writeFile` function works in a Chrome or Chromium extension:
```js
XLSX.writeFile(wb, "export.xlsx");
```
Under the hood, it uses the `chrome.downloads` API. `"downloads"` permission
should be set in `manifest.json`:
```js
"permissions": [
"downloads"
]
```
## Content Script Table Scraping
`table_to_book` and `table_to_sheet` can help build workbooks from DOM tables:
```js
var tables = document.getElementsByTagName("table");
var wb = XLSX.utils.book_new();
for(var i = 0; i < tables.length; ++i) {
var ws = XLSX.utils.table_to_sheet(tables[i]);
XLSX.utils.book_append_sheet(wb, ws, "Table" + i);
}
```
## Demo
The demo extension includes multiple features to demonstrate sample usage.
Production extensions should include proper error handling.
#### Table Exporter
The `content.js` content script converts a table in the DOM to workbook object
using the `table_to_book` utility function:
```js
// event page script trigger
chrome.tabs.sendMessage(tab.id);
// content script convert
var wb = XLSX.utils.table_to_book(elt);
// event page script callback
XLSX.writeFile(wb, "export.xlsx");
```
Since the workbook object is a plain JS object, the object is sent back to an
event page script which generates the file and attempts a download.
#### Bookmark Exporter
`chrome.bookmarks` API enables bookmark tree traversal. The "Export Bookmarks"
button in the extension pop-up recursively walks the bookmark tree, pushes the
bookmark URLs into a data array, and exports into a simple spreadsheet:
```js
/* walk the bookmark tree */
function recurse_bookmarks(data, tree) {
if(tree.url) data.push({Name: tree.title, Location: tree.url});
(tree.children||[]).forEach(function(child) { recurse_bookmarks(data, child); });
}
/* get bookmark data */
chrome.bookmarks.getTree(function(res) {
/* load into an array */
var data = [];
res.forEach(function(t) { recurse_bookmarks(data, t); });
/* create worksheet */
var ws = XLSX.utils.json_to_sheet(data, { header: ['Name', 'Location'] });
/* create workbook and export */
var wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, 'Bookmarks');
XLSX.writeFile(wb, "bookmarks.xlsx");
});
```
[The new demo](https://docs.sheetjs.com/docs/getting-started/demos/chromium)
includes more up-to-date details.
[![Analytics](https://ga-beacon.appspot.com/UA-36810333-1/SheetJS/js-xlsx?pixel)](https://github.com/SheetJS/js-xlsx)

@ -1,27 +0,0 @@
/* xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com */
/* eslint-env browser */
/* global XLSX, chrome */
var coords = [0,0];
document.addEventListener('mousedown', function(mouse) {
if(mouse && mouse.button == 2) coords = [mouse.clientX, mouse.clientY];
});
chrome.runtime.onMessage.addListener(function(msg, sender, cb) {
if(!msg || !msg['Sheet']) return;
if(msg.Sheet == "JS") {
var elt = document.elementFromPoint(coords[0], coords[1]);
while(elt != null) {
if(elt.tagName.toLowerCase() == "table") return cb(XLSX.utils.table_to_book(elt));
elt = elt.parentElement;
}
} else if(msg.Sheet == "J5") {
var tables = document.getElementsByTagName("table");
var wb = XLSX.utils.book_new();
for(var i = 0; i < tables.length; ++i) {
var ws = XLSX.utils.table_to_sheet(tables[i]);
XLSX.utils.book_append_sheet(wb, ws, "Table" + i);
}
return cb(wb);
}
cb(coords);
});

@ -1,30 +0,0 @@
{
"manifest_version": 2,
"name": "SheetJS Demo",
"description": "Sample Extension using SheetJS to interact with Chrome",
"version": "0.0.1",
"browser_action": {
"default_popup": "popup.html",
"default_icon": "logo.png"
},
"background": {
"scripts": ["xlsx.full.min.js", "table.js"],
"persistent": false
},
"content_scripts": [{
"matches": ["<all_urls>"],
"js": ["content.js", "xlsx.full.min.js"],
"run_at": "document_end"
}],
"icons": {
"16": "logo.png"
},
"permissions": [
"activeTab",
"<all_urls>",
"bookmarks",
"contextMenus",
"downloads",
"tabs"
]
}

@ -1,18 +0,0 @@
<!DOCTYPE html>
<!-- (C) 2013-present SheetJS http://sheetjs.com -->
<!-- vim: set ts=2: -->
<html>
<head>
<title>SheetJS Chrome Extension Export Test</title>
<meta charset="utf-8" />
</head>
<body>
<!-- SheetJS js-xlsx library -->
<script type="text/javascript" src="xlsx.full.min.js"></script>
<button type="button" id="sjsdownload">Export Bookmarks</button>
<a><div id="sjsversion">Version</div></a>
<script type="text/javascript" src="popup.js"></script>
</body>
</html>

@ -1,31 +0,0 @@
/* xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com */
/* eslint-env browser */
/* global XLSX, chrome */
document.getElementById('sjsversion').innerText = "SheetJS " + XLSX.version;
document.getElementById('sjsversion').addEventListener('click', function() {
chrome.tabs.create({url: "https://sheetjs.com/"}); return false;
});
/* recursively walk the bookmark tree */
function recurse_bookmarks(data, tree, path) {
if(tree.url) data.push({Name: tree.title, Location: tree.url, Path:path});
var T = path ? (path + "::" + tree.title) : tree.title;
(tree.children||[]).forEach(function(C) { recurse_bookmarks(data, C, T); });
}
/* export bookmark data */
document.getElementById('sjsdownload').addEventListener('click', function() {
chrome.bookmarks.getTree(function(res) {
var data = [];
res.forEach(function(t) { recurse_bookmarks(data, t, ""); });
/* create worksheet */
var ws = XLSX.utils.json_to_sheet(data, { header: ['Name', 'Location', 'Path'] });
/* create workbook and export */
var wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, 'Bookmarks');
XLSX.writeFile(wb, "bookmarks.xlsx");
});
});

@ -1,43 +0,0 @@
/* xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com */
/* eslint-env browser */
/* global XLSX, chrome */
chrome.runtime.onInstalled.addListener(function() {
chrome.contextMenus.create({
type: "normal",
id: "sjsexport",
title: "Export Table to XLSX",
contexts: ["page", "selection"]
});
chrome.contextMenus.create({
type: "normal",
id: "sj5export",
title: "Export All Tables in Page",
contexts: ["page", "selection"]
});
chrome.contextMenus.onClicked.addListener(function(info/*, tab*/) {
var mode = "";
switch(info.menuItemId) {
case 'sjsexport': mode = "JS"; break;
case 'sj5export': mode = "J5"; break;
default: return;
}
chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
chrome.tabs.sendMessage(tabs[0].id, {Sheet:mode}, sjsexport_cb);
});
});
chrome.contextMenus.create({
id: "sjsabout",
title: "About",
contexts: ["browser_action"]
});
chrome.contextMenus.onClicked.addListener(function(info/*, tab*/) {
if(info.menuItemId !== "sjsabout") return;
chrome.tabs.create({url: "https://sheetjs.com/"});
});
});
function sjsexport_cb(wb) {
if(!wb || !wb.SheetNames || !wb.Sheets) { return alert("Error in exporting table"); }
XLSX.writeFile(wb, "export.xlsx");
}

@ -1,7 +0,0 @@
{
"env": { "shared-node-browser":true },
"parserOptions": {
"ecmaVersion": 8
},
"plugins": [ "html", "json" ]
}

@ -1 +0,0 @@
*.db

@ -1,89 +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 Firebase Dump Demo</title>
<style>
a { text-decoration: none }
</style>
</head>
<body>
<pre>
<h3><a href="//sheetjs.com/">SheetJS</a> Firebase Dump Demo</h3>
<b>Example Code</b>
/* ... connect to firebase */
const database = firebase.database();
/* import workbook */
await database.ref('foo').set(workbook);
/* change cells */
database.ref('foo').update({
"Sheets/Sheet1/A1": {"t": "s", "v": "J"},
"Sheets/Sheet1/A2": {"t": "n", "v": 5},
});
/* export snapshot */
const val = await database.ref('foo').once('value').val();
XLSX.writeFile(wb, "firebase.xlsx");
</pre>
<script src="xlsx.full.min.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.12.0/firebase.js"></script>
<script>
const Firebase = firebase;
const config = {
credential: {
getAccessToken: () => ({
expires_in: 0,
access_token: '',
}),
},
databaseURL: 'ws://localhost:5555'
};
/* make new workbook object from CSV */
const wb = XLSX.read('a,b,c\n1,2,3', {type:"binary"});
let P = Promise.resolve("sheetjs");
/* Connect to Firebase server and initialize collection */
P = P.then(async () => {
Firebase.initializeApp(config);
const database = Firebase.database();
await database.ref('foo').set(null);
return [database];
});
/* Insert entire workbook object into `foo` ref */
P = P.then(async ([database]) => {
await database.ref('foo').set(wb);
return [database];
});
/* Change cell A1 of Sheet1 to "J" and change A2 to 5 */
P = P.then(async ([database]) => {
database.ref('foo').update({
"Sheets/Sheet1/A1": {"t": "s", "v": "J"},
"Sheets/Sheet1/A2": {"t": "n", "v": 5},
});
return [database];
});
/* Write to file */
P = P.then(async ([database]) => {
const val = await database.ref('foo').once('value');
const wb = await val.val();
XLSX.writeFile(wb, "firebase.xlsx");
console.log(csv);
return [database];
});
/* Close connection */
P = P.then(async ([database]) => { database.app.delete(); });
</script>
</body>

@ -1,58 +0,0 @@
/* xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com */
/* eslint-env node */
const XLSX = require('xlsx');
const assert = require('assert');
const Firebase = require('firebase-admin');
const config = {
credential: {
getAccessToken: () => ({
expires_in: 0,
access_token: '',
}),
},
databaseURL: 'ws://localhost:5555'
};
/* make new workbook object from CSV */
const wb = XLSX.read('a,b,c\n1,2,3', {type:"binary", raw:true});
let P = Promise.resolve("sheetjs");
/* Connect to Firebase server and initialize collection */
P = P.then(async () => {
Firebase.initializeApp(config);
const database = Firebase.database();
await database.ref('foo').set(null);
return [database];
});
/* Insert entire workbook object into `foo` ref */
P = P.then(async ([database]) => {
await database.ref('foo').set(wb);
return [database];
});
/* Change cell A1 of Sheet1 to "J" and change A2 to 5 */
P = P.then(async ([database]) => {
database.ref('foo').update({
"Sheets/Sheet1/A1": {"t": "s", "v": "J"},
"Sheets/Sheet1/A2": {"t": "n", "v": 5},
});
return [database];
});
/* Write to file */
P = P.then(async ([database]) => {
const val = await database.ref('foo').once('value');
const wb = await val.val();
XLSX.writeFile(wb, "firebase.xlsx");
const ws = XLSX.readFile("firebase.xlsx").Sheets.Sheet1;
const csv = XLSX.utils.sheet_to_csv(ws);
assert.equal(csv, "J,b,c\n5,2,3\n");
console.log(csv);
return [database];
});
/* Close connection */
P = P.then(async ([database]) => { database.app.delete(); });

@ -1,73 +0,0 @@
/* xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com */
/* eslint-env node */
/* global Promise */
const XLSX = require('xlsx');
const assert = require('assert');
const SheetJSKnex = require("./SheetJSKnex");
const Knex = require('knex');
/* Connection to both databases are passed around */
let P = Promise.resolve([
Knex({ client: 'sqlite3', connection: { filename: './knex1.db' } }),
Knex({ client: 'sqlite3', connection: { filename: './knex2.db' } })
]);
/* Sample data table */
P = P.then(async (_) => {
const [knex] = _;
await knex.schema.dropTableIfExists('pres');
await knex.schema.createTable('pres', (table) => {
table.string('name');
table.integer('idx');
});
await knex.insert([
{ name: "Barack Obama", idx: 44 },
{ name: "Donald Trump", idx: 45 }
]).into('pres');
await knex.schema.dropTableIfExists('fmts');
await knex.schema.createTable('fmts', (table) => {
table.string('ext');
table.string('ctr');
table.integer('multi');
});
await knex.insert([
{ ext: 'XLSB', ctr: 'ZIP', multi: 1 },
{ ext: 'XLS', ctr: 'CFB', multi: 1 },
{ ext: 'XLML', ctr: '', multi: 1 },
{ ext: 'CSV', ctr: 'ZIP', multi: 0 },
]).into('fmts');
return _;
});
/* Export database to XLSX */
P = P.then(async (_) => {
const [knex] = _;
const wb = XLSX.utils.book_new();
await SheetJSKnex.book_append_knex(wb, knex, "pres");
await SheetJSKnex.book_append_knex(wb, knex, "fmts");
XLSX.writeFile(wb, "knex.xlsx");
return _;
});
/* Import XLSX to database */
P = P.then(async (_) => {
const [, knex] = _;
const wb = XLSX.readFile("knex.xlsx");
await SheetJSKnex.wb_to_knex(wb, knex);
return _;
});
/* Compare databases */
P = P.then(async (_) => {
const [k1, k2] = _;
const P1 = await k1.select("*").from('pres');
const P2 = await k2.select("*").from('pres');
const F1 = await k1.select("*").from('fmts');
const F2 = await k2.select("*").from('fmts');
assert.deepEqual(P1, P2);
assert.deepEqual(F1, F2);
});
P.then(async () => { process.exit(); });

@ -1,59 +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>
a { text-decoration: none }
</style>
</head>
<body>
<pre>
<b><a href="http://sheetjs.com">SheetJS LocalStorage Demo</a></b>
<pre id="data_">
Original Data:
</pre>
<pre id="out">
Output:
</pre>
<script src="xlsx.full.min.js"></script>
<script src="ObjUtils.js"></script>
<script src="https://unpkg.com/localforage/dist/localforage.min.js"></script>
<script src="SheetJSForage.js"></script>
<script>
/* eslint-env browser */
/*global XLSX, localforage */
var data = {
"title": "SheetDB",
"metadata": {
"author": "SheetJS",
"code": 7262
},
"data": [
{ "Name": "Barack Obama", "Index": 44 },
{ "Name": "Donald Trump", "Index": 45 },
]
};
document.getElementById("data_").innerText += JSON.stringify(data, 2, 2);
localforage.setDriver(localforage.INDEXEDDB);
(async function() {
await localforage.clear();
await localforage.load(data);
var wb = await localforage.dump();
console.log(wb);
var OUT = document.getElementById("out");
wb.SheetNames.forEach(function(n, i) {
OUT.innerText += "Sheet " + i + " (" + n + ")\n";
OUT.innerText += XLSX.utils.sheet_to_csv(wb.Sheets[n]);
OUT.innerText += "\n";
});
})();
</script>
</body>
</html>

@ -1,57 +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>
a { text-decoration: none }
</style>
</head>
<body>
<pre>
<b><a href="http://sheetjs.com">SheetJS LocalStorage Demo</a></b>
<pre id="data_">
Original Data:
</pre>
<pre id="out">
Output:
</pre>
<script src="xlsx.full.min.js"></script>
<script src="ObjUtils.js"></script>
<script src="SheetJSStorage.js"></script>
<script>
/* eslint-env browser */
/*global XLSX */
var data = {
"title": "SheetDB",
"metadata": {
"author": "SheetJS",
"code": 7262
},
"data": [
{ "Name": "Barack Obama", "Index": 44 },
{ "Name": "Donald Trump", "Index": 45 },
]
};
document.getElementById("data_").innerText += JSON.stringify(data, 2, 2);
(function() {
localStorage.clear();
localStorage.load(data);
var wb = localStorage.dump();
console.log(wb);
var OUT = document.getElementById("out");
wb.SheetNames.forEach(function(n, i) {
OUT.innerText += "Sheet " + i + " (" + n + ")\n";
OUT.innerText += XLSX.utils.sheet_to_csv(wb.Sheets[n]);
OUT.innerText += "\n";
});
})();
</script>
</body>
</html>

@ -1,23 +0,0 @@
/* xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com */
/* eslint-env node */
var low = require('lowdb');
var SheetJSAdapter = require('./SheetJSLowDB');
var adapter = new SheetJSAdapter();
var db = low(adapter);
db.defaults({ posts: [], user: {}, count: 0 }).write();
db.get('posts').push({ id: 1, title: 'lowdb is awesome'}).write();
db.set('user.name', 'typicode').write();
db.update('count', function(n) { return n + 1; }).write();
adapter.dumpFile('ldb1.xlsx');
var adapter2 = new SheetJSAdapter();
adapter2.loadFile('ldb1.xlsx');
var db2 = low(adapter2);
db2.get('posts').push({ id: 2, title: 'mongodb is not'}).write();
db2.set('user.name', 'sheetjs').write();
db2.update('count', function(n) { return n + 1; }).write();
adapter2.dumpFile('ldb2.xlsx');

@ -1,16 +0,0 @@
.PHONY: init
init:
rm -f node_modules/xlsx
mkdir -p node_modules
cd node_modules; ln -s ../../../ xlsx; cd -
rm -f xlsx.full.min.js
ln -s ../../dist/xlsx.full.min.js
FILES=$(filter-out xlsx.full.min.js,$(wildcard *.js)) $(wildcard *.html)
.PHONY: lint
lint: $(FILES)
eslint $(FILES)
.PHONY: clean
clean:
rm -f *.db *.xlsx *.csv

@ -1,63 +0,0 @@
/* xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com */
/* eslint-env node */
/* global Promise */
const XLSX = require('xlsx');
const SheetJSMongo = require("./SheetJSMongo");
const MongoClient = require('mongodb').MongoClient;
const url = 'mongodb://localhost:27017/sheetjs';
const db_name = 'sheetjs';
let P = Promise.resolve("sheetjs");
/* Connect to mongodb server */
P = P.then(async () => {
const client = await MongoClient.connect(url,{ useUnifiedTopology: true });
return [client];
});
/* Sample data table */
P = P.then(async ([client]) => {
const db = client.db(db_name);
try { await db.collection('pres').drop(); } catch(e) {}
const pres = db.collection('pres');
await pres.insertMany([
{ name: "Barack Obama", idx: 44 },
{ name: "Donald Trump", idx: 45 }
], {ordered: true});
try { await db.collection('fmts').drop(); } catch(e) {}
const fmts = db.collection('fmts');
await fmts.insertMany([
{ ext: 'XLSB', ctr: 'ZIP', multi: 1 },
{ ext: 'XLS', ctr: 'CFB', multi: 1 },
{ ext: 'XLML', multi: 1 },
{ ext: 'CSV', ctr: 'ZIP', multi: 0 },
], {ordered: true});
return [client, pres, fmts];
});
/* Export database to XLSX */
P = P.then(async ([client, pres, fmts]) => {
const wb = XLSX.utils.book_new();
await SheetJSMongo.book_append_mongo(wb, pres, "pres");
await SheetJSMongo.book_append_mongo(wb, fmts, "fmts");
XLSX.writeFile(wb, "mongocrud.xlsx");
return [client, pres, fmts];
});
/* Read the new file and dump all of the data */
P = P.then(([client]) => {
const wb = XLSX.readFile('mongocrud.xlsx');
wb.SheetNames.forEach((n,i) => {
console.log(`Sheet #${i+1}: ${n}`);
const ws = wb.Sheets[n];
console.log(XLSX.utils.sheet_to_csv(ws));
});
return [client];
});
/* Close connection */
P.then(async ([client]) => { client.close(); });

@ -1,54 +0,0 @@
/* xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com */
/* eslint-env node */
/* global Promise */
const XLSX = require('xlsx');
const assert = require('assert');
const MongoClient = require('mongodb').MongoClient;
const url = 'mongodb://localhost:27017/sheetjs';
const db_name = 'sheetjs';
/* make new workbook object from CSV */
const wb = XLSX.read('a,b,c\n1,2,3', {type:"binary", raw:true});
let P = Promise.resolve("sheetjs");
/* Connect to mongodb server and initialize collection */
P = P.then(async () => {
const client = await MongoClient.connect(url,{ useUnifiedTopology: true });
const db = client.db(db_name);
try { await db.collection('wb').drop(); } catch(e) {}
const coll = db.collection('wb');
return [client, coll];
});
/* Insert entire workbook object as a document */
P = P.then(async ([client, coll]) => {
const res = await coll.insertOne(wb);
assert.equal(res.insertedCount, 1);
return [client, coll];
});
/* Change cell A1 of Sheet1 to "J" and change A2 to 5 */
P = P.then(async ([client, coll]) => {
const res = await coll.updateOne({}, { $set: {
"Sheets.Sheet1.A1": {"t": "s", "v": "J"},
"Sheets.Sheet1.A2": {"t": "n", "v": 5},
}});
assert.equal(res.matchedCount, 1);
assert.equal(res.modifiedCount, 1);
return [client, coll];
});
/* Write to file */
P = P.then(async ([client, coll]) => {
const res = await coll.find({}).toArray();
const wb = res[0];
XLSX.writeFile(wb, "mongo.xlsx");
const ws = XLSX.readFile("mongo.xlsx").Sheets.Sheet1;
console.log(XLSX.utils.sheet_to_csv(ws));
return [client, coll];
});
/* Close connection */
P.then(async ([client]) => { client.close(); });

@ -1,70 +0,0 @@
/* xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com */
/* eslint-env node */
var XLSX = require('xlsx');
var assert = require('assert');
var SheetJSSQL = require('./SheetJSSQL');
var mysql = require('mysql2/promise');
/* Connection options (requires two databases sheetjs and sheetj5) */
var opts = {
host : 'localhost',
user : 'SheetJS',
password : 'SheetJS',
};
/* Sample data table */
var init = [
"DROP TABLE IF EXISTS pres",
"CREATE TABLE pres (name TEXT, idx TINYINT)",
"INSERT INTO pres VALUES ('Barack Obama', 44)",
"INSERT INTO pres VALUES ('Donald Trump', 45)",
"DROP TABLE IF EXISTS fmts",
"CREATE TABLE fmts (ext TEXT, ctr TEXT, multi TINYINT)",
"INSERT INTO fmts VALUES ('XLSB', 'ZIP', 1)",
"INSERT INTO fmts VALUES ('XLS', 'CFB', 1)",
"INSERT INTO fmts VALUES ('XLML', '', 1)",
"INSERT INTO fmts VALUES ('CSV', '', 0)",
];
(async () => {
const conn1 = await mysql.createConnection(Object.assign({}, opts, {database: "sheetjs"}));
for(var i = 0; i < init.length; ++i) await conn1.query(init[i]);
/* Export table to XLSX */
var wb = XLSX.utils.book_new();
async function book_append_table(wb, name) {
var r_f = await conn1.query('SELECT * FROM ' + name);
var r = r_f[0];
var ws = XLSX.utils.json_to_sheet(r);
XLSX.utils.book_append_sheet(wb, ws, name);
}
await book_append_table(wb, "pres");
await book_append_table(wb, "fmts");
XLSX.writeFile(wb, "mysql.xlsx");
/* Capture first database info and close */
var P1 = (await conn1.query("SELECT * FROM pres"))[0];
var F1 = (await conn1.query("SELECT * FROM fmts"))[0];
await conn1.close();
/* Import XLSX to table */
const conn2 = await mysql.createConnection(Object.assign({}, opts, {database: "sheetj5"}));
var wb2 = XLSX.readFile("mysql.xlsx");
var queries = SheetJSSQL.book_to_sql(wb2, "MYSQL");
for(i = 0; i < queries.length; ++i) await conn2.query(queries[i]);
/* Capture first database info and close */
var P2 = (await conn2.query("SELECT * FROM pres"))[0];
var F2 = (await conn2.query("SELECT * FROM fmts"))[0];
await conn2.close();
/* Compare results */
assert.deepEqual(P1, P2);
assert.deepEqual(F1, F2);
/* Display results */
console.log(P2);
console.log(F2);
})();

@ -1,59 +0,0 @@
/* xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com */
/*global XLSX, module, require */
var ObjUtils = (function() {
var X;
if(typeof XLSX !== "undefined") X = XLSX;
else if(typeof require !== 'undefined') X = require('xlsx');
else throw new Error("Could not find XLSX");
function walk(obj, key, arr) {
if(Array.isArray(obj)) return;
if(typeof obj != "object" || obj instanceof Date) { arr.push({path:key, value:obj}); return; }
Object.keys(obj).forEach(function(k) {
walk(obj[k], key ? key + "." + k : k, arr);
});
}
function object_to_workbook(obj) {
var wb = X.utils.book_new();
var base = []; walk(obj, "", base);
var ws = X.utils.json_to_sheet(base, {header:["path", "value"]});
X.utils.book_append_sheet(wb, ws, "_keys");
Object.keys(obj).forEach(function(k) {
if(!Array.isArray(obj[k])) return;
X.utils.book_append_sheet(wb, X.utils.json_to_sheet(obj[k]), k);
});
return wb;
}
function deepset(obj, path, value) {
if(path.indexOf(".") == -1) return obj[path] = value;
var parts = path.split(".");
if(!obj[parts[0]]) obj[parts[0]] = {};
return deepset(obj[parts[0]], parts.slice(1).join("."