最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Not able to get proper Data in the excel file created using ExcelJS package in NodeJS - Stack Overflow

matteradmin5PV0评论

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 });
        }
      })
    );

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far