Comments (13)
0086/#/home:1 Uncaught (in promise) incorrect header check
P
from excelize-wasm.
Thanks for your feedback. Could you follow the issue template, and show us a complete, standalone example program or reproducible demo?
from excelize-wasm.
import { init } from 'excelize-wasm'
onMounted(() => {
init('./excelize.wasm.gz').then(excelize => {
const f = excelize.NewFile();
console.log(f);
});
});
from excelize-wasm.
提示 Bad magic number
node 版本正常 浏览器运行报错
from excelize-wasm.
export async function init(wasmPath) {
const go = new Go();
let buffer;
if (typeof window === 'undefined') {
global.excelize = {};
} else {
window.excelize = {};
}
buffer = await (await fetch(wasmPath)).arrayBuffer();
const result = await WebAssembly.instantiate(buffer, go.importObject);
go.run(result.instance);
return excelize;
}
把解压缩移除正常后浏览器就正常了 怀疑是那个pako 的问题
from excelize-wasm.
所有代码都是来自你的 demo 我并没有修改,我的代码是从
npm 包中提取
from excelize-wasm.
Thanks for your feedback. I've tested and it works well. Please try with following code:
<html>
<head>
<meta charset="utf-8">
<script src="https://xuri.me/excelize-wasm/v0.0.3/index.js"></script>
</head>
<body>
<div>
<button onclick="download()">Download</button>
</div>
<script>
function download() {
excelizeWASM
.init('https://xuri.me/excelize-wasm/v0.0.3/excelize.wasm.gz')
.then((excelize) => {
const f = excelize.NewFile();
// Create a new sheet.
const { index } = f.NewSheet('Sheet2');
// Set value of a cell.
f.SetCellValue('Sheet2', 'A2', 'Hello world.');
f.SetCellValue('Sheet1', 'B2', 100);
// Set active sheet of the workbook.
f.SetActiveSheet(index);
// Save spreadsheet by the given path.
const { buffer, error } = f.WriteToBuffer();
if (error) {
console.log(error);
return;
}
const link = document.createElement('a');
link.download = 'Book1.xlsx';
link.href = URL.createObjectURL(
new Blob([buffer], {
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
})
);
link.click();
});
}
</script>
</body>
from excelize-wasm.
Thanks for your feedback. I've tested and it works well. Please try with following code:
<html> <head> <meta charset="utf-8"> <script src="https://xuri.me/excelize-wasm/v0.0.3/index.js"></script> </head> <body> <div> <button onclick="download()">Download</button> </div> <script> function download() { excelizeWASM .init('https://xuri.me/excelize-wasm/v0.0.3/excelize.wasm.gz') .then((excelize) => { const f = excelize.NewFile(); // Create a new sheet. const { index } = f.NewSheet('Sheet2'); // Set value of a cell. f.SetCellValue('Sheet2', 'A2', 'Hello world.'); f.SetCellValue('Sheet1', 'B2', 100); // Set active sheet of the workbook. f.SetActiveSheet(index); // Save spreadsheet by the given path. const { buffer, error } = f.WriteToBuffer(); if (error) { console.log(error); return; } const link = document.createElement('a'); link.download = 'Book1.xlsx'; link.href = URL.createObjectURL( new Blob([buffer], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', }) ); link.click(); }); } </script> </body>
有没有关于单元格样式的demo
const style = f.NewStyle({
Font: { Color: 'FFFFFF' },
Fill: { Type: 'pattern', Color: ['E0EBF5'] },
});
console.log(style);
f.SetColWidth('Sheet1', 'A', 'A', 50);
f.SetColWidth('Sheet1', 'B', 'B', 30);
f.SetRowStyle('Sheet1', 1, 1, style);
f.SetCellStyle('Sheet1', 'A6', 'A6', style);
这么写不起做
from excelize-wasm.
Please reference the docs of the SetCellStyle
function. Specify the Pattern
field of the fill style.
from excelize-wasm.
I'll close this issue, if you have any questions, please let me know to reopen this anytime.
from excelize-wasm.
export async function init(wasmPath) { const go = new Go(); let buffer; if (typeof window === 'undefined') { global.excelize = {}; } else { window.excelize = {}; } buffer = await (await fetch(wasmPath)).arrayBuffer(); const result = await WebAssembly.instantiate(buffer, go.importObject); go.run(result.instance); return excelize; }
把解压缩移除正常后浏览器就正常了 怀疑是那个pako 的问题
Yes, it work. If someone use Vite and same problem ,just add to package.json
"excelize-wasm": "github:dearmark/excelize-wasm",
from excelize-wasm.
export async function init(wasmPath) { const go = new Go(); let buffer; if (typeof window === 'undefined') { global.excelize = {}; } else { window.excelize = {}; } buffer = await (await fetch(wasmPath)).arrayBuffer(); const result = await WebAssembly.instantiate(buffer, go.importObject); go.run(result.instance); return excelize; }
把解压缩移除正常后浏览器就正常了 怀疑是那个pako 的问题
Yes, it work. If someone use Vite and same problem ,just add to
package.json
"excelize-wasm": "github:dearmark/excelize-wasm",
换了一个压缩控件就行,pako 自身的问题
from excelize-wasm.
export async function init(wasmPath) { const go = new Go(); let buffer; if (typeof window === 'undefined') { global.excelize = {}; } else { window.excelize = {}; } buffer = await (await fetch(wasmPath)).arrayBuffer(); const result = await WebAssembly.instantiate(buffer, go.importObject); go.run(result.instance); return excelize; }
把解压缩移除正常后浏览器就正常了 怀疑是那个pako 的问题
Yes, it work. If someone use Vite and same problem ,just add to
package.json
"excelize-wasm": "github:dearmark/excelize-wasm",
换了一个压缩控件就行,pako 自身的问题
实际上,在部署到nginx时,我代码需要调用的是init('/wasm/excelize.wasm')
,因为nginx开启了gzip压缩,配合使用Vite生成dist时,会自动生成excelize.wasm.gz
文件;在我的使用场景里,无需提前使用.gz
文件,nginx自动映射。
from excelize-wasm.
Related Issues (10)
- memory running out HOT 3
- Argument type Buffer is not assignable to parameter type Uint8Array[] HOT 1
- Add support to fn GetStyle
- how to read excel in browser? HOT 3
- Feature request, add stream writer support 请问一下有考虑支持流式写入的功能吗? HOT 1
- Is it possible to format cells? HOT 3
- Does not run on Node 20+ HOT 1
- Document / implement a formalized release process
- [Feature request] Provide options for data validation drop list HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from excelize-wasm.