Skip to content
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

Add Picture constrains the picture to too few cols and rows #212

Open
BeMoreDog opened this issue Apr 17, 2018 · 3 comments
Open

Add Picture constrains the picture to too few cols and rows #212

BeMoreDog opened this issue Apr 17, 2018 · 3 comments
Labels
enhancement New feature or request

Comments

@BeMoreDog
Copy link

Description

When I add an image to an existing spreadsheet (a png in my case) whose size perfectly matches the size (in cm) of the area in which I want it to display, it gets displayed scaled/displayed incorrectly (too small).

I think the calculation for to.col & to.row calculated in positionObjectPixels is somehow going wrong when using the col/row dimensions or image dimensions.
I also think that if there was an option to use <xdr:oneCellAnchor> see here it may fix the image display by avoiding having to do the calculations.

Steps to reproduce the issue:

  1. Create an existing 'template' spreadsheet in excel with the first 8 column widths sized as follows (to hold the image): a=1.38cm, b=19.39, c=1.14, d=1.11, e=1.11, f=1.11, g=2.94, h=4.42 (total 31.6cm) / or as Excel prefers to measure them A=6.29, B=98.86, c=5.14, d=5, e=5, f=5, g=14.43, h=22
  2. Use func (*File) AddPicture ...with the aspect ratio locked, no offset, no link and scaling set to 1 (I have also tried without these) to insert a png of size 10.64cm high and 30.96 wide

Describe the results you received:

  • The image is inserted constrained to the width of 3 cols (a, b, c).
  • It's aspect ratio is wrong.
  • In Excel, going to the image size properties and choosing 'Reset' scales it as it should be (to 100% scale and col H)

Describe the results you expected:

  • The image is inserted constrained within the width of 8 cols (a, b, c, d, e, f, g, h).
  • It's aspect ratio should be maintained.
  • In Excel, going to the image size properties should show it scaled to 100%

Output of go version:

go1.10

Excelize version or commit ID:

1.2.0

Environment details (OS, Microsoft Excel™ version, physical, etc.):
OS. Win 10 & MacOS 10.13, physical, Excel 1708 & earlier

@xuri xuri added the enhancement New feature or request label Apr 18, 2018
@xuri
Copy link
Member

xuri commented Apr 18, 2018

Thanks for your issue. I will consider adding and using oneCellAnchor support when no offset, no link and scaling set.

@BeMoreDog
Copy link
Author

Thanks, do you think this (<xdr:oneCellAnchor>) is the only way to get the image to display at it's intended size?
Do you have any idea why the to.col & to.row calculated in positionObjectPixels is somehow going wrong for the existing <xdr:twoCellAnchor> implementation? I had a look but couldn't see anything obvious.

I've attached a sample case to illustrate the issue Excelizeissue212.zip

@xuri
Copy link
Member

xuri commented Apr 20, 2018

Excel use EMUs (English Metric Units) to measure image offset and used to determine the location of the picture, this value is affected by different screen resolutions and can‘t be accurately calculated, so if the generated image size doesn't meet expectations, you need to set the offset manually. Reference English Metric Units and Open XML.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants