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

AddPicture does not work properly when Copying Sheets with Images #1584

Closed
t4traw opened this issue Jul 21, 2023 · 2 comments
Closed

AddPicture does not work properly when Copying Sheets with Images #1584

t4traw opened this issue Jul 21, 2023 · 2 comments
Labels
confirmed This issue can be reproduced

Comments

@t4traw
Copy link

t4traw commented Jul 21, 2023

Description

I found a strange behavior with the AddPicture function after copying a sheet in Excelize. When I attempt to insert an image into the copied sheet using AddPicture, the function doesn't behave as expected if there is already an image inserted in a different sheet.

package main

import (
	_ "image/png"

	"github.com/xuri/excelize/v2"
)

func main() {
	xlsx, _ := excelize.OpenFile("./Book1.xlsx")

	templateSheetName := "Sheet2"
	templateSheetIndex, _ := xlsx.GetSheetIndex(templateSheetName)

	Copied1, _ := xlsx.NewSheet("Copied1")
	_ = xlsx.CopySheet(templateSheetIndex, Copied1)
	Copied2, _ := xlsx.NewSheet("Copied2")
	_ = xlsx.CopySheet(templateSheetIndex, Copied2)

	photoPotisions, _ := xlsx.SearchSheet(templateSheetName, "photo")

	xlsx.AddPicture("Copied1", photoPotisions[0], "./a.png", &excelize.GraphicOptions{})
	xlsx.AddPicture("Copied2", photoPotisions[0], "./b.png", &excelize.GraphicOptions{})

	xlsx.SaveAs("./output.xlsx")
}

I executed this code without making any changes. Here are the generated .xlsx files:

  1. This is the .xlsx file created when there is no image inserted in Sheet1.
    2023-07-21_191430
  2. This is the .xlsx file created when an image is inserted in Sheet1.
    2023-07-21_191637

I have pushed the sample code to the repository.

https://github.com/t4traw/addpicture_duplicate

Output of go version:

go version go1.19 darwin/arm64

Excelize version or commit ID:

v2.7.2-0.20230522012428-c2327484006e

Environment details (OS, Microsoft Excel™ version, physical, etc.):

  • OS: macOS 13.3.1
  • Excel: 16.72
@xuri xuri added confirmed This issue can be reproduced in progress Working in progress labels Jul 23, 2023
@xuri xuri closed this as completed in 7f3d663 Jul 24, 2023
@xuri
Copy link
Member

xuri commented Jul 24, 2023

Thanks for your issue. I have fixed this issue, please try to upgrade the master branch code, and this patch will be released in the next version.

@xuri xuri removed the in progress Working in progress label Jul 24, 2023
@t4traw
Copy link
Author

t4traw commented Jul 25, 2023

It worked perfectly with my own code too! Superb! Thank you for this cool library!

jenbonzhang pushed a commit to jenbonzhang/excelize that referenced this issue Oct 22, 2023
- Optimize number format parser
- Update documentation for the `AddFormControl` function
- Update unit tests
- Upgrade dependencies package
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed This issue can be reproduced
Projects
None yet
Development

No branches or pull requests

2 participants