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.

Image location don't respect Column width

See original GitHub issue

I set custom column width while defining sheet columns. When adding an image using coordinate (50% column to use), the image don’t respect my custom width.

Additional explanation: https://github.com/exceljs/exceljs/issues/650#issuecomment-645887635

Code :

      sheet.columns = [
          { header: 'Id', key: 'id', width: 10 },
          { header: 'Name', key: 'name', width: 32 },
      ];

      var imageId2 = workbook.addImage({
        base64: myBase64Image,
        extension: 'png',
      });

      sheet.getColumn(4).width = 38;
      // sheet.addImage(imageId2, 'B2:D6');
      sheet.addImage(imageId2, {
                          tl: { col: 1, row: 1 },
                          br: { col: 1.5, row: 4 }
                        });

      sheet.addImage(imageId2, {
                          tl: { col: 3, row: 1 },
                          br: { col: 3.5, row: 4 }
                        });


      workbook.xlsx.writeBuffer({
                  base64: true
              })
      .then(function(xls64) {
          // done
          var data = new Blob([xls64], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" });
          saveAs(data, "output.xlsx");
      });

Actual result :

image

Expected result:

image

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:1
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
ShraddhaJ11commented, May 27, 2020

Hi @Siemienik Still facing image alignment issue with custom column width.

1reaction
ShraddhaJ11commented, Jun 18, 2020

First I am reading a excel file and then I am only adding the image on a particular cell. If width of the column for that cell is default column width then image alignment is working fine using col and row but If the excel file that I am reading, have custom column width then adding image to a cell that has custom width , in that right image alignment is not working.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Img doesn't respect width in html (with flexbox) - Stack Overflow
You want to set the dimensions of your container, then have the image inside expand to fill it. I'd reshuffle it like this:...
Read more >
C37: Using CSS max-width and height to fit images | WAI - W3C
This is done by using CSS max-width and height property techniques that adapt to the available space and keep the original dimensions of...
Read more >
table-layout - CSS: Cascading Style Sheets - MDN Web Docs
Table and column widths are set by the widths of table and col elements or by the width of the first row of...
Read more >
Preventing a Grid Blowout | CSS-Tricks
To apply our fix, we need to make sure that there is the column has a definite minimum width instead of auto ....
Read more >
HTML Tag: Change The Width Of A Picture In HTML »
If you specify the width, it may be much too small for some users and much too big for others. Most of the...
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