gpt4 book ai didi

javascript - 类型 'Buffer' 不可分配给类型 'BlobPart'

转载 作者:行者123 更新时间:2023-11-30 09:17:58 25 4
gpt4 key购买 nike

blobType: string = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8';
cols = ['Column1', 'Column2', 'Column3', 'Column4', 'Column5']
data = [
{ col1: "a1", col2: "b1", col3: "c1", col4: "d1", col5: "e1" },
{ col1: "a2", col2: "b2", col3: "c2", col4: "d2", col5: "e2" },
{ col1: "a3", col2: "b3", col3: "c3", col4: "d3", col5: "e3" },
{ col1: "a4", col2: "b4", col3: "c4", col4: "d4", col5: "e4" },
{ col1: "a5", col2: "b5", col3: "c5", col4: "d5", col5: "e5" }
]

这是我的方法

exportToExcel() {
var workbook = new Excel.Workbook();
workbook.creator = 'Web';
workbook.lastModifiedBy = 'Web';
workbook.created = new Date();
workbook.modified = new Date();
workbook.addWorksheet(this.sName, { views: [{state: 'frozen', ySplit: 3,
xSplit: 2, activeCell: 'A1', showGridLines: false}] });
let sheet = workbook.getWorksheet(1);
let head1 = ['Exported Data'];
sheet.addRow(head1);
sheet.addRow('');
sheet.getRow(3).values = this.cols;
sheet.columns = [
{ key: 'col1' },
{ key: 'col2' },
{ key: 'col3' },
{ key: 'col4' },
{ key: 'col5' }
];
sheet.addRows(this.data);
workbook.xlsx.writeBuffer().then(data => {
console.log(data);
const blob = new Blob([data], { type: this.blobType });
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = this.excelFileName;
a.click();
})
}
}

错误:

Type 'Buffer' is not assignable to type 'BlobPart'. Type 'Buffer' isnot assignable to type 'Blob'.Property 'size' is missing in type 'Buffer'. [2322] (parameter) data: Excel.Buffer

const blob = new Blob([data], { type: this.blobType }); 

我在上面一行遇到错误,我错过了什么吗??

最佳答案

这解决了我的问题:

const blob = new Blob([data as BlobPart], {
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
});

关于javascript - 类型 'Buffer' 不可分配给类型 'BlobPart',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53714922/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com