react-tabulator icon indicating copy to clipboard operation
react-tabulator copied to clipboard

How to create PDF or XLS?

Open benriga opened this issue 5 years ago • 6 comments

How to create PDF or XLS?

Short Description: I've been unable to get Tabulator to create a PDF or Excel spreadsheet. I consistently get ReferenceError no matter what I try.

Long Description I've been trying to get Tabulator to create a PDF or Excel spreadsheet but I consistently get ReferenceError: jsPDF is not defined or ReferenceError: XLSX is not defined

Code For Excel I know I have XLSX working as I can create a spreadsheet directly with it but the tabulator download function fails with a ReferenceError. PDF gives the same result.


// this line works fine
        XLSX.utils.book_new(); 
// this line fails with a ReferenceError
        tablulatorRef.table.download("xlsx", "data.xlsx", {
          sheetName: "Export to Excel"
        });

Is there some way to pass the XLSX reference to Tabulator? I've been unable to find any sample that works for me. I feel like I'm missing some critical information to get this working.

Any help or a nudge in the right direction would be appreciated.

benriga avatar Jan 29 '20 04:01 benriga

@benriga Did you solve this? I just posted a similar download issue. Seeing if you've solved and can provide some guidance.

https://github.com/ngduc/react-tabulator/issues/76#issuecomment-586407150

psaban20 avatar Feb 14 '20 19:02 psaban20

@psaban20 No. Sorry. I set it aside while I work on other things.

benriga avatar Feb 15 '20 17:02 benriga

@benriga I'll keep trying and will let you know if I get anywhere.

psaban20 avatar Feb 15 '20 17:02 psaban20

I had the same issue and managed to solve by adding these three script tags in the head of my public/index.html file:

<script src="https://unpkg.com/xlsx/dist/xlsx.full.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/jspdf.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/jspdf.plugin.autotable.js"></script>

SalimSalici avatar Jul 14 '20 14:07 SalimSalici

it does not work in a react Js project

mrm15 avatar Jan 29 '23 08:01 mrm15

It actually does work. Add the scripts to index.html

Download table data using the snippet.

if(tableRef!==null && tableRef.current!==null && tableRef.current!==undefined){ // @ts-ignore: tableRef.current.download("xlsx", "data.xlsx", {sheetName:"My Data"}); }

arindammitra06 avatar Oct 02 '23 23:10 arindammitra06