Open mantegnous opened 5 years ago
Need to import like this (see example):
import React from "react";
import ReactExport from "react-data-export";
const ExcelFile = ReactExport.ExcelFile;
const ExcelSheet = ReactExport.ExcelFile.ExcelSheet;
const ExcelColumn = ReactExport.ExcelFile.ExcelColumn;
I encounter the same issue. In order to resolve all the issues after adding the package to my project I had to:
Adding to webpack config
(using webpack 4):
....
node: { fs: 'empty' },
externals: [
{ './cptable': 'var cptable' },
{ './jszip': 'jszip' },
],
...
Add xlsx
package to solve issue #90 (as the answer suggested):
yarn add xlsx
The code to export is:
...
import ReactExport from "react-data-export";
..
const ExcelFile = ReactExport.ExcelFile;
const ExcelSheet = ReactExport.ExcelFile.ExcelSheet;
const ExcelColumn = ReactExport.ExcelFile.ExcelColumn;
class MyClass extends Component { .... exportData = async () => { const entries = await this.props.getData();
return (
<ExcelFile>
<ExcelSheet data={entries} name="Data">
<ExcelColumn label="Name" value="name" />
<ExcelColumn label="Time" value="time" />
<ExcelColumn label="ID" value="uniqeId" />
<ExcelColumn label="Action" value="action" />
</ExcelSheet>
</ExcelFile>
);
} ..... render() { return ( ...
I have the same issue, any one solved this?
I am using different solution, I am using xlsx
package directly:
import XLSX from 'xlsx';
export default (data, fileName) => {
// create a new blank workbook
const workBook = XLSX.utils.book_new();
// convert from json to worksheet
const workSheet = XLSX.utils.json_to_sheet(data);
// insert worksheet into workbook
XLSX.utils.book_append_sheet(workBook, workSheet, [sheetName]);
// download file
XLSX.writeFile(workBook, `${fileName}.xlsx`);
};
import { default as ExcelFile, ExcelSheet, ExcelColumn } from "react-data-export";
No works.. why?