question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to insert image FIT inside a cell ?

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

12reactions
Alanscutcommented, Jan 7, 2020

See the example of add image to a cell.

worksheet.addImage(imageId2, {
  tl: { col: 0, row: 0 },
  ext: { width: 500, height: 200 }
});
6reactions
Knight-Hcommented, Jul 29, 2021

Not sure if you still need this, but what I did was using the same cellId fits inside the cell. I think this works because the same cell is used for the top left (tl) and the bottom right (br).

sheet.addImage(imageId, `${cellId}:${cellId}`)

Example:

sheet.addImage(imageId, `J13:J13`)
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to insert picture in Excel cell, comment, header and footer
In the Insert Picture dialog that opens, browse to the picture of interest, select it, and click Insert. This will place the picture...
Read more >
How to Insert Picture Into a Cell in Excel (a Step-by-Step ...
Go to the Insert tab. · Click on the Pictures option (it's in the illustrations group). · In the 'Insert Picture' dialog box,...
Read more >
Insert Pictures in Excel Automatically Size to Fit Cells
From Format Picture >> select Size & Properties >> then select Properties. Mark on the option Move and size with cells.
Read more >
How can I fit a picture in a cell in Microsoft Excel? - Quora
Click on the Insert tab · Insert picture · Resize the cells according to the picture · Right-click on the picture · Format...
Read more >
How to resize pictures to fit cells in Excel? - ExtendOffice
Resize a selected picture to fit a single cell with VB Macro ; Resize inserted pictures to fit cells with Kutools for Excel...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found