5

I'm trying to add an image to a specific cell, is there any way I can adjust the image size or the cell size so it can fit on the cell.?

    result.map(order => {
      const worksheet = workbook.addWorksheet(order.branch_code);

      worksheet.columns = [
        { header: 'Id', key: 'id', width: 10 },
        { header: 'Product Code', key: 'pcode', width: 20 },
        { header: 'Image', key: 'image', width: 50 },
      ];

      order.products.map(product => {
        const imageId = workbook.addImage({
          filename: `${PRODUCT_IMAGE_PATH}/${product.image}`,
          extension: 'jpeg',
        });

        worksheet.addRow({ id: product.products.id, pcode: product.products.product_code });
        worksheet.addImage(imageId, `C${position}:C${position}`);
        position++;
      });
    });

    await workbook.xlsx.writeFile('export.xlsx');

enter image description here

but it looks like this, how can i fix this.?

expected OP:

enter image description here

Thorin
  • 131
  • 1
  • 2
  • 9
  • What exactly is the problem? Is the image not full width&height? – Gilles Heinesch Apr 06 '21 at 09:18
  • 4
    @GillesHeinesch I actually managed to insert the image correctly, I'm doing it like this, `worksheet.addImage(imageId, { tl: { col: 8.1, row: rowPos++ }, ext: { width: 140,height: 90 }});` Right now I'm facing an issue with adding a new row at the end after the loop is finished.? if you have experience in `exceljs` could you help me out a bit.? – Thorin Apr 06 '21 at 13:00
  • 3
    Perfect could you please add your answer to the question so everyone who has the same problem can see how you figured it out? Could you please create a new question for this issue and just tag me in the comments. I will give my best to help you then. :-) @Thorin – Gilles Heinesch Apr 06 '21 at 13:26

0 Answers0