我将数据导出到Excel,但我会收到此错误:无法读取未定义的属性(Reading'编辑')
我想将我的材料表数据导出到Excel,但是当我单击下载时,我会在控制台中获得错误: 无法读取未定义的属性(读取')
(我使用“ xlsx”:“^0.18.0”),
<div onClick={downloadExcel} className="downloadExcel">
<img src="/assets/excel-svgrepo-com.svg" />
</div>
而我的downloadexcel函数是:
const downloadExcel = () => {
const newData = Apiary.map((row) => {
delete row.tableData;
return row;
});
const workSheet = XLSX.utils.json_to_sheet(newData);
const workBook = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(workBook, workSheet, "students");
//Buffer
let buf = XLSX.write(workBook, { bookType: "xlsx", type: "buffer" });
//Binary string
XLSX.write(workBook, { bookType: "xlsx", type: "binary" });
//Download
XLSX.writeFile(workBook, "لیست زنبورستان.xlsx");
};
当我onclick img img时,我的反应是冻结的,并停止 如何解决此错误?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
tl; dr:确保您将XLSX库类似:
import *从'xlsx'
我与vue.js上的xlsx相似的问题。
我正在使用
import xlsx从'xlsx'
导入lib,并在控制台上获取此错误:然后我在终端上注意到(正在运行vue.js应用程序)消息:
在'xlsx'
中找不到“导出'默认值'(导入为'xlsx'),因此我通过将导入更改为:
import * as xlsx从'xlsx'<
TL;DR: Make sure you import the XLSX library like this:
import * as XLSX from 'xlsx'
I had a similar issue with the XLSX on Vue.js.
I was importing the lib on a component with
import XLSX from 'xlsx'
and getting this error on the console:And then I noticed on the terminal (which was running the vue.js app) the message:
"export 'default' (imported as 'XLSX') was not found in 'xlsx'
So I've resolved it by changing the import to:
import * as XLSX from 'xlsx'
问题似乎是因为XLSX版本。 0.18.0和0.15.1之间有一些破裂的变化。
我能够通过三种方式解决问题:
import * as xlsx as xlsx as xlsx/xlsx.js;
实际上,实际上,在XLSX的较新版本,有两个可用的文件,即,XLSX/XLSX.JS和
XLSX/XLSX.MJS。默认情况下,App尝试加载.mjs文件,而.mjs文件默认不可导入。
通过明确定义配置以允许在应用中导入.mjs文件。
通过在整个项目中使用较低版本的XLSX。 XLSX版本0.15.1将起作用。
Problem seems to be because of xlsx version. There are some breaking changes between 0.18.0 and 0.15.1.
I was able to solve the issue in three ways:
import * as XLSX from 'xlsx/xlsx.js;
Actually, in newer version of xlsx, there are two files available, i.e, xlsx/xlsx.js and
xlsx/xlsx.mjs. By default, app tries to load .mjs file while .mjs files are not importable by default.
By explicitly defining config to allow import of .mjs files in the app.
By using lower version of xlsx across whole project. xlsx version 0.15.1 will work.