forked from sheetjs/docs.sheetjs.com
content-type
This commit is contained in:
parent
155b88ff3c
commit
fbf32ffb0a
2
_headers
2
_headers
@ -1,3 +1,3 @@
|
||||
/*.ts
|
||||
Content-Type: text/javascript
|
||||
Content-Type: application/typescript
|
||||
|
||||
|
@ -16,10 +16,27 @@ XLS (both '97-2004 and '95), and SpreadsheetML 2003.
|
||||
|
||||
Not all Clipboard APIs offer access to all clipboard types.
|
||||
|
||||
:::note
|
||||
|
||||
Each browser demo was tested in the following environments:
|
||||
|
||||
| Browser | Date |
|
||||
|:------------|:-----------|
|
||||
| Chrome 116 | 2023-09-01 |
|
||||
| Safari 16.6 | 2023-09-01 |
|
||||
| Brave 1.57 | 2023-09-01 |
|
||||
|
||||
:::
|
||||
|
||||
## Browser Reading (paste)
|
||||
|
||||
Clipboard data can be read from a `paste` event, accessible from the event
|
||||
`clipboardData` property:
|
||||
Clipboard data can be read from a `paste` event.
|
||||
|
||||
The event `clipboardData` property has a `getData` method which returns a string
|
||||
compatible with the `"string"` type in the SheetJS `read` method[^1].
|
||||
|
||||
The following example reads from the HTML clipboard and generates a XLSX file
|
||||
using the SheetJS `writeFile` method[^2]:
|
||||
|
||||
```js
|
||||
document.onpaste = function(e) {
|
||||
@ -31,7 +48,7 @@ document.onpaste = function(e) {
|
||||
};
|
||||
```
|
||||
|
||||
`getData` accepts one argument: the desired MIME type. Chrome 103 supports:
|
||||
`getData` accepts one argument: the desired MIME type. Tested browsers support:
|
||||
|
||||
| MIME type | Data format |
|
||||
|:-------------|:---------------------------|
|
||||
@ -39,8 +56,6 @@ document.onpaste = function(e) {
|
||||
| `text/html` | HTML |
|
||||
| `text/rtf` | RTF (rich text format) |
|
||||
|
||||
`getData` returns a string compatible with the `string` type for `XLSX.read`.
|
||||
|
||||
### Live Demo
|
||||
|
||||
Open a file in Excel, copy some cells, then come back to this window. Click on
|
||||
@ -78,10 +93,10 @@ function ClipboardRead() {
|
||||
|
||||
Modern browsers support reading files that users have copied into the clipboard.
|
||||
|
||||
:::caution
|
||||
:::caution pass
|
||||
|
||||
Excel does not copy data into files! Use your system file browser to select and
|
||||
copy spreadsheets into the clipboard.
|
||||
Due to browser API limitations, the system file browser should be used to select
|
||||
and copy spreadsheets into the clipboard.
|
||||
|
||||
:::
|
||||
|
||||
@ -121,11 +136,15 @@ function ClipboardReadFiles() {
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
## Browser Writing (copy)
|
||||
|
||||
Clipboard data can be written from a `copy` event, accessible from the event
|
||||
`clipboardData` property:
|
||||
Clipboard data can be written from a `copy` event.
|
||||
|
||||
The event `clipboardData` property has a `setData` method which accepts a string
|
||||
that can be generated using `type: "string"` in the SheetJS `write` method[^3].
|
||||
|
||||
The following example generates a HTML string from the first sheet of a workbook
|
||||
object and loads the string into the HTML clipboard:
|
||||
|
||||
```js
|
||||
document.oncopy = function(e) {
|
||||
@ -139,12 +158,15 @@ document.oncopy = function(e) {
|
||||
};
|
||||
```
|
||||
|
||||
`setData` accepts two arguments: MIME type and new data. Chrome 103 supports:
|
||||
`setData` accepts two arguments: MIME type and new data.
|
||||
|
||||
| MIME type | Data format |
|
||||
|:-------------|:---------------------------|
|
||||
| `text/plain` | TSV (tab separated values) |
|
||||
| `text/html` | HTML |
|
||||
The following table lists the supported MIME types and the `bookType`[^4] value
|
||||
that must be passed to the SheetJS `write` method:
|
||||
|
||||
| MIME type | Data format | `bookType` |
|
||||
|:-------------|:---------------------------|:-----------|
|
||||
| `text/plain` | TSV (tab separated values) | `txt` |
|
||||
| `text/html` | HTML | `html` |
|
||||
|
||||
Browsers do not currently support assigning to the `text/rtf` clipboard type.
|
||||
|
||||
@ -160,7 +182,7 @@ This demo creates a simple workbook from the following HTML table:
|
||||
|
||||
Create a new file in Excel then come back to this window. Select the text
|
||||
below and copy (Control+C for Windows, Command+C for Mac). Go back to the
|
||||
excel
|
||||
Excel file, select cell A1, and paste.
|
||||
|
||||
```jsx live
|
||||
function ClipboardWrite() {
|
||||
@ -190,9 +212,9 @@ There are special methods for specific clipboard types:
|
||||
|
||||
| File Type | Read Clipboard Data | Write Clipboard Data |
|
||||
|:----------|:---------------------|:----------------------|
|
||||
| RTF | `clipboard.readRTF` | `clipboard.writeRTF` |
|
||||
| TSV | `clipboard.readText` | `clipboard.writeText` |
|
||||
| HTML | `clipboard.readHTML` | `clipboard.writeHTML` |
|
||||
| RTF | `clipboard.readRTF` | `clipboard.writeRTF` |
|
||||
|
||||
Each method operates on JS strings.
|
||||
|
||||
@ -211,23 +233,7 @@ function copy_first_sheet_to_clipboard(workbook) {
|
||||
}
|
||||
```
|
||||
|
||||
:::caution Experimental Buffer Clipboard Support
|
||||
|
||||
Electron additionally supports binary operations using `Buffer` objects. This
|
||||
support is considered "experimental" and is not guaranteed to work on any
|
||||
platform. Issues should be raised with the Electron project
|
||||
|
||||
On the `MacOS` platform, some versions of Excel store a packaged file with key
|
||||
`dyn.ah62d4qmxhk4d425try1g44pdsm11g55gsu1en5pcqzwc4y5tsz3gg3k`. The package is
|
||||
a simple CFB file that can be parsed:
|
||||
|
||||
```js
|
||||
const { clipboard } = require('electron');
|
||||
const XLSX = require("xlsx");
|
||||
const buf = clipboard.readBuffer('dyn.ah62d4qmxhk4d425try1g44pdsm11g55gsu1en5pcqzwc4y5tsz3gg3k');
|
||||
const cfb = XLSX.CFB.read(buf, {type: "buffer"});
|
||||
const pkg = XLSX.CFB.find(cfb, "Package").content;
|
||||
const wb = XLSX.read(pkg);
|
||||
```
|
||||
|
||||
:::
|
||||
[^1]: See [`read` in "Reading Files"](/docs/api/parse-options)
|
||||
[^2]: See [`writeFile` in "Writing Files"](/docs/api/write-options)
|
||||
[^3]: See [`write` in "Writing Files"](/docs/api/write-options)
|
||||
[^4]: See ["Supported Output Formats" in "Writing Files"](/docs/api/write-options#supported-output-formats) for details on `bookType`
|
@ -143,16 +143,16 @@ This demo was last tested in the following deployments:
|
||||
|
||||
| Node Version | Date | Node Status when tested |
|
||||
|:-------------|:-----------|:------------------------|
|
||||
| `0.12.18` | 2023-05-30 | End-of-Life |
|
||||
| `4.9.1` | 2023-05-30 | End-of-Life |
|
||||
| `6.17.1` | 2023-05-30 | End-of-Life |
|
||||
| `8.17.0` | 2023-05-30 | End-of-Life |
|
||||
| `10.24.1` | 2023-05-30 | End-of-Life |
|
||||
| `12.22.12` | 2023-05-30 | End-of-Life |
|
||||
| `14.21.3` | 2023-05-30 | End-of-Life |
|
||||
| `16.20.0` | 2023-05-30 | Maintenance LTS |
|
||||
| `18.16.0` | 2023-05-30 | Active LTS |
|
||||
| `20.2.0` | 2023-05-30 | Current |
|
||||
| `0.12.18` | 2023-09-02 | End-of-Life |
|
||||
| `4.9.1` | 2023-09-02 | End-of-Life |
|
||||
| `6.17.1` | 2023-09-02 | End-of-Life |
|
||||
| `8.17.0` | 2023-09-02 | End-of-Life |
|
||||
| `10.24.1` | 2023-09-02 | End-of-Life |
|
||||
| `12.22.12` | 2023-09-02 | End-of-Life |
|
||||
| `14.21.3` | 2023-09-02 | End-of-Life |
|
||||
| `16.20.0` | 2023-09-02 | Maintenance LTS |
|
||||
| `18.17.1` | 2023-09-02 | Active LTS |
|
||||
| `20.5.1` | 2023-09-02 | Current |
|
||||
|
||||
While streaming methods work in End-of-Life versions of NodeJS, production
|
||||
deployments should upgrade to a Current or LTS version of NodeJS.
|
||||
@ -212,7 +212,7 @@ Joseph Biden,46
|
||||
|
||||
:::note
|
||||
|
||||
The live demo was last tested on 2023 May 30 in Chromium 113.
|
||||
The live demo was last tested on 2023-09-02 in Chromium 116.
|
||||
|
||||
:::
|
||||
|
||||
@ -313,7 +313,7 @@ The following live demo fetches and parses a file in a Web Worker. The `to_csv`
|
||||
streaming function is used to generate CSV rows and pass back to the main thread
|
||||
for further processing.
|
||||
|
||||
:::note
|
||||
:::note pass
|
||||
|
||||
For Chromium browsers, the File System Access API provides a modern worker-only
|
||||
approach. [The Web Workers demo](/docs/demos/bigdata/worker#streaming-write)
|
||||
@ -443,7 +443,7 @@ stream.to_csv(wb.Sheets[wb.SheetNames[0]]).resume();`}
|
||||
|
||||
:::note
|
||||
|
||||
This demo was last tested on 2023 May 30
|
||||
This demo was last tested on 2023-09-02 against Deno `1.36.4`
|
||||
|
||||
:::
|
||||
|
@ -13,7 +13,7 @@ Parsing and writing large spreadsheets takes time. During the process, if the
|
||||
SheetJS library is running in the web browser, the website may freeze.
|
||||
|
||||
Workers provide a way to off-load the hard work so that the website does not
|
||||
freeze during processing. The work is still performed locally. No data is sent
|
||||
freeze during processing. The work is still performed locally. No data is sent
|
||||
to a remote server.
|
||||
|
||||
The following diagrams show the normal and Web Worker flows when exporting a
|
||||
@ -71,7 +71,7 @@ sequenceDiagram
|
||||
:::note Browser Compatibility
|
||||
|
||||
IE10+ and modern browsers support basic Web Workers. Some APIs like `fetch` were
|
||||
added later. Feature testing is highly recommended.
|
||||
added later. Feature testing is strongly recommended.
|
||||
|
||||
:::
|
||||
|
||||
@ -138,7 +138,7 @@ For production use, it is highly encouraged to download and host the script.
|
||||
ESM is supported in Web Workers in the Chromium family of browsers (including
|
||||
Chrome and Edge) as well as in browsers powered by WebKit (including Safari).
|
||||
|
||||
For legacy browsers like Firefox and IE, `importScripts` should be used.
|
||||
For legacy browsers including Firefox and IE, `importScripts` should be used.
|
||||
|
||||
:::
|
||||
|
||||
@ -189,10 +189,10 @@ Each browser demo was tested in the following environments:
|
||||
|
||||
| Browser | Date | Comments |
|
||||
|:------------|:-----------|:----------------------------------------|
|
||||
| Chrome 113 | 2023-05-22 | |
|
||||
| Edge 113 | 2023-05-22 | |
|
||||
| Safari 16.4 | 2023-05-22 | File System Access API is not supported |
|
||||
| Brave 1.51 | 2023-05-22 | File System Access API is not supported |
|
||||
| Chrome 116 | 2023-09-02 | |
|
||||
| Edge 116 | 2023-09-02 | |
|
||||
| Safari 16.6 | 2023-09-02 | File System Access API is not supported |
|
||||
| Brave 1.57 | 2023-09-02 | File System Access API is not supported |
|
||||
| Firefox 113 | 2023-05-22 | File System Access API is not supported |
|
||||
|
||||
:::
|
||||
@ -658,7 +658,8 @@ self.addEventListener('message', async(e) => {
|
||||
} else if(e.data.time) log(e.data.time, e.data.ts);
|
||||
};
|
||||
setCnt(0); setHz(0); setState(""); setHTML("");
|
||||
try {
|
||||
if(!window.showSaveFilePicker) setState("Browser missing API support!");
|
||||
else try {
|
||||
/* Show picker and get handle to file */
|
||||
const wFile = await window.showSaveFilePicker({
|
||||
suggestedName: "SheetJSStream.csv",
|
@ -17,9 +17,9 @@ and typed arrays is straightforward.
|
||||
This demo covers conversions between worksheets and Typed Arrays for use with
|
||||
TensorFlow.js and other ML libraries.
|
||||
|
||||
:::note
|
||||
:::info pass
|
||||
|
||||
Live code blocks in this page load the standalone build from version `4.6.0`.
|
||||
Live code blocks in this page load the standalone build from version `4.10.0`.
|
||||
|
||||
For use in web frameworks, the `@tensorflow/tfjs` module should be used.
|
||||
|
||||
@ -27,6 +27,18 @@ For use in NodeJS, the native bindings module is `@tensorflow/tfjs-node`.
|
||||
|
||||
:::
|
||||
|
||||
:::note pass
|
||||
|
||||
Each browser demo was tested in the following environments:
|
||||
|
||||
| Browser | Date | TF.js version |
|
||||
|:------------|:-----------|:--------------|
|
||||
| Chrome 116 | 2023-09-02 | `4.10.0` |
|
||||
| Safari 16.6 | 2023-09-02 | `4.10.0` |
|
||||
| Brave 1.57 | 2023-09-02 | `4.10.0` |
|
||||
|
||||
:::
|
||||
|
||||
## CSV Data Interchange
|
||||
|
||||
`tf.data.csv` generates a Dataset from CSV data. The function expects a URL.
|
||||
@ -55,7 +67,7 @@ The demo first fetches the XLSX file and generates CSV text. A blob URL is
|
||||
generated and fed to `tf.data.csv`. The rest of the demo follows the official
|
||||
example in the TensorFlow documentation.
|
||||
|
||||
:::caution
|
||||
:::caution pass
|
||||
|
||||
If the live demo shows a message
|
||||
|
||||
@ -181,7 +193,7 @@ async function getData() {
|
||||
|
||||
## Low-Level Operations
|
||||
|
||||
:::caution
|
||||
:::caution pass
|
||||
|
||||
While it is more efficient to use low-level operations, JS or CSV interchange
|
||||
is strongly recommended when possible.
|
||||
@ -191,7 +203,7 @@ is strongly recommended when possible.
|
||||
### Data Transposition
|
||||
|
||||
A typical dataset in a spreadsheet will start with one header row and represent
|
||||
each data record in its own row. For example, the Iris dataset might look like
|
||||
each data record in its own row. For example, the Iris dataset might look like
|
||||
|
||||
![Iris dataset](pathname:///files/iris.png)
|
||||
|
||||
@ -260,7 +272,7 @@ var ws = XLSX.utils.aoa_to_sheet(aoa);
|
||||
### Importing Data from a Spreadsheet
|
||||
|
||||
`sheet_to_json` with the option `header:1` will generate a row-major array of
|
||||
arrays that can be transposed. However, it is more efficient to walk the sheet
|
||||
arrays that can be transposed. However, it is more efficient to walk the sheet
|
||||
manually:
|
||||
|
||||
```js
|
@ -1,4 +1,4 @@
|
||||
{
|
||||
"label": "Big Data",
|
||||
"position": 11
|
||||
"position": 37
|
||||
}
|
@ -13,7 +13,7 @@ data processing in the web browser, and some innovations and discoveries have
|
||||
been integrated into the ReactJS framework and other foundational JS libraries.
|
||||
|
||||
JS Engines have improved over the years, but there are some hard limits to
|
||||
browser support using traditional methods of data processing. Vendors have
|
||||
browser support using traditional methods of data processing. Vendors have
|
||||
introduced APIs and techniques for representing and processing very large binary
|
||||
and textual files.
|
||||
|
@ -1,4 +1,4 @@
|
||||
{
|
||||
"label": "Other Languages",
|
||||
"position": 12
|
||||
"position": 42
|
||||
}
|
2
docz/static/tfjs/tf.min.js
vendored
2
docz/static/tfjs/tf.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user