Giter Site home page Giter Site logo

Comments (13)

zhangchenna avatar zhangchenna commented on May 23, 2024 1

0086/#/home:1 Uncaught (in promise) incorrect header check
P

from excelize-wasm.

xuri avatar xuri commented on May 23, 2024

Thanks for your feedback. Could you follow the issue template, and show us a complete, standalone example program or reproducible demo?

from excelize-wasm.

zhangchenna avatar zhangchenna commented on May 23, 2024

import { init } from 'excelize-wasm'

onMounted(() => {
init('./excelize.wasm.gz').then(excelize => {
const f = excelize.NewFile();
console.log(f);
});
});

from excelize-wasm.

zhangchenna avatar zhangchenna commented on May 23, 2024
<script src="https://zhangchenna-1252291207.cos.ap-beijing.myqcloud.com/index.js"></script>
Download
<script> console.log(excelizeWASM); function download() { excelizeWASM .init('https://zhangchenna-1252291207.cos.ap-beijing.myqcloud.com/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>

提示 Bad magic number

node 版本正常 浏览器运行报错

from excelize-wasm.

zhangchenna avatar zhangchenna commented on May 23, 2024

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.

zhangchenna avatar zhangchenna commented on May 23, 2024

所有代码都是来自你的 demo 我并没有修改,我的代码是从
npm 包中提取

from excelize-wasm.

xuri avatar xuri commented on May 23, 2024

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.

zhangchenna avatar zhangchenna commented on May 23, 2024

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.

xuri avatar xuri commented on May 23, 2024

Please reference the docs of the SetCellStyle function. Specify the Pattern field of the fill style.

from excelize-wasm.

xuri avatar xuri commented on May 23, 2024

I'll close this issue, if you have any questions, please let me know to reopen this anytime.

from excelize-wasm.

dearmark avatar dearmark commented on May 23, 2024

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.

zhangchenna avatar zhangchenna commented on May 23, 2024

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.

dearmark avatar dearmark commented on May 23, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.