Home » excel » ReactJS components for PDF export, Excel export and print

ReactJS components for PDF export, Excel export and print

Posted by: admin March 7, 2020 Leave a comment

Questions:

I´m building some ReactJS Table and Report components tha basically will contain <table> data, some graphics (d3) and some textual data. I need to provide 3 buttons:

  1. Export to PDF
  2. Export to Excel
  3. Print

Are there any trustable packages available for the tasks above using ReactJS ? What is the approach to handle these requirements ?

How to&Answers:

I would use a combination of the following JavaScript libraries:

React Csv is my favourite JavaScript library for working with csv. It excels at dynamic generation.

PDF Make is my favourite JavaScript library for generating PDFs.

Note: I would attach the files to this post, but there is currently no facility for this in StackOverflow.

Answer:

  1. react-pdf (published 16 days ago – not tested)
  2. react-export-excel (published 8 months ago – not tested)
  3. For printing, put window.print() in your code

Example:
Copy and paste this as .html (in React, it would be onClick={window.print()} … If I’m correct)

<!Doctype html>
<html>
  <body>
    <p>Use the button below to print</p>
    <button id="print" onclick="window.print()">Print</button>
  </body>
</html>

Answer:

Old question, but since I was looking for something similar, I ended up using :

  1. jspdf (see specific issue for reactjs)
  2. react-excel-workbook
  3. nothing yet, feel free to update the answer if you have.