Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将嵌套数组导出为xlsx格式_Javascript_Excel_Reactjs_Antd - Fatal编程技术网

Javascript 将嵌套数组导出为xlsx格式

Javascript 将嵌套数组导出为xlsx格式,javascript,excel,reactjs,antd,Javascript,Excel,Reactjs,Antd,我正在使用Antd表格显示数据列表。我需要将表格数据导出为excel文件。我目前正在使用这个软件包。但是我不确定如何处理嵌套的对象数组 const data = [ { "id": 83, "name": "Tim", "reports": [ { "id": 4, "self": 0, "year": 2019, "month": 12,

我正在使用Antd表格显示数据列表。我需要将表格数据导出为excel文件。我目前正在使用这个软件包。但是我不确定如何处理嵌套的对象数组

const data = [
  {
     "id": 83,
     "name": "Tim",      
     "reports": [
        {
           "id": 4,
           "self": 0,
           "year": 2019,
           "month": 12,
           "appraiser": 0
        },
        {
           "id": 5,
           "self": 0,
           "year": 2020,
           "month": 1,
           "appraiser": 0
        },
        {
           "id": 6,
           "self": 0,
           "year": 2020,
           "month": 2,
           "appraiser": 0
        }, {
           "id": 7,
           "self": 0,
           "year": 2020,
           "month": 8,
           "appraiser": 0
        },
     ],
     "average": 0
  },
  {
     "id": 91,
     "name": "Jhon",       
     "reports": [
        {
           "id": 8,
           "self": 0,
           "year": 2019,
           "month": 12,
           "appraiser": 0
        },
        {
           "id": 9,
           "self": 0,
           "year": 2020,
           "month": 1,
           "appraiser": 0
        },
        {
           "id": 10,
           "self": 0,
           "year": 2020,
           "month": 2,
           "appraiser": 0
        }, {
           "id": 11,
           "self": 0,
           "year": 2020,
           "month": 8,
           "appraiser": 0
        },
     ],
     "average": 0
  }]
Export.js

import React from "react";
import ReactExport from "react-export-excel";

const ExcelFile = ReactExport.ExcelFile;
const ExcelSheet = ReactExport.ExcelFile.ExcelSheet;
const ExcelColumn = ReactExport.ExcelFile.ExcelColumn;

const exportReport = ({ report }) => {

return (
    <ExcelFile element={downloadButton}>
        <ExcelSheet data={report} name="Report">
            <ExcelColumn label="Id" value="id"></ExcelColumn>
            <ExcelColumn label="Name" value="name"></ExcelColumn>
            <ExcelColumn label="Average" value="average"></ExcelColumn>
        </ExcelSheet>
    </ExcelFile>
)
}

export default exportReport

你能制作一个代码沙盒吗?@blueseal当然!。请检查“我当前正在使用react export excel软件包。”-您的代码沙盒中没有“react export excel”软件包。@blueseal似乎react export excel在后台使用xlsx库。它不处理复杂的JSON结构。我使用了xlsx来构造适合我的数据。我将很快更新答案。无论如何谢谢你!
| id |       January-2020 |      February-2020 |average| 
|--------|----------------|-----------------|
|         self | appraiser  self | appraiser
         |----------------|---------------- |          |
| 83     |   0  |    0    |  0     |    0   |      0   |
| 91     |   0  |    0    |  0     |    0   |      0   |