Skip to content

If you insert into two or more images of multiple sheets, the images will be pasted in duplicate. #373

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

Closed
GinSanaduki opened this issue Mar 27, 2019 · 7 comments
Labels
bug Something isn't working

Comments

@GinSanaduki
Copy link

GinSanaduki commented Mar 27, 2019

Create a new Excel file, insert an image into one cell of one sheet, create another sheet, insert another image into one cell of another sheet, as the result, causes a event that pasted two images on both cells of both sheets.
It doesn't occur when you finish inserted an image into one cell of a sheet, or inserted images into two or more cells of the same sheet.

func main () {
    xlsx: = excelize.NewFile ()
    // Create a worksheet
    index: = xlsx.NewSheet ("Sheet2")
    // Insert image1.jpg into A2 cell of sheet 1
    // Still okay at this point
    err: = xlsx.AddPicture ("Sheet1", "A2", "./image1.jpg", "")
    if err! = nil {
        fmt.Println (err)
        return err
    }
    // Insert image2.jpg into A20 cell of sheet 2
    // If this is executed, image1.jpg is pasted A2 cells of Sheet 1 and Sheet 2 
    // and image2.jpg is pasted A20 cells of Sheet 1 and Sheet 2.
    err: = xlsx.AddPicture ("Sheet2", "A20", "./image2.jpg", "")
    if err! = nil {
        fmt.Println (err)
        return err
    }
   // Save Excel
   err: = xlsx.SaveAs ("./Book1.xlsx")
   if err! = nil {
        fmt.Println (err)
        return err
    }
    return nil
}

When I extracted the Excel file and saw it, the value of the name held inside of drawing1.xml was the same (Picture 1), so it is considered to be due to that.
If SaveAS is executed first and then reopened and the image is executed only after Save is executed, the stored information will disappear or it will operate normally.
Of course, there is no problem if you insert image1.jpg into one cell of one sheet, execute SaveAS, reopen it, and insert image2.jpg into another cell of another sheet.

func main () {
    xlsx: = excelize.NewFile ()
    // Create a worksheet
    index: = xlsx.NewSheet ("Sheet2")
    // Save Excel
    err: = xlsx.SaveAs ("./Book1.xlsx")
    if err! = nil {
        fmt.Println (err)
        return err
    }
    // Reopen
    xlsx, err: = excelize.OpenFile ("./Book1.xlsx")
    if err! = nil {
         fmt.Println (err)
         return err
    }
    // Insert image1.jpg into A2 cell of sheet 1
    err: = xlsx.AddPicture ("Sheet1", "A2", "./image1.jpg", "")
    if err! = nil {
        fmt.Println (err)
        return err
    }
    // Save Excel
    err: = xlsx.Save ()
    if err! = nil {
        fmt.Println (err)
        return err
    }
    // Insert image2.jpg into A20 cell of sheet 2
    err: = xlsx.AddPicture ("Sheet2", "A20", "./image2.jpg", "")
    if err! = nil {
        fmt.Println (err)
        return err
    }
    // Save Excel
    err: = xlsx.Save ()
    if err! = nil {
        fmt.Println (err)
        return err
    }
    return nil
}

When this is executed, Book1.xlsx is generated in which image1.jpg is inserted into only A2 cell of sheet 1 and image2.jpg is inserted into only A20 cell of sheet 2.

@GinSanaduki GinSanaduki changed the title If you paste two or more images on multiple sheets, the images will be pasted in duplicate. If you insert into two or more images of multiple sheets, the images will be pasted in duplicate. Mar 27, 2019
@xuri
Copy link
Member

xuri commented Mar 29, 2019

Hi @GinSanaduki, thanks for your issue. I have tested based on your code and it works well. Which version of Excelize and Go are you using?

@xuri xuri added the needs more info This issue can't reproduce, need more info label Mar 29, 2019
@GinSanaduki
Copy link
Author

Hi @GinSanaduki, thanks for your issue. I have tested based on your code and it works well. Which version of Excelize and Go are you using?

Hi @xuri , thanks for the reply.
The excelize library, which I downloaded March 21, 2019, is one version before the latest commit.
When I tried with 2 windows 10, the same phenomenon occurred.
go version go1.12.1 windows/amd64
I know what to do here for the time being, so if you don't reproduce it, let me wait and see please.
Thank you for confirmation.

@nateglims
Copy link

I see something similar with comments on 69b38ddcd6:

package main

import "github.com/360EntSecGroup-Skylar/excelize"

func main() {
	xlsx := excelize.NewFile()
	xlsx.NewSheet("Sheet2")

	err := xlsx.AddComment("Sheet1", "A1", `{"author":"Me:","text":"Comment"}`)
	if err != nil {
		panic(err)
	}

	err = xlsx.AddComment("Sheet2", "A2", `{"author":"Me:","text":"Comment"}`)
	if err != nil {
		panic(err)
	}

	err = xlsx.SaveAs("./Test.xlsx")
	if err != nil {
		panic(err)
	}
}

Sheet1:
image

Sheet2:
image

@GinSanaduki
Copy link
Author

I did not know that the same event would occur even with the addition of comments...thank you for providing the information.

@xuri xuri added bug Something isn't working confirmed This issue can be reproduced and removed needs more info This issue can't reproduce, need more info labels May 11, 2019
@xuri xuri closed this as completed in 25763ba May 11, 2019
@xuri
Copy link
Member

xuri commented May 11, 2019

Hi @nateglims @GinSanaduki, I have fixed it, but the issues of duplicate images haven't been confirmed yet.

@GinSanaduki
Copy link
Author

Just in case, I put the reproduction file of those days.
Book1.xlsx

evi01

evi02

@GinSanaduki
Copy link
Author

GinSanaduki commented May 11, 2019

It did not occur with modified sources.
This problem does not occur with current sources.
Thank you very much.

Book1.xlsx
evi04
evi03

nullfy pushed a commit to nullfy/excelize that referenced this issue Oct 23, 2020
@xuri xuri removed the confirmed This issue can be reproduced label Nov 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants