-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Image position - stretching image #467
Comments
I'm having a similar issue in where the
If I make Do you see the discrepancy here? |
I decided that maybe I could avoid this and pre-size my actual image first and use There seems to be something fundamentally broken in this function. |
Hi man. I know what you mean, I tried everything with this plugin but it didnt work. So I had to fork this package and fix it. Currently I'm not near PC but tomorrow I will write you how to use my modified version to make pictures scalable any way you want. |
Sounds good, perhaps we could make a PR with these fixes too? :) |
So as promised this is my fork of ExcelJS: https://github.com/Trynex/exceljs (TLDR starts here:) So basic example in original: But that stretches the wrong way as your cell width and height is not accounted for in calculation. So what you want to do here is to add specific position in the cell where these top left and bottom right corners will start in pixels. Example with my fix: Try to play with it little and ask if you need any help. |
@Trynex interesting way of going around this issue. |
One can also use the sharp image processing library to add a transparent (or white) background to an image and scale the image whilst retaining it's aspect ratio. Then, placing this square image into a square cell will display it with the correct aspect ratio. Maybe an image is a simpler way of explaining: The ratio between width an height in this library seems to be 0.14291498 (IDK why?). In other words, one can set col.width = 10 * 1.429149798 and row.height = 100 to get a square cell. Then, you can use the following sharp snippet to scale the image, preserving the aspect ratio and adding a white background to the image in the places where extra space is needed to keep the image square.
One could use this snippet to use a transparent background
Super duper hacky but I got a working solution for my use case. Whether or not this will help you depends on your use case. |
@Trynex: thanks for your fork. Now I can actually place images without or with only invisible stretch. Just a quick info for everyone: rowOff and colOff in the open xml specification is not in pixel but actually in EMUs which supposedly stands for English Metric Unit. Here's an article on the topic. @Trynex implemented it so that when you use his code 1 unit in rowOff and colOff is actually 10000 EMU The row height (as defined with For colOff the thing is even more complex since column with is in some fucked-up font dependend unit. In my case, I got good results with multiplying the cell width (as defined with So, Thanks Microsoft for making a "standard" thats so fucked up that you need to spend hours on just placing images. You could have at least used the same unit for x and y. |
I'm just wondering why @Trynex's fix isn't pulled into master. It's an actual bug that |
How to export excel ? workbook.xlsx.writeBuffer({ but i open excel file and crash, help pls |
@FelipeRobles92 It might be because you forgot to quote your file name
|
it just happens to me when export excel with image :( |
I can confirm. This issue is still there. Same problem as OP posted. |
@Trynex @jwmann @dmastag @kaidoj if You need this changes quicly, i have build branch in my repo: npm:
|
@Siemienik as soon as i get back to that project where i used exceljs, i will try out your fix and see if that fixes my problem. Ofc its better to have tests etc. I just did it to fix my issue fast without going too deep into execeljs code. Edit: I can now confirm that @Siemienik fix works for me too. |
@alubbe @guyonroche |
any one found reason of that? |
probably mess in installed dependencies. Can not reproduce it again |
So .. does the bug still exists or was it fixed? |
as for me, i cannot reproduce it again. So i'd say it's fixed |
@Trynex How to calculate coloff and rowoff and what is the unit of coloff and rowoff ? |
still not working and calculating rowOff & colOff is not clear |
Hello everyone. I have a problem with images using exceljs. If I just run excel file through and save it, images are immediately deformed (stretched). I tried workaround and so I just removed images from original excel file and inserted them with add image. Again stretched. So I tried not to specify cells for image to include, but also other(more specific option):
{tl: { col: 1.2, row: 0.4 }, br: { col: 3.2, row: 0.9 }}
This worked when row number was not decimal. Because the example above didn't scale the image
from 0.4 to 0.9 of the cell, but rather deformed it .. Which is weird as the image started the position on 0.4. This for example worked fine:
{tl: { col: 1.2, row: 0.4 }, br: { col: 3.2, row: 1 }}
but any decimal number in br->row does weird things.
I also tried to specify editAs attribute and all its options, but no luck there.
Am I doing something wrong or is it a bug? Is there any workaround where I can specify the place where I want to include image without stretching image?
Thank you for your help!
The text was updated successfully, but these errors were encountered: