danfo.readExcel
Reads a JSON file from local or remote location into a DataFrame.
danfo.readExcel(source, options)
Parameters
Type
Description
source
string
source : string, URL or local file path to Excel file.
options
Object
{
sheet : string, (Optional) Name of the sheet which u want to parse. Default will be the first sheet. method: The HTTP method to use.
headers: Additional headers to send with the request if reading JSON from remote url. Supports all the node-fetch options in Nodejs, and all fetch options in browsers.
}

Example

The readExcel method can read excel files saved on a local disk, or over the internet.
Node.js
Browser
1
const dfd = require("danfojs-node")
2
const path = require("path")
3
4
let local_xcel = path.join(process.cwd(), "data", "testexcel.xlxs")
5
6
async function load_process_data() {
7
let df = await dfd.readExcel(local_xcel)
8
df.head().print()
9
}
10
11
load_process_data()
Copied!
1
<!DOCTYPE html>
2
<html lang="en">
3
4
<head>
5
<meta charset="UTF-8">
6
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/bundle.min.js"></script>
8
<title>Document</title>
9
</head>
10
11
<body>
12
13
<script>
14
15
const remote_url = 'https://file-examples-com.github.io/uploads/2017/02/file_example_XLS_100.xls';
16
dfd.readExcel(remote_url).then(df => {
17
df.head().print()
18
})
19
20
21
</script>
22
</body>
23
24
</html>
Copied!

Reading an input file object in the browser

By specifying a valid file object, you can load Excel files in the browser in DataFrames/Series
Browser
1
<!DOCTYPE html>
2
<html lang="en">
3
4
<head>
5
<meta charset="UTF-8">
6
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/bundle.min.js"></script>
8
<title>Document</title>
9
</head>
10
11
<body>
12
<input type="file" id="file" name="file">
13
<script>
14
const inputFile = document.querySelector('#file')
15
16
inputFile.addEventListener("change", async () => {
17
const excelFile = inputFile.files[0]
18
dfd.readExcel(excelFile).then((df) => {
19
df.print()
20
})
21
})
22
23
</script>
24
</body>
25
26
</html>
Copied!