Closed
Description
Code to reproduce the issue
package main
import (
_ "image/jpeg"
"os"
"path/filepath"
"github.com/xuri/excelize/v2"
)
func addPictureToA1WithOffset(f *excelize.File, data []byte, ext string, offset int) error {
enable := true
disable := false
if err := f.AddPictureFromBytes("Sheet1", "A1", &excelize.Picture{Extension: ext, File: data, Format: &excelize.GraphicOptions{
PrintObject: &enable,
Locked: &disable,
ScaleX: 1,
ScaleY: 1,
OffsetX: offset,
Positioning: "oneCell",
}}); err != nil {
panic(err)
}
return nil
}
func main() {
f := excelize.NewFile()
defer func() {
if err := f.Close(); err != nil {
panic(err)
}
}()
f.SetColWidth("Sheet1", "A", "H", 20)
imagePath := "./pic.jpg" // pixel 60*60
ext := ".jpg"
data, _ := os.ReadFile(filepath.Clean(imagePath))
addPictureToA1WithOffset(f, data, ext, 0)
addPictureToA1WithOffset(f, data, ext, 60)
addPictureToA1WithOffset(f, data, ext, 120)
addPictureToA1WithOffset(f, data, ext, 180)
if err := f.SaveAs("result.xlsx"); err != nil {
panic(err)
}
}
Description
In the code example below, I try to add 4 60x60 sized pictures into cell A1, I'm expecting the pictures to maintain the size of 60x60 and be arranged horizontally end to end.
But there are two problems occur.
- The size of the pictures is incorrect, the first and second picture size is 90x100, while the third picture size is 112x100.
- The fourth picture is invisible.

The fourth picture is misplaced and I believe it's a bug. As the debug screenshot show below, in method addDrawingPicture, from.Col is equal to to.Col while from.ColOff(1714500) is larger than to.ColOff(895350).

Output of go version:
go version go1.20.6 linux/amd64
Excelize version or commit ID:
commit ID: 41c7dd30ce7e
go.sum: github.com/xuri/excelize/v2 v2.8.2-0.20240921073936-41c7dd30ce7e h1:9UoqZmYeb3ZN7rj3PEdm1rfP9dSPMwGfbaFyt+idd5E=
Environment details (OS, Microsoft Excel™ version, physical, etc.):
Linux
Metadata
Metadata
Assignees
Labels
No labels