Thanks for the great package. I want to insert image inside a cell. Currently, I'm using fixed width and height, but have no idea how to make image size fit inside a cell. How can I do that with exceljs ? Thanks in advance !
I want to
const tmpWorkBook = new ExcelJS.Workbook();
tmpWorkBook.xlsx.readFile(filePath)
.then(function() {
const worksheet = tmpWorkBook.getWorksheet("Sheet1");
var imageID = tmpWorkBook.addImage({
filename: imagePath,
extension: 'png',
});
console.log("imageID", imageID);
const relCol = cell.columnNumber() - 1;
const relNum = cell.rowNumber() - 1;
worksheet.addImage(imageID, {
tl: { col: relCol, row: relNum },
ext: { width: 100, height: 50 } // currently I'm using fixed width and height.
});
tmpWorkBook.xlsx.writeFile(outputPath);
});
I noticed that I can insert image fit inside a range but wonder how I can do that with cell?
worksheet.addImage(imageId2, 'B2:D6');
See the example of add image to a cell.
worksheet.addImage(imageId2, {
tl: { col: 0, row: 0 },
ext: { width: 500, height: 200 }
});
Thanks for opening this request.
Please re-open if you still have issues.
Best of luck.
See the example of add image to a cell.
worksheet.addImage(imageId2, { tl: { col: 0, row: 0 }, ext: { width: 500, height: 200 } });
It doesn't fit cell