我想给excel表的数据部分提供一个数组。我该怎么做呢?这是我的密码:
filteredData() {
for (const row of this.props.processes) {
const values = allverbisheaders.map((header) => {
return row[header];
});
this.state.CSVRows.push(values);
}
console.log(this.state.CSVRows[0]);
console.log(this.state.CSVRows[1]);
console.log(this.state.CSVRows[2]);
console.log(this.state.CSVRows[3]);
return this.state.CSVRows;
};
const VerbisSet = [
{
columns: [
{title: allverbisheaderstr[0], width: {wch: 27}},
{title: allverbisheaderstr[1], width: {wch: 20}},
{title: allverbisheaderstr[2], width: {wch: 33}},
{title: allverbisheaderstr[3], width: {wch: 30}},
{title: allverbisheaderstr[4], width: {wch: 30}},
{title: allverbisheaderstr[5], width: {wch: 30}},
{title: allverbisheaderstr[6], width: {wch: 30}},
{title: allverbisheaderstr[7], width: {wch: 30}},
],
data: [
[
this.state.CSVRows[0]
],
]
}
];
return (
<div>
<DropdownItem
onClick ={() => {this.filteredData()}}>
Process Listesi Kontrol
</DropdownItem>
<DropdownItem>
<ExcelFile element={<a>Verbis</a>}>
<ExcelSheet dataSet={VerbisSet} name="Verbis Data"/>
</ExcelFile>
</DropdownItem>
</div>
);}}
CSVRow是一个矩阵。第一个要素是:
(8) ["Education", "Learning Information", "Education Status", "CONTRACT", "E", "E", "Employee", "EMAIL - HAND"]我想将此矩阵添加到Excel表中。
我预先运行了filteredData函数并设置了CSVRows矩阵.
发布于 2020-11-20 14:04:27
我不太清楚你的数据的形状,但我怀疑这个问题是由数据的尺寸造成的。
从库的文档中,data字段的长度应该与columns字段的长度相匹配。但是,data字段的长度为1,而columns字段的长度为8。
尝试以下几点:
const VerbisSet = [
{
columns: [
{ title: allverbisheaderstr[0], width: { wch: 27 } },
{ title: allverbisheaderstr[1], width: { wch: 20 } },
{ title: allverbisheaderstr[2], width: { wch: 33 } },
{ title: allverbisheaderstr[3], width: { wch: 30 } },
{ title: allverbisheaderstr[4], width: { wch: 30 } },
{ title: allverbisheaderstr[5], width: { wch: 30 } },
{ title: allverbisheaderstr[6], width: { wch: 30 } },
{ title: allverbisheaderstr[7], width: { wch: 30 } },
],
data: [
// notice here, I removed one level of array nesting
this.state.CSVRows[0]
],
}
];或者简单的说:
const VerbisSet = [
{
columns: [
{ title: allverbisheaderstr[0], width: { wch: 27 } },
{ title: allverbisheaderstr[1], width: { wch: 20 } },
{ title: allverbisheaderstr[2], width: { wch: 33 } },
{ title: allverbisheaderstr[3], width: { wch: 30 } },
{ title: allverbisheaderstr[4], width: { wch: 30 } },
{ title: allverbisheaderstr[5], width: { wch: 30 } },
{ title: allverbisheaderstr[6], width: { wch: 30 } },
{ title: allverbisheaderstr[7], width: { wch: 30 } },
],
data: this.state.CSVRows,
}
];https://stackoverflow.com/questions/64914485
复制相似问题