How to Insert Image using ExcelJs into a cell

Viewed 5440

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

0 Answers
Related