inputtype

This commit is contained in:
SheetJS 2022-11-13 15:45:13 -05:00
parent a55b6f4b04
commit 9239192893
7 changed files with 37 additions and 42 deletions

@ -92,7 +92,8 @@ The official Deno registry is out of date. This is a registry bug.
:::
Applications using the Deno registry can migrate by changing the URLs.
Applications using the Deno registry can migrate by changing the URLs. After
migrating, it is easy to update by changing the version number.
<Tabs>
<TabItem value="v" label="URL with version">

@ -5,8 +5,7 @@ title: Google Sheets
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
This demo uses [`node-google-spreadsheet`](https://theoephraim.github.io/node-google-spreadsheet)
to interact with Google Sheets v4 API.
This demo uses `node-google-spreadsheet` to interact with Google Sheets v4 API.
:::caution
@ -57,13 +56,7 @@ not natively support the XLSB format. SheetJS fills the gap.
<details><summary><b>How to run locally</b> (click to show)</summary>
0) Follow the [Authentication and Service Account](https://theoephraim.github.io/node-google-spreadsheet/#/getting-started/authentication)
instructions. At the end, you should have
- Created a project and enabled the Sheets API
- Created a service account with a JSON key
Move the generated JSON key to `key.json` in your project folder.
0) Follow the [Initial Configuration](#initial-configuration).
1) Create a new Google Sheet and share with the generated service account. It
should be granted the "Editor" role
@ -195,13 +188,7 @@ The goal is to refresh a Google Sheet based on a local file.
<details><summary><b>How to run locally</b> (click to show)</summary>
0) Follow the [Authentication and Service Account](https://theoephraim.github.io/node-google-spreadsheet/#/getting-started/authentication)
instructions. At the end, you should have
- Created a project and enabled the Sheets API
- Created a service account with a JSON key
Move the generated JSON key to `key.json` in your project folder.
0) Follow the [Initial Configuration](#initial-configuration).
1) Create a new Google Sheet and share with the generated service account. It
should be granted the "Editor" role

@ -647,7 +647,7 @@ the standalone browser scripts.
2) Save the following script to `SheetJSQuick.js`:
```js title="SheetJSQuick.js
```js title="SheetJSQuick.js"
/* sheetjs (C) 2013-present SheetJS -- https://sheetjs.com */
/* load XLSX */
import * as std from "std";
@ -664,10 +664,10 @@ rh.read(ab, 0, sz);
rh.close();
/* parse file */
var wb = XLSX.read(ab, {type: 'array'});
var wb = XLSX.read(ab);
/* write array */
var out = XLSX.write(wb, {type: 'array'});
/* write XLSX */
var out = XLSX.write(wb, {bookType: "xlsx", type: "array"});
/* write contents to file */
var wh = std.open("SheetJSQuick.xlsx", "wb");
@ -861,6 +861,7 @@ The `load` function in `jjs` can load the minified source directly:
```js
var global = (function(){ return this; }).call(null);
load('shim.min.js');
load('xlsx.full.min.js');
```
@ -887,6 +888,7 @@ array and calls `XLSX.read` with type `"array"`.
/* load module */
var global = (function(){ return this; }).call(null);
load('shim.min.js');
load('xlsx.full.min.js');
/* helper to convert byte array to plain JS array */
@ -905,7 +907,7 @@ function process_file(path) {
var u8a = b2a(bytes);
/* read data */
var wb = XLSX.read(u8a, {type:"array"});
var wb = XLSX.read(u8a);
/* get first worksheet as an array of arrays */
var ws = wb.Sheets[wb.SheetNames[0]];

@ -100,7 +100,7 @@ class ParseResource extends Drash.Resource {
const file = request.bodyParam<Drash.Types.BodyFile>("upload");
if (!file) throw new Error("File is required!");
// highlight-next-line
var wb = read(file.content, {type: "buffer"});
var wb = read(file.content);
return response.html( utils.sheet_to_html(wb.Sheets[wb.SheetNames[0]]));
}
}
@ -156,7 +156,7 @@ class ParseResource extends Drash.Resource {
public POST(request: Drash.Request, response: Drash.Response) {
const file = request.bodyParam<Drash.Types.BodyFile>("file");
if (!file) throw new Error("File is required!");
var wb = read(file.content, {type: "buffer"});
var wb = read(file.content);
return response.html( utils.sheet_to_html(wb.Sheets[wb.SheetNames[0]]));
}

@ -13,9 +13,9 @@ SheetJS libraries strive to maintain broad browser and JS engine compatibility.
## Integration
The ["Standalone Browser Scripts"](/docs/getting-started/installation/standalone) section has
instructions for obtaining or referencing the standalone scripts. These are
designed to be referenced with `<script>` tags.
["Standalone Browser Scripts"](/docs/getting-started/installation/standalone)
section has instructions for obtaining or referencing the standalone scripts.
These are designed to be referenced with `<script>` tags.
## Internet Explorer
@ -27,7 +27,7 @@ The SheetJS testing grid still includes IE and should work.
:::
The modern upload and download strategies are not available in older versions of
IE, but there are approaches using older technologies like ActiveX and Flash.
IE, but there are approaches using ActiveX or Flash.
<details><summary><b>Complete Example</b> (click to show)</summary>
@ -58,7 +58,7 @@ npx -y http-server .
<details><summary><b>Other Live Demos</b> (click to show)</summary>
:::warning
:::caution
The hosted solutions may not work in older versions of Windows. For testing,
demo pages should be downloaded and hosted using a simple HTTP server.
@ -174,9 +174,8 @@ included in the page and the relevant features are enabled on the target system.
### AngularJS
[AngularJS](https://en.wikipedia.org/wiki/AngularJS) was a front-end MVC
framework that was abandoned by Google in 2022. It should not be confused with
"Angular" the modern framework.
AngularJS was a front-end MVC framework that was discontinued by Google in 2022.
It should not be confused with the modern framework "Angular".
The [Live demo](pathname:///angularjs/index.html) shows a simple table that is
updated with file data and exported to spreadsheets.
@ -391,8 +390,7 @@ require(["xlsx"], function(_XLSX) {
### KnockoutJS
[KnockoutJS](https://en.wikipedia.org/wiki/Knockout_(web_framework)) was a
popular MVVM framework.
KnockoutJS was a popular MVVM framework.
The [Live demo](pathname:///knockout/knockout.html) shows a view model that is
updated with file data and exported to spreadsheets.

@ -325,8 +325,8 @@ The [`server` demo](/docs/demos/server) has more advanced examples.
</TabItem>
<TabItem value="deno" label="Deno">
[Drash](https://drash.land/drash/) is a HTTP server framework for Deno. In a
`POST` request handler, the body parser can pull file data into a `Uint8Array`:
Drash is a HTTP server framework for Deno. In a `POST` request handler, the
body parser can pull file data into a `Uint8Array`:
<pre><code parentName="pre" {...{"className": "language-ts"}}>{`\
// @deno-types="https://cdn.sheetjs.com/xlsx-${current}/package/types/index.d.ts"
@ -345,7 +345,7 @@ class SheetResource extends Drash.Resource {
const file = request.bodyParam<Drash.Types.BodyFile>("file");
if (!file) throw new Error("File is required!");
// highlight-next-line
var wb = XLSX.read(file.content, {type: "buffer"});
var wb = XLSX.read(file.content);
var html = XLSX.utils.sheet_to_html(wb.Sheets[wb.SheetNames[0]]);
return response.html(html);
}
@ -583,7 +583,7 @@ and process the whole thing at the end:
```js
// XLSX is a global from the standalone script
async function process_RS(stream) {
async function buffer_RS(stream) {
/* collect data */
const buffers = [];
const reader = stream.getReader();
@ -605,9 +605,9 @@ async function process_RS(stream) {
return out;
}
const data = await process_RS(stream);
const data = await buffer_RS(stream);
/* data is Uint8Array */
const workbook = XLSX.read(data, {type: 'array'});
const workbook = XLSX.read(data);
```
</TabItem>
@ -617,7 +617,6 @@ When dealing with Readable Streams, the easiest approach is to buffer the stream
and process the whole thing at the end:
```js
var fs = require("fs");
var XLSX = require("xlsx");
function process_RS(stream, cb) {
@ -625,7 +624,7 @@ function process_RS(stream, cb) {
stream.on("data", function(data) { buffers.push(data); });
stream.on("end", function() {
var buffer = Buffer.concat(buffers);
var workbook = XLSX.read(buffer, {type:"buffer"});
var workbook = XLSX.read(buffer);
/* DO SOMETHING WITH workbook IN THE CALLBACK */
cb(workbook);

@ -87,6 +87,14 @@ tells the library how to parse the data argument:
| `"array"` | array: array of 8-bit unsigned int (byte `n` is `data[n]`) |
| `"file"` | string: path of file that will be read (nodejs only) |
Some common types are automatically deduced from the data input type, including
NodeJS `Buffer` objects, `Uint8Array` and `ArrayBuffer` objects, and arrays of
numbers.
When a JS `string` is passed with no `type`, the library assumes the data is a
Base64 string. `FileReader#readAsBinaryString` or ASCII data requires `"binary"`
type. DOM strings including `FileReader#readAsText` should use type `"string"`.
### Guessing File Type
<details>