0
import React from 'react';
import ReactExport from 'react-data-export';

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

ExcelData = [{
        columns:
            [
                [{ title: "Header1" }],
                [{ title: "Header2" }],
                [{ title: "Header3" }],
                [{ title: "Header4" }],
            ],
    data:
        [
          [ {..}, {..}, {..}, {..} ],
          [ {..}, {..}, {..}, {..} ],
          [ {..}, {..}, {..}, {..} ],
          [ {..}, {..}, {..}, {..} ],  
        ],    

}]

1.if i want to append the another object FinalData to the data array in given format like array of objects , under Header1 the Data from Data01 to Data04 likewise should come. how can we do that? The format of the FinalData will be

FinalData = [
                [{ value: "Data01" },
                 { value: "Data02" },
                 { value: "Data03" }
                 { value: "Data04"  }],
                [{ value: "Data21" },
                 { value: "Data22" },
                 { value: "Data23" }
                 { value: "Data24"  }],
                [{ value: "Data31" },
                 { value: "Data32" },
                 { value: "Data33" }
                 { value: "Data34"  }],
                [{ value: "Data41" },
                 { value: "Data42" },
                 { value: "Data43" }
                 { value: "Data44"  }],
            ]

I want the function which maps the FinalData to the data in ExcelData, the format should be the same. Because i need to pass the same structure in dataSet={ExcelData} to get the expected output Excel.

export default function ExcelExportTwo() {
    return (
        <div>
            <ExcelFile element={<button>ExcelExportThree</button>}>
                <ExcelSheet dataSet={ExcelData} name="Organization" />
            </ExcelFile>
        </div>
    );
}

Expected Output in the Excel Sheet should be enter image description here

Anvesh
  • 97
  • 2
  • 11
  • can you post your desired result? – michael Nov 19 '20 at 18:13
  • Your question is a little confusing, but surely you know how to access an item within an array with an index using square brackets, and know the existence of the pop() push() shif() unshift() array methods in javascript. (?) – EspressoBeans Nov 19 '20 at 18:16

1 Answers1

1

I am not sure if this is what you need.

const ExcelData = [
  {
    columns: [
      [{title: 'Header1'}],
      [{title: 'Header2'}],
      [{title: 'Header3'}],
      [{title: 'Header4'}],
    ],
    data: [],
  },
];

const FinalData = [
  [
    {value: 'Data11'},
    {value: 'Data12'},
    {value: 'Data13'},
    {value: 'Data14'},
  ],
  [
    {value: 'Data21'},
    {value: 'Data22'},
    {value: 'Data23'},
    {value: 'Data24'},
  ],
  [
    {value: 'Data31'},
    {value: 'Data32'},
    {value: 'Data33'},
    {value: 'Data34'},
  ],
  [
    {value: 'Data41'},
    {value: 'Data42'},
    {value: 'Data43'},
    {value: 'Data44'},
  ],
];

const result = [{...ExcelData[0], data: [...FinalData]}];
console.log(result);
michael
  • 4,053
  • 2
  • 12
  • 31