首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >反应导出Excel?

反应导出Excel?
EN

Stack Overflow用户
提问于 2020-11-19 15:11:34
回答 1查看 2.1K关注 0票数 1

我想给excel表的数据部分提供一个数组。我该怎么做呢?这是我的密码:

代码语言:javascript
复制
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是一个矩阵。第一个要素是:

代码语言:javascript
复制
(8) ["Education", "Learning Information", "Education Status", "CONTRACT", "E", "E", "Employee", "EMAIL - HAND"]

我想将此矩阵添加到Excel表中。

我预先运行了filteredData函数并设置了CSVRows矩阵.

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-11-20 14:04:27

我不太清楚你的数据的形状,但我怀疑这个问题是由数据的尺寸造成的。

从库的文档中,data字段的长度应该与columns字段的长度相匹配。但是,data字段的长度为1,而columns字段的长度为8。

尝试以下几点:

代码语言:javascript
复制
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]
    ],
  }
];

或者简单的说:

代码语言:javascript
复制
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,
  }
];
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64914485

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档