This closes #1560, fix incorrect row number when get object position

This commit is contained in:
xuri 2023-06-12 00:09:40 +08:00
parent 78c974d855
commit 8e891b52c6
No known key found for this signature in database
GPG Key ID: BA5E5BB1C948EDF7
2 changed files with 5 additions and 5 deletions

8
col.go
View File

@ -605,14 +605,14 @@ func flatCols(col xlsxCol, cols []xlsxCol, replacer func(fc, c xlsxCol) xlsxCol)
// height # Height of object frame. // height # Height of object frame.
func (f *File) positionObjectPixels(sheet string, col, row, x1, y1, width, height int) (int, int, int, int, int, int) { func (f *File) positionObjectPixels(sheet string, col, row, x1, y1, width, height int) (int, int, int, int, int, int) {
// Adjust start column for offsets that are greater than the col width. // Adjust start column for offsets that are greater than the col width.
for x1 >= f.getColWidth(sheet, col) { for x1 >= f.getColWidth(sheet, col+1) {
x1 -= f.getColWidth(sheet, col) x1 -= f.getColWidth(sheet, col+1)
col++ col++
} }
// Adjust start row for offsets that are greater than the row height. // Adjust start row for offsets that are greater than the row height.
for y1 >= f.getRowHeight(sheet, row) { for y1 >= f.getRowHeight(sheet, row+1) {
y1 -= f.getRowHeight(sheet, row) y1 -= f.getRowHeight(sheet, row+1)
row++ row++
} }

View File

@ -108,7 +108,7 @@ func TestAddPictureErrors(t *testing.T) {
assert.NoError(t, f.AddPicture("Sheet1", "Q7", filepath.Join("test", "images", "excel.wmf"), nil)) assert.NoError(t, f.AddPicture("Sheet1", "Q7", filepath.Join("test", "images", "excel.wmf"), nil))
assert.NoError(t, f.AddPicture("Sheet1", "Q13", filepath.Join("test", "images", "excel.emz"), nil)) assert.NoError(t, f.AddPicture("Sheet1", "Q13", filepath.Join("test", "images", "excel.emz"), nil))
assert.NoError(t, f.AddPicture("Sheet1", "Q19", filepath.Join("test", "images", "excel.wmz"), nil)) assert.NoError(t, f.AddPicture("Sheet1", "Q19", filepath.Join("test", "images", "excel.wmz"), nil))
assert.NoError(t, f.AddPicture("Sheet1", "Q25", "excelize.svg", &GraphicOptions{ScaleX: 2.1})) assert.NoError(t, f.AddPicture("Sheet1", "Q25", "excelize.svg", &GraphicOptions{ScaleX: 2.8}))
assert.NoError(t, f.SaveAs(filepath.Join("test", "TestAddPicture2.xlsx"))) assert.NoError(t, f.SaveAs(filepath.Join("test", "TestAddPicture2.xlsx")))
assert.NoError(t, f.Close()) assert.NoError(t, f.Close())
} }