Aug 28, 2024 12:30 AM - edited Aug 28, 2024 12:31 AM
Hi!
I am working on a small script thats generate a XLSX file from an airtable base.
I stucked at when I want to download a file. Is there any solution to download from the extension section and not from an attachment field?
Thank you for any help!
Aug 28, 2024 10:59 AM
If you are using the scripting block in Airtable, you can create a downloadable link for your generated file. Here’s an example of how you can do this using Javascript:
Aug 28, 2024 10:59 AM
Here is a basic example:
// Load the required library (e.g., xlsx)
const XLSX = require('xlsx');
// Create a new workbook and worksheet
const workbook = XLSX.utils.book_new();
const worksheet = XLSX.utils.json_to_sheet([
{ Name: 'John Doe', Age: 30 },
{ Name: 'Jane Smith', Age: 25 }
]);
XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');
// Convert the workbook to binary
const wbout = XLSX.write(workbook, { bookType: 'xlsx', type: 'binary' });
// Convert binary string to an ArrayBuffer
function s2ab(s) {
const buf = new ArrayBuffer(s.length);
const view = new Uint8Array(buf);
for (let i = 0; i < s.length; i++) view[i] = s.charCodeAt(i) & 0xFF;
return buf;
}
// Create a blob from the ArrayBuffer
const blob = new Blob([s2ab(wbout)], { type: 'application/octet-stream' });
// Create a link element
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = 'example.xlsx'; // Name of the file to be downloaded
// Append the link to the document
document.body.appendChild(link);
// Programmatically click the link to trigger the download
link.click();
// Remove the link from the document
document.body.removeChild(link);
Aug 28, 2024 11:00 AM
If you are looking to host the file externally and provide a download link in Airtable:
If you want to leverage Airtable’s built-in extensions (like the Page Designer or others):
Aug 28, 2024 11:35 PM
Hello @balazs_farsang
This is not possible to directly generate Excel or any downloadable file using an Airtable Script extension.
You can just manually download it as csv using visual UI. OR you can push data to another platform using API and automation. See this for download as CSV https://community.airtable.com/t5/development-apis/how-to-export-table-into-mysql-table-file-or-csv/...
The suggestions from @Saravanan_009 are directly from AI(GPT, or other) responses. Airtable scripts are not allowed to import any external modules. https://chatgpt.com/share/2af8ce7b-6451-47b7-805f-cda61dcf0393
The last response is also not work. Just gives you an error at the end.
A possible solution is just to download it as csv using different views and filters OR create a script that just shows data in a comma-separated or a Table.
@Saravanan_009 It's good to use AI response please cross-check it first.