This closes #1628, fix the GetPictures function returns pictures doesn't correct in some cases

This commit is contained in:
xuri 2023-08-25 01:06:41 +08:00
parent db22452398
commit 15614badfc
No known key found for this signature in database
GPG Key ID: BA5E5BB1C948EDF7
2 changed files with 10 additions and 3 deletions

View File

@ -649,9 +649,7 @@ func (f *File) getPicture(row, col int, drawingXML, drawingRelationships string)
if wsDr, _, err = f.drawingParser(drawingXML); err != nil {
return
}
if pics = f.getPicturesFromWsDr(row, col, drawingRelationships, wsDr); len(pics) > 0 {
return
}
pics = f.getPicturesFromWsDr(row, col, drawingRelationships, wsDr)
deWsDr = new(decodeWsDr)
if err = f.xmlNewDecoder(bytes.NewReader(namespaceStrictToTransitional(f.readXML(drawingXML)))).
Decode(deWsDr); err != nil && err != io.EOF {

View File

@ -70,6 +70,15 @@ func TestAddPicture(t *testing.T) {
assert.NoError(t, f.SaveAs(filepath.Join("test", "TestAddPicture1.xlsx")))
assert.NoError(t, f.Close())
// Test get pictures after inserting a new picture from a workbook which contains existing pictures
f, err = OpenFile(filepath.Join("test", "TestAddPicture1.xlsx"))
assert.NoError(t, err)
assert.NoError(t, f.AddPicture("Sheet1", "A30", filepath.Join("test", "images", "excel.jpg"), nil))
pics, err := f.GetPictures("Sheet1", "A30")
assert.NoError(t, err)
assert.Len(t, pics, 2)
assert.NoError(t, f.Close())
// Test add picture with unsupported charset content types
f = NewFile()
f.ContentTypes = nil