Can i send a file from trcp router?

I want to send a xlxs/csv file to FE (expo). Can i do this like expressJs? or do i need to first uplaod to s3 then give it's uploaded URL?
1 Reply
albatroz
albatrozOP2y ago
const workbook = XLSX.utils.book_new();

for (const tableName in data) {
if (Array.isArray(data[tableName])) {
const sheetName = tableName;
const sheetData = data[tableName];

if (sheetData && sheetData.length > 0) {
const worksheet = XLSX.utils.json_to_sheet(sheetData);

const headers = Object.keys(sheetData[0]);
XLSX.utils.sheet_add_aoa(worksheet, [headers], { origin: "A1" });

for (let i = 0; i < sheetData.length; i++) {
const createdAt = sheetData[i].createdAt;
if (createdAt) {
sheetData[i].createdAt = new Date(createdAt).toLocaleString();
}
}

XLSX.utils.sheet_add_json(worksheet, sheetData, { skipHeader: true, origin: "A2" });

XLSX.utils.book_append_sheet(workbook, worksheet, sheetName);
}
}
}

const excelFilePath = "output.xlsx";
XLSX.writeFile(workbook, excelFilePath);
const workbook = XLSX.utils.book_new();

for (const tableName in data) {
if (Array.isArray(data[tableName])) {
const sheetName = tableName;
const sheetData = data[tableName];

if (sheetData && sheetData.length > 0) {
const worksheet = XLSX.utils.json_to_sheet(sheetData);

const headers = Object.keys(sheetData[0]);
XLSX.utils.sheet_add_aoa(worksheet, [headers], { origin: "A1" });

for (let i = 0; i < sheetData.length; i++) {
const createdAt = sheetData[i].createdAt;
if (createdAt) {
sheetData[i].createdAt = new Date(createdAt).toLocaleString();
}
}

XLSX.utils.sheet_add_json(worksheet, sheetData, { skipHeader: true, origin: "A2" });

XLSX.utils.book_append_sheet(workbook, worksheet, sheetName);
}
}
}

const excelFilePath = "output.xlsx";
XLSX.writeFile(workbook, excelFilePath);
Want results from more Discord servers?
Add your server