All Projects → react-csv → React Csv

react-csv / React Csv

Licence: mit
React components to build CSV files on the fly basing on Array/literal object of data

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Csv

Jxls
Java library for creating Excel reports using Excel templates
Stars: ✭ 128 (-82.51%)
Mutual labels:  excel, reporting
Psexcel
A simple Excel PowerShell module
Stars: ✭ 234 (-68.03%)
Mutual labels:  excel, reporting
Xlwings
xlwings is a BSD-licensed Python library that makes it easy to call Python from Excel and vice versa. It works with Microsoft Excel on Windows and macOS.
Stars: ✭ 2,181 (+197.95%)
Mutual labels:  excel, reporting
Pyetl
python ETL framework
Stars: ✭ 33 (-95.49%)
Mutual labels:  excel, etl
Samples-NET.Core-MVC-CSharp
ASP.NET Core 2.0 MVC C# samples for Stimulsoft Reports.Web reporting tool.
Stars: ✭ 28 (-96.17%)
Mutual labels:  excel, reporting
Transformalize
Configurable Extract, Transform, and Load
Stars: ✭ 125 (-82.92%)
Mutual labels:  excel, etl
Closedxml.report
ClosedXML.Report is a tool for report generation with which you can easily export any data from your .NET classes to Excel using a XLSX-template.
Stars: ✭ 230 (-68.58%)
Mutual labels:  excel, reporting
Openvasreporting
OpenVAS Reporting: Convert OpenVAS XML report files to reports
Stars: ✭ 42 (-94.26%)
Mutual labels:  excel, reporting
Samples-ASP.NET-MVC-CSharp
ASP.NET MVC C# samples for Stimulsoft Reports.Web reporting tool.
Stars: ✭ 31 (-95.77%)
Mutual labels:  excel, reporting
Reports.JS
Stimulsoft Reports.JS is a reporting tool for Node.js and JavaScript applications.
Stars: ✭ 33 (-95.49%)
Mutual labels:  excel, reporting
Jsreport
javascript based business reporting platform 🚀
Stars: ✭ 798 (+9.02%)
Mutual labels:  excel, reporting
Addax
Addax is an open source universal ETL tool that supports most of those RDBMS and NoSQLs on the planet, helping you transfer data from any one place to another.
Stars: ✭ 615 (-15.98%)
Mutual labels:  etl, excel
Yarg
Yet Another Report Generator - CUBA Platform reporting engine
Stars: ✭ 215 (-70.63%)
Mutual labels:  excel, reporting
Samples-JS-PHP
JavaScript and PHP samples for Stimulsoft Reports.PHP reporting tool.
Stars: ✭ 17 (-97.68%)
Mutual labels:  excel, reporting
StormReport
🌀 Library - Create your reports using only annotations
Stars: ✭ 17 (-97.68%)
Mutual labels:  excel, reporting
dbd
dbd is a database prototyping tool that enables data analysts and engineers to quickly load and transform data in SQL databases.
Stars: ✭ 30 (-95.9%)
Mutual labels:  etl, excel
Laracsv
A Laravel package to easily generate CSV files from Eloquent model
Stars: ✭ 583 (-20.36%)
Mutual labels:  excel
Calamine
A pure Rust Excel/OpenDocument SpeadSheets file reader: rust on metal sheets
Stars: ✭ 644 (-12.02%)
Mutual labels:  excel
Reporter
Service that generates a PDF report from a Grafana dashboard
Stars: ✭ 581 (-20.63%)
Mutual labels:  reporting
Pswinreporting
This PowerShell Module has multiple functionalities, but one of the signature features of this module is the ability to parse Security logs on Domain Controllers providing easy to use access to AD Events.
Stars: ✭ 575 (-21.45%)
Mutual labels:  reporting

Build Status Coverage Status

Build Status Coverage Status

Overview :

Generate a CSV file from given data.

This data can be an array of arrays, an array of literal objects, or strings.

Example :

import { CSVLink, CSVDownload } from "react-csv";

const csvData = [
  ["firstname", "lastname", "email"],
  ["Ahmed", "Tomi", "[email protected]"],
  ["Raed", "Labes", "[email protected]"],
  ["Yezzi", "Min l3b", "[email protected]"]
];
<CSVLink data={csvData}>Download me</CSVLink>;
// or
<CSVDownload data={csvData} target="_blank" />;

For more examples, see here 👈🏼

Install

npm install react-csv --save;

Or for non-node developers, you can use CDN directly:

<script src="https://cdn.rawgit.com/abdennour/react-csv/6424b500/cdn/react-csv-latest.min.js" type="text/javascript"></script>

Components:

This package includes two components: CSVLink and CSVDownload.

0. Common Props:

The two components accept the following Props:

- data Props:

A required property that represents the CSV data. This data can be array of arrays, array of literal objects or string.

Example of Array of arrays

// Array of arrays. Each item is rendered as a CSV line
data = [
  ["firstname", "lastname", "email"],
  ["Ahmed", "Tomi", "[email protected]"],
  ["Raed", "Labes", "[email protected]"],
  ["Yezzi", "Min l3b", "[email protected]"]
];

Example of array of literal objects

// Array of literal objects. Each item is rendered as CSV line however the order of fields will be defined by the headers props. If the headers props are not defined, the component will generate headers from each data item.
data = [
  { firstname: "Ahmed", lastname: "Tomi", email: "[email protected]" },
  { firstname: "Raed", lastname: "Labes", email: "[email protected]" },
  { firstname: "Yezzi", lastname: "Min l3b", email: "[email protected]" }
];

Example of strings

// A string can be used if the data is already formatted correctly

data = `firstname,lastname
Ahmed,Tomi
Raed,Labes
Yezzi,Min l3b
`;

// or using 3rd party package
import json2csv from "json2csv";
data = json2csv(arrayOfLiteralObjects);

- headers Props:

Specifying headers helps to define an order of the CSV fields. The csv content will be generated accordingly.

Notes :

  • The meaning of headers with data of type Array is to order fields AND prepend those headers at the top of the CSV content.
  • The meaning of headers with data of type String data is only prepending those headers as the first line of the CSV content.
Custom Header Labels

Custom header labels can be used when converting data of type Object to CSV by having the header array itself be an array of literal objects of the form:

{ label: /* Label to display at the top of the CSV */, key: /* Key to the data */ }

If the header array is an array of strings, the header labels will be the same as the keys used to index the data objects.

Example:

import { CSVLink } from "react-csv";

headers = [
  { label: "First Name", key: "firstname" },
  { label: "Last Name", key: "lastname" },
  { label: "Email", key: "email" }
];

data = [
  { firstname: "Ahmed", lastname: "Tomi", email: "[email protected]" },
  { firstname: "Raed", lastname: "Labes", email: "[email protected]" },
  { firstname: "Yezzi", lastname: "Min l3b", email: "[email protected]" }
];

<CSVLink data={data} headers={headers}>
  Download me
</CSVLink>;
Nested JSON data

It is possible to reference nested strings in your data using dot notation

headers = [
  { label: 'First Name', key: 'details.firstName' },
  { label: 'Last Name', key: 'details.lastName' },
  { label: 'Job', key: 'job' },
];

data = [
  { details: { firstName: 'Ahmed', lastName: 'Tomi' }, job: 'manager'},
  { details: { firstName: 'John', lastName: 'Jones' }, job: 'developer'},
];

Note: if at any point the nested keys passed do not exist then looks for key with dot notation in the object.

- separator Props:

Following a request to add this feature , from 1.0.1 release, react-csv supports separator props which is equals by default a comma , .

import { CSVLink } from "react-csv";

<CSVLink data={array} separator={";"}>
    Download me
</CSVLink>

/*
    "foo";"bar"
    "a";"b"
 */

- enclosingCharacter Props:

Following a request to add this feature, react-csv supports an enclosingCharacter prop which defaults to ".

import {CSVLink} from 'react-csv';

<CSVLink data={array} enclosingCharacter={`'`}>
    Download me
</CSVLink>

/*
    'foo','bar'
    'a','b'
 */

1. CSVLink Component:

It renders a hyperlink and clicking on it will trigger the download action of the CSV document.

It does not accept only data and headers props, but it also renders all props of HTMLAnchor tag. (className, target,....)

- filename Props:

filename is another props restricted to CSVLink. It specifies the filename of the downloaded CSV.

example

import { CSVLink } from "react-csv";

<CSVLink
  data={data}
  filename={"my-file.csv"}
  className="btn btn-primary"
  target="_blank"
>
  Download me
</CSVLink>;

- onClick Props:

onClick is another props restricted to CSVLink.

If it is defined, it means 3 things:

1 - It will run at the top of the click handling logic. 2 - [Sync] If it returns an explicit false, the return will be interpreted as a claim to stop the click handling, then, the next logic will not be executed if so. 3 - [Async] If it is async, "done" argument must be called if you want to invoke the handling of the component. (check examples below) 4 - [Async] If it is async (includes api call, timeout,... ) and it calls done with false will be interpreted as a claim to stop the click handling, then, the next logic will not be executed if so.

examples

  • 🔬 Sync + Proceed
import { CSVLink } from "react-csv";

<CSVLink
  data={data}
  onClick={() => {
    console.log("You click the link"); // 👍🏻 Your click handling logic
  }}
>
  Download me
</CSVLink>;
  • 🔬 Sync + Don't Proceed
import { CSVLink } from "react-csv";

<CSVLink
  data={data}
  onClick={event => {
    console.log("You click the link");
    return false; // 👍🏻 You are stopping the handling of component
  }}
>
  Download me
</CSVLink>;
  • 🔬 Async + Proceed
import { CSVLink } from "react-csv";

<CSVLink
  data={data}
  asyncOnClick={true}
  onClick={(event, done) => {
    axios.post("/spy/user").then(() => {
      done(); // REQUIRED to invoke the logic of component
    });
  }}
>
  Download me
</CSVLink>;
  • 🔬 Async + Don't Proceed
import { CSVLink } from "react-csv";

<CSVLink
  data={data}
  asyncOnClick={true}
  onClick={(event, done) => {
    axios.post("/spy/user").then(() => {
      done(false); // Don't Proceed
    });
  }}
>
  Download me
</CSVLink>;

2. CSVDownload Component:

It triggers downloading ONLY on mounting the component. so , be careful to render this component whenever it is needed.

It does not accept only data and headers props , but also , it takes advantage of all arguments of window.open function known that its signature is :

window.open(ARG0, target, specs, replace);

Thus, target, specs and replace Props are available .

example

import { CSVDownload } from "react-csv";

<CSVDownload data={data} target="_blank" />;

For non-node developers, they have to use CDN version :

 <script src="https://cdn.rawgit.com/abdennour/react-csv/6424b500/cdn/react-csv-latest.min.js" type="text/javascript"></script>

 <script type="text/babel">
   const {CSVDownload, CSVLink} = ReactCSV;// or window.ReactCSV

   const element= (<CSVDownload data={data} target="_blank" />);

   ReactDOM.render(element, document.querySelector('#app'));
 </script>

Contribution :

  • Unit-tests must cover at least 90% of code .

  • Write documentation of the new class, function, method, attribute ..so on.. following JSDoc syntax.

  • Add an example for the new feature to sample-site.

  • docker-compose run --rm npm start runs the sample-site

  • docker-compose run --rm npm run docgen generates documentation in HTML output.

  • docker-compose run --rm npm run cdn generate a bundle to be used as CDN

Donation

If this project help you reduce time to develop, you can give me a cup of coffee 🍵 :)

paypal

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].