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

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

Been asked ages ago, but for anyone stumbling on this — you can increase the height of the row like this (add right before the order.products.map(...) loop). Note that this will increase the height for all the rows.
worksheet.properties.defaultRowHeight = 20 // Increase this value to increase row height
You can also configure the image size when adding it. Just pass the ext option and give it an object with width and height properties (tl for placement, editAs for cell behavior):
worksheet.addImage(imageID, {
tl: { col: colNum, row: rowNum },
ext: { width: 150, height: 100 },
editAs: 'oneCell'
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With