-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Adding Picture into a merged cell is unable to adjust the alignment in the cell #1958
Comments
Thanks for your issue. This library support gets the cell images inserted by IMAGE formula function by PR #1857, the f.AddPicture("Sheet1", "A1", "image.png",
&excelize.GraphicOptions{
AutoFit: true,
LockAspectRatio: true,
+ OffsetX: 10,
}) You can calculate offset value by merged cell range width and image width, the width of merged cell range can be got by cumulate width of each column width, get each column width by |
Could you show us a complete, standalone example program or reproducible demo? Please provide the image file attachment if you can. |
Here's the code:
|
Thanks for your feedback. I think insert to the middle column of the merged cells column, and change image scale in your case would be more works, it should be like this: f.AddPicture("Sheet1", "B1", "IMAGE.png", &excelize.GraphicOptions{
OffsetX: 5,
ScaleX: 0.135,
ScaleY: 0.135,
}) |
Description
I tried to insert a picture into a merged cell and I wanted to align the picture with the cell as "center".
Steps to reproduce the issue:
if err := f.MergeCell("Sheet1", "A1", "C6"); err != nil { ...... }
if err := f.AddPicture("Sheet1", "A1", "image.png", &excelize.GraphicOptions{ AutoFit: true, LockAspectRatio: true, }); err != nil { ...... }
centralStyle, err := f.NewStyle(&excelize.Style{ Alignment: &excelize.Alignment{ Horizontal: "center", Vertical: "center", }, }) if err != nil { ...... }
Describe the results you received:
The outcome picture in the cell is still align left not center.
I read the source code in github and found that there's a const
PictureInsertType
to control the picture insert type, but I got error withFunctional\excelize.go:163:4: unknown field InsertType in struct literal of type excelize.Picture Functional\excelize.go:163:16: undefined: PictureInsertTypePlaceInCell
.And the code I used for trying to involve the PictureInsertType.
if err := f.AddPictureFromBytes("Sheet1", "A1", &excelize.Picture{Extension: ".png", File: file, Format: &excelize.GraphicOptions{AutoFit: true}, PictureInsertType: PictureInsertTypePlaceInCell}); err != nil { ...... }
Describe the results you expected:
I found out that the picture insert type is "insert over cell" with the "AddPicture" function.
I'd like to know in which way can I configure the picture's alignment type or the picture insert type as "add picture into cell".
Output of
go version
:Excelize version or commit ID:
Environment details (OS, Microsoft Excel™ version, physical, etc.):
The text was updated successfully, but these errors were encountered: