description |
---|
Converts a DataFrame or Series to Excel file, and write file to disk or download in browser. |
danfo.toExcel(data, options)
Parameters | Type | Description | Default |
---|---|---|---|
data | Series or DataFrame | The Series or DataFrame to write to CSV | |
options | object, optional | Configuration object: {
writingOptions: Supports all xlsx write options. See https://docs.sheetjs.com/docs/api/write-options } |
{ |
The toExcel function can be used to write out a DataFrame or Series to Excel (.xlsx) file. The output format will depend on the environment. In the following examples, we show you how to write/download an Excel file from Node and Browser environments.
You can write a DataFrame or Series in Excel format using the toExcel function and specifying the file path.
{% tabs %} {% tab title="Node.js" %}
const dfd = require("danfojs-node")
let data = {
Abs: [20.2, 30, 47.3],
Count: [34, 4, 5],
"country code": ["NG", "FR", "GH"],
};
let df = new dfd.DataFrame(data);
dfd.toExcel(df, { filePath: "testOut.xlsx"});
{% endtab %} {% endtabs %}
You can automatically convert and download an Excel file in a browser environment, by specifying a filename. This will open a download window.
let data = {
Abs: [20.2, 30, 47.3],
Count: [34, 4, 5],
"country code": ["NG", "FR", "GH"],
};
let df = new DataFrame(data);
dfd.toExcel(df, { fileName: "testOut.xlsx"});