admin管理员组文章数量:1023782
so i trying to create a xlx file from the input and upload it to S3 bucket so when i pass large data say 1000 rows I could see that only column headers are created in the file not the data but still the file size is around 100kb but if i send small input i could see the rows getting created
any help is much appreciated attaching the snippet of the code where i am trying to create xlsx file
await Promise.all(
payload.queryResults.map(async (queryResult: QueryResult) => {
const { columnHeader, strId, queryName, data = [] } = queryResult;
try {
// Process the Excel file
const workbook = new ExcelJS.Workbook();
const worksheet = workbook.addWorksheet('Sheet1');
worksheet.addRow(columnHeader);
// Add data rows only if `data` is a non-empty array
if (Array.isArray(data) && data.length > 0) {
data.forEach((row) => {
const rowData = columnHeader.map(col => row[col] || '');
worksheet.addRow(rowData);
});
}
const filePath = filename.xlsx`;
const buffer = await workbook.xlsx.writeBuffer();
await uploadFiletoS3(stagingBucket, filePath, Buffer.from(buffer));
successfulQueries.push({ queryName, strId });
} catch (uploadError) {
failedQueries.push({ queryName, strId, error: uploadError.message });
logger.error(`Error uploading file for query: ${queryName} for store: ${strId}`, { error: uploadError });
}
})
);
so i trying to create a xlx file from the input and upload it to S3 bucket so when i pass large data say 1000 rows I could see that only column headers are created in the file not the data but still the file size is around 100kb but if i send small input i could see the rows getting created
any help is much appreciated attaching the snippet of the code where i am trying to create xlsx file
await Promise.all(
payload.queryResults.map(async (queryResult: QueryResult) => {
const { columnHeader, strId, queryName, data = [] } = queryResult;
try {
// Process the Excel file
const workbook = new ExcelJS.Workbook();
const worksheet = workbook.addWorksheet('Sheet1');
worksheet.addRow(columnHeader);
// Add data rows only if `data` is a non-empty array
if (Array.isArray(data) && data.length > 0) {
data.forEach((row) => {
const rowData = columnHeader.map(col => row[col] || '');
worksheet.addRow(rowData);
});
}
const filePath = filename.xlsx`;
const buffer = await workbook.xlsx.writeBuffer();
await uploadFiletoS3(stagingBucket, filePath, Buffer.from(buffer));
successfulQueries.push({ queryName, strId });
} catch (uploadError) {
failedQueries.push({ queryName, strId, error: uploadError.message });
logger.error(`Error uploading file for query: ${queryName} for store: ${strId}`, { error: uploadError });
}
})
);
本文标签:
版权声明:本文标题:javascript - Not able to get proper Data in the excel file created using ExcelJS package in NodeJS - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745603776a2158610.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论