Sheetah is a Node.js library that streamlines the process of exporting Excel files. With the sheetah.io service, you can generate Excel files from your data and templates fast and effortlessly.
Install Sheetah using npm:
npm install sheetah
First, obtain your API key from the Developer Settings Page. Then use the following code to initialize Sheetah:
const Sheetah = require("sheetah");
const API_KEY = "YOUR_API_KEY";
const sheetah = new Sheetah(API_KEY);
Follow these steps to export an Excel file using Sheetah:
Specify the template by using setTemplateId
method:
sheetah.setTemplateId(35);
Add tables with the setTables
method:
sheetah.setTables([
{
id: "table1",
columns: [
{ name: "Column 1", filter: false, totalFormula: "none" },
{ name: "Column 2", filter: true, totalFormula: "average" },
],
rows: [
["Row 1", "Data"],
["Row 2", "More Data"],
],
},
]);
Table settings must be completed on the Template Settings Page.
Use the setVariables
method to add dynamic data. This is useful for dynamic data insertion:
sheetah.setVariables({
user: "Dave",
email: "admin@example.com",
year: "2019",
month: "08",
});
Use the setSheets
method to add sheets:
sheetah.setSheets([
{
id: 1,
name: "Budget",
directData: {
A1: "This is cell A1 on Budget sheet",
},
},
{
id: 2,
name: "Expenses",
directData: {
B2: "This is cell B2 on Expenses sheet",
},
},
]);
With setOptions
you can specify filename, password, and expiration days:
sheetah.setOptions({
filename: "Survey Results",
password: "mypassword",
expireInDays: 7,
});
Export your file to a downloadable URL with exportExcelToFileUrl
method:
(async () => {
const result = await sheetah.exportExcelToFileUrl();
if (result.message === "success") {
console.log("Download URL:", result.fileUrl);
} else {
console.log("Download Failed:", result.message);
}
})();
Alternatively, you can also export the sheet and get it as a byte array using exportExcelToBuffer
method:
(async () => {
const result = await sheetah.exportExcelToBuffer();
if (result.buffer) {
// Do something with result.buffer
}
})();
Lastly, you can also save the exported sheet as a local file:
(async () => {
const result = await sheetah.exportExcelToFile("/path/to/file.xlsx");
if (result.file) {
console.log("Downloaded file =", result.file);
}
})();
Contributions are welcomed. If you are interested, please fork the repository and make your changes. A detailed description of your changes when making a PR is appreciated.
This project is licensed under the MIT License.
_Note: Don't forget to replace 'YOUR_API_KEY'
with your actual API key when using the library.