forked from sheetjs/docs.sheetjs.com
		
	denoncm
This commit is contained in:
		
							parent
							
								
									17850ebbd3
								
							
						
					
					
						commit
						c72069816c
					
				| @ -7,19 +7,12 @@ sidebar_custom_props: | ||||
| --- | ||||
| 
 | ||||
| import current from '/version.js'; | ||||
| import Tabs from '@theme/Tabs'; | ||||
| import TabItem from '@theme/TabItem'; | ||||
| 
 | ||||
| # Deno | ||||
| 
 | ||||
| [Deno](https://deno.land/) is a JavaScript runtime powered by V8. | ||||
| 
 | ||||
| :::caution Deno support is considered experimental. | ||||
| 
 | ||||
| Great open source software grows with user tests and reports. Any issues should | ||||
| be reported to the Deno project for further diagnosis. | ||||
| 
 | ||||
| ::: | ||||
| 
 | ||||
| Each standalone release script is available at <https://cdn.sheetjs.com/>. | ||||
| Module scripts and type definitions are available at <https://cdn.sheetjs.com/>. | ||||
| 
 | ||||
| Using the URL imports, `deno run` will automatically download scripts and types: | ||||
| 
 | ||||
| @ -30,12 +23,10 @@ import * as XLSX from 'https://cdn.sheetjs.com/xlsx-${current}/package/xlsx.mjs' | ||||
| 
 | ||||
| The `@deno-types` comment instructs Deno to use the type definitions. | ||||
| 
 | ||||
| :::warning | ||||
| :::caution Deno support is considered experimental. | ||||
| 
 | ||||
| Older releases are technically available on [deno.land/x](https://deno.land/x/) | ||||
| but the Deno registry is out of date. | ||||
| 
 | ||||
| <https://cdn.sheetjs.com/> is the authoritative source for SheetJS scripts. | ||||
| Great open source software grows with user tests and reports. Any issues should | ||||
| be reported to the Deno project for further diagnosis. | ||||
| 
 | ||||
| ::: | ||||
| 
 | ||||
| @ -48,3 +39,92 @@ If Encoding support is required, `cpexcel.full.mjs` must be manually imported: | ||||
| import * as cptable from 'https://cdn.sheetjs.com/xlsx-${current}/package/dist/cpexcel.full.mjs'; | ||||
| XLSX.set_cptable(cptable);`} | ||||
| </code></pre> | ||||
| 
 | ||||
| ## Node Compatibility Mode | ||||
| 
 | ||||
| :::caution | ||||
| 
 | ||||
| Node Compatibility Mode is useful for migrating existing NodeJS scripts to Deno. | ||||
| It is considered unstable by the platform developers. | ||||
| 
 | ||||
| For greenfield Deno projects, HTTP imports are strongly recommended. | ||||
| 
 | ||||
| ::: | ||||
| 
 | ||||
| The ["NodeJS" installation section](/docs/getting-started/installation/nodejs) | ||||
| includes instructions for installing the NodeJS package. | ||||
| 
 | ||||
| After installing, the `std/node` require can be used directly: | ||||
| 
 | ||||
| ```ts | ||||
| /* load the `require` machinery */ | ||||
| import { createRequire } from "https://deno.land/std/node/module.ts"; | ||||
| const require = createRequire(import.meta.url); | ||||
| 
 | ||||
| /* require the library */ | ||||
| const XLSX = require("xlsx"); | ||||
| ``` | ||||
| 
 | ||||
| ## Upgrade Notes | ||||
| 
 | ||||
| Upgrading to the latest version involves changing the import URLs.  The import | ||||
| and the types URLs should be updated at the same time: | ||||
| 
 | ||||
| <pre><code parentName="pre" {...{"className": "language-diff"}}>{`\ | ||||
| -// @deno-types="https://cdn.sheetjs.com/xlsx-0.18.3/package/types/index.d.ts" | ||||
| +// @deno-types="https://cdn.sheetjs.com/xlsx-${current}/package/types/index.d.ts" | ||||
| 
 | ||||
| -import * as XLSX from 'https://cdn.sheetjs.com/xlsx-0.18.3/package/xlsx.mjs'; | ||||
| +import * as XLSX from 'https://cdn.sheetjs.com/xlsx-${current}/package/xlsx.mjs'; | ||||
| 
 | ||||
| -import * as cptable from 'https://cdn.sheetjs.com/xlsx-0.18.3/package/dist/cpexcel.full.mjs'; | ||||
| +import * as cptable from 'https://cdn.sheetjs.com/xlsx-${current}/package/dist/cpexcel.full.mjs'; | ||||
| `} | ||||
| </code></pre> | ||||
| 
 | ||||
| #### Deno Registry | ||||
| 
 | ||||
| :::warning | ||||
| 
 | ||||
| The official Deno registry is out of date.  This is a registry bug. | ||||
| 
 | ||||
| <https://cdn.sheetjs.com/> is the authoritative source for SheetJS scripts. | ||||
| 
 | ||||
| ::: | ||||
| 
 | ||||
| Applications using the Deno registry can migrate by changing the URLs. | ||||
| 
 | ||||
| <Tabs> | ||||
|   <TabItem value="v" label="URL with version"> | ||||
| 
 | ||||
| The SheetJS CDN version has no `v`.  For example, `v0.18.3` maps to `0.18.3`: | ||||
| 
 | ||||
| ```diff | ||||
| -// @deno-types="https://deno.land/x/sheetjs@v0.18.3/types/index.d.ts" | ||||
| +// @deno-types="https://cdn.sheetjs.com/xlsx-0.18.3/package/types/index.d.ts" | ||||
| 
 | ||||
| -import * as XLSX from 'https://deno.land/x/sheetjs@v0.18.3/xlsx.mjs'; | ||||
| +import * as XLSX from 'https://cdn.sheetjs.com/xlsx-0.18.3/package/xlsx.mjs'; | ||||
| 
 | ||||
| -import * as cptable from 'https://deno.land/x/sheetjs@v0.18.3/dist/cpexcel.full.mjs'; | ||||
| +import * as cptable from 'https://cdn.sheetjs.com/xlsx-0.18.3/package/dist/cpexcel.full.mjs'; | ||||
| ``` | ||||
| 
 | ||||
|   </TabItem> | ||||
|   <TabItem value="nov" label="URL without version"> | ||||
| 
 | ||||
| Version-less imports (`https://deno.land/x/sheetjs/xlsx.mjs`) map to `0.18.3`: | ||||
| 
 | ||||
| ```diff | ||||
| -// @deno-types="https://deno.land/x/sheetjs/types/index.d.ts" | ||||
| +// @deno-types="https://cdn.sheetjs.com/xlsx-0.18.3/package/types/index.d.ts" | ||||
| 
 | ||||
| -import * as XLSX from 'https://deno.land/x/sheetjs/xlsx.mjs'; | ||||
| +import * as XLSX from 'https://cdn.sheetjs.com/xlsx-0.18.3/package/xlsx.mjs'; | ||||
| 
 | ||||
| -import * as cptable from 'https://deno.land/x/sheetjs/dist/cpexcel.full.mjs'; | ||||
| +import * as cptable from 'https://cdn.sheetjs.com/xlsx-0.18.3/package/dist/cpexcel.full.mjs'; | ||||
| ``` | ||||
| 
 | ||||
|   </TabItem> | ||||
| </Tabs> | ||||
|  | ||||
| @ -80,8 +80,6 @@ body parser out of the box. | ||||
| In testing, [Drash](https://drash.land/drash/) had an in-memory body parser | ||||
| which could handle file uploads on hosted services like Deno Deploy. | ||||
| 
 | ||||
| The service <https://s2c.sheetjs.com> is hosted on Deno Deploy using Drash! | ||||
| 
 | ||||
| _Reading Data_ | ||||
| 
 | ||||
| `Request#bodyParam` reads body parameters.  For uploaded files, the `content` | ||||
| @ -174,9 +172,9 @@ class ParseResource extends Drash.Resource { | ||||
| <pre><h3><a href="//sheetjs.com/">SheetJS</a> Spreadsheet Conversion Service</h3> | ||||
| <b>API</b> | ||||
| 
 | ||||
| Send a POST request to https://s2c.sheetjs.com/ with the file in the "file" body parameter: | ||||
| Send a POST request to http://localhost:3000/ with the file in the "file" body parameter: | ||||
| 
 | ||||
| $ curl -X POST -F"file=@test.xlsx" https://s2c.sheetjs.com/ | ||||
| $ curl -X POST -F"file=@test.xlsx" http://localhost:3000/ | ||||
| 
 | ||||
| The response will be an HTML TABLE generated from the first worksheet. | ||||
| 
 | ||||
| @ -459,8 +457,8 @@ fastify.post('/', async(req, reply) => { | ||||
| Out of the box, Fastify will return an error `FST_ERR_CTP_BODY_TOO_LARGE` when | ||||
| processing large spreadsheets (`statusCode 413`).  This is a Fastify issue. | ||||
| 
 | ||||
| [`bodyLimit`](https://www.fastify.io/docs/latest/Reference/Server/#bodylimit) | ||||
| in the docs explains the setting. It can be overridden during server creation: | ||||
| The default body size limit (including all uploaded files and fields) is 1 MB. | ||||
| It can be increased by setting the `bodyLimit` option during server creation: | ||||
| 
 | ||||
| ```js | ||||
| /* increase request body size limit to 5MB = 5 * 1024 * 1024 bytes */ | ||||
|  | ||||
| @ -126,12 +126,14 @@ support for CSS styling and rich text. | ||||
| ```html | ||||
| <script> | ||||
| (async() => { | ||||
|   const f = await fetch(URL_TO_DOWNLOAD); // replace with the URL of the file | ||||
|   const ab = await f.arrayBuffer(); | ||||
|   /* replace with the URL of the file */ | ||||
|   const URL_TO_DOWNLOAD = "https://sheetjs.com/pres.numbers"; | ||||
|   const ab = await (await fetch(URL_TO_DOWNLOAD)).arrayBuffer(); | ||||
| 
 | ||||
|   /* Parse file and get first worksheet */ | ||||
|   const wb = XLSX.read(ab); | ||||
|   const ws = wb.Sheets[wb.SheetNames[0]]; | ||||
|   const wsname = wb.SheetNames[0]; | ||||
|   const ws = wb.Sheets[wsname]; | ||||
| 
 | ||||
|   /* Generate HTML */ | ||||
|   var output = document.getElementById("TableContainer"); | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user