{`\
// @deno-types="https://cdn.sheetjs.com/xlsx-${current}/package/types/index.d.ts"
import * as XLSX from 'https://cdn.sheetjs.com/xlsx-${current}/package/xlsx.mjs';
const workbook = XLSX.readFile("test.xlsx");`}
:::note
Applications reading files must be invoked with the `--allow-read` flag.
:::
{`\
// @deno-types="https://cdn.sheetjs.com/xlsx-${current}/package/types/index.d.ts"
import * as XLSX from 'https://cdn.sheetjs.com/xlsx-${current}/package/xlsx.mjs';
/* load the codepage support library for extended support with older formats */
import * as cptable from 'https://cdn.sheetjs.com/xlsx-${current}/package/dist/cpexcel.full.mjs';
XLSX.set_cptable(cptable);
import * as Drash from "https://deno.land/x/drash@v2.5.4/mod.ts";
class SheetResource extends Drash.Resource {
public paths = ["/"];
public POST(request: Drash.Request, response: Drash.Response) {
// highlight-next-line
const file = request.bodyParam("file");
if (!file) throw new Error("File is required!");
// highlight-next-line
var wb = XLSX.read(file.content, {type: "buffer"});
var html = XLSX.utils.sheet_to_html(wb.Sheets[wb.SheetNames[0]]);
return response.html(html);
}
}
const server = new Drash.Server({ hostname: "", port: 7262, protocol: "http",
resources: [
// highlight-next-line
SheetResource,
],
});
server.run();`}
:::note
Deno must be run with the `--allow-net` flag to enable network requests:
```bash
deno run --allow-net test-server.ts
```
To test, submit a POST request to http://localhost:7262 including a file:
```bash
curl -X POST -F "file=@test.xlsx" http://localhost:7262/
```
:::
{`\
// @deno-types="https://cdn.sheetjs.com/xlsx-${current}/package/types/index.d.ts"
import * as XLSX from 'https://cdn.sheetjs.com/xlsx-${current}/package/xlsx.mjs';
/* load the codepage support library for extended support with older formats */
import * as cptable from 'https://cdn.sheetjs.com/xlsx-${current}/package/dist/cpexcel.full.mjs';
XLSX.set_cptable(cptable);
const url = "https://oss.sheetjs.com/test_files/formula_stress_test.xlsx";
// highlight-next-line
const data = await (await fetch(url)).arrayBuffer();
/* data is an ArrayBuffer */
const workbook = XLSX.read(data);`}
:::note
Deno must be run with the `--allow-net` flag to enable network requests:
```
deno run --allow-net test-fetch.ts
```
:::
{`\
// @deno-types="https://cdn.sheetjs.com/xlsx-${current}/package/types/index.d.ts"
import * as XLSX from 'https://cdn.sheetjs.com/xlsx-${current}/package/xlsx.mjs';
import { readAll } from "https://deno.land/std/streams/conversion.ts";
/* Simple Deno.Reader from a file */
const file = await Deno.open("test.xlsx", {read: true});
/* \`content\` will be a Uint8Array holding the full contents of the stream */
const content = await readAll(file);
/* Since this is a Uint8Array, \`XLSX.read\` "just works" */
const wb = XLSX.read(content);
console.log(wb.SheetNames);`}
Sheet | JS |
12345 | 67 |