-
-
Notifications
You must be signed in to change notification settings - Fork 8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deno support #2217
Comments
FYI found this trail (up to about 10 messages from that point) which has some diagnosis - looks like it's not possible currently |
same problem.. |
we have SheetJS working with Deno v1.10.x here, in case it helps either of you: https://github.com/githubocto/flat-postprocessing/blob/main/src/xlsx.ts |
Assuming the next release will have actual ESM builds and a proper |
@thouger There are two ways to read a file and then use sheetjs for other operations:
// demo.js
// Use: deno run --allow-all demo.js
import XLSX from 'https://esm.sh/xlsx';
const xlsxData /* Uint8Array */ = Deno.readFileSync(new URL('example.xlsx', import.meta.url).pathname);
const workBook = XLSX.readFile(
xlsxData.buffer,
{ type: "array" }
);
// console.log('sheets', workBook.Sheets);
console.log('sheetNames', workBook.SheetNames);
const json = XLSX.utils.sheet_to_json(workBook.Sheets[workBook.SheetNames[0]])
console.log('jsonData-sheetNames[0]', json); |
谢谢你的回答哈哈哈哈,我后面放弃了deno了,很多库没有兼容比较麻烦。 |
Consider the following sample: import * as XLSX from 'https://jspm.dev/npm:xlsx@0.18.0!cjs';
const rawdata = Deno.readFileSync("test.xlsb");
const wb = XLSX.read(rawdata, {type: "buffer"});
const buf = XLSX.write(wb, {type: "buffer", bookType: "fods"});
await Deno.writeFileSync("test.fods", new Uint8Array(buf)); This currently works with release 0.18.0 on deno 1.10.3 + typescript 4.2.2 with the following command: $ deno run --allow-read --allow-write test.ts It is also possible to reference the ESM build directly: import * as XLSX from 'https://unpkg.com/xlsx/xlsx.mjs'; Issues:
It is still not generally recommended to use the ESM build for a few reasons, including "missing codepage support" (the library will need a method to do it instead of proactively trying to
|
pushed a special tag // @deno-types="https://deno.land/x/sheetjs@v0.18.0+deno/types/index.d.ts"
import * as XLSX from 'https://deno.land/x/sheetjs@v0.18.0+deno/xlsx.mjs';
import * as cptable from 'https://deno.land/x/sheetjs/dist/cpexcel.full.mjs';
XLSX.set_cptable(cptable);
const ws = XLSX.utils.aoa_to_sheet([["a","b","c"],[1,2,3],[4,5,6]]);
const wb = XLSX.utils.book_new(); XLSX.utils.book_append_sheet(wb, ws, "Sheet1");
XLSX.writeFile(wb, "test.xlsx");
const workbook = XLSX.readFile("test.xlsx");
XLSX.utils.sheet_add_aoa(workbook.Sheets["Sheet1"], [[7, 8, 9]], { origin: -1 });
XLSX.writeFile(workbook, "test1.xlsx"); The other discussed issues will be raised separately |
I've come across SheetJS via the Deno third-party modules. However there's no example or usage for deno. Is it possible to use with Deno? Apparently Deno prefers code imports that conform to ES modules. I've tried to use SheetJS via skypak.dev which can sometimes help convert node packages to modern ES modules, but I can't get the import to work, so sample code doesn't work. https://jspm.org/ might be another option. Unfortunately I'm learning server-side JS and Deno. Appreciate any tips to get it working on Deno. Thanks.
The text was updated successfully, but these errors were encountered: