@@ -500,6 +500,11 @@ func TestGetCellImages(t *testing.T) {
500500 })
501501 return f
502502 }
503+ addStructure := func (f * File ) * File {
504+ f .Pkg .Store (defaultXMLRdRichValueStructurePart , []byte (`<rvStructures xmlns="http://schemas.microsoft.com/office/spreadsheetml/2017/richdata" count="1">
505+ <s t="_localImage"><k n="_rvRel:LocalImageIdentifier" t="i"/><k n="CalcOrigin" t="i"/><k n="Text" t="s"/></s></rvStructures>` ))
506+ return f
507+ }
503508 f = prepareWorkbook ()
504509 pics , err := f .GetPictures ("Sheet1" , "A1" )
505510 assert .NoError (t , err )
@@ -509,6 +514,17 @@ func TestGetCellImages(t *testing.T) {
509514 assert .NoError (t , err )
510515 assert .Equal (t , []string {"A1" }, cells )
511516
517+ f = addStructure (prepareWorkbook ())
518+ // Test get the cell images with rich value struct
519+ pics , err = f .GetPictures ("Sheet1" , "A1" )
520+ assert .NoError (t , err )
521+ assert .Equal (t , 1 , len (pics ))
522+ assert .Equal (t , PictureInsertTypePlaceInCell , pics [0 ].InsertType )
523+ cells , err = f .GetPictureCells ("Sheet1" )
524+ assert .NoError (t , err )
525+ assert .Equal (t , []string {"A1" }, cells )
526+
527+ f = prepareWorkbook ()
512528 // Test get the cell images without image relationships parts
513529 f .Relationships .Delete (defaultXMLRdRichValueRelRels )
514530 f .Pkg .Store (defaultXMLRdRichValueRelRels , []byte (fmt .Sprintf (`<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="%s" Target="../media/image1.png"/></Relationships>` , SourceRelationshipHyperLink )))
@@ -605,6 +621,18 @@ func TestGetCellImages(t *testing.T) {
605621 f .Pkg .Store (defaultXMLRdRichValuePart , []byte (`<rvData count="1"><rv s="1"><v></v><v>1</v><v>0</v><v>0</v></rv></rvData>` ))
606622 _ , err = f .GetPictures ("Sheet1" , "A1" )
607623 assert .EqualError (t , err , "strconv.Atoi: parsing \" \" : invalid syntax" )
624+
625+ f = addStructure (prepareWorkbook ())
626+ // Test get the cell images with no valid definition and fallback old-style
627+ f .Pkg .Store (defaultXMLRdRichValueStructurePart , []byte (`<rvStructures xmlns="http://schemas.microsoft.com/office/spreadsheetml/2017/richdata" count="1"></rvStructures>` ))
628+ pics , err = f .GetPictures ("Sheet1" , "A1" )
629+ assert .NoError (t , err )
630+ assert .Equal (t , 1 , len (pics ))
631+
632+ // Test get the cell images with unsupported charset rich value
633+ f .Pkg .Store (defaultXMLRdRichValueStructurePart , MacintoshCyrillicCharset )
634+ _ , err = f .GetPictures ("Sheet1" , "A1" )
635+ assert .EqualError (t , err , "XML syntax error on line 1: invalid UTF-8" )
608636}
609637
610638func TestGetImageCells (t * testing.T ) {
@@ -615,3 +643,33 @@ func TestGetImageCells(t *testing.T) {
615643 assert .EqualError (t , err , "XML syntax error on line 1: invalid UTF-8" )
616644 assert .NoError (t , f .Close ())
617645}
646+
647+ func TestGetCellImagesAndAltText (t * testing.T ) {
648+ f , err := OpenFile (filepath .Join ("test" , "CellImage.xlsx" ))
649+ assert .NoError (t , err )
650+ type imageType struct {
651+ cell string
652+ insertType PictureInsertType
653+ altText string
654+ }
655+ want := []imageType {
656+ {"B1" , PictureInsertTypePlaceInCell , "Smiling alarm clock face" },
657+ {"B2" , PictureInsertTypePlaceInCell , "" },
658+ {"B3" , PictureInsertTypePlaceInCell , "Bullseye outline" },
659+ {"B4" , PictureInsertTypeIMAGE , "" },
660+ {"B5" , PictureInsertTypeIMAGE , "other alt_text" },
661+
662+ {"D1" , PictureInsertTypePlaceInCell , "Smiling alarm clock face" },
663+ {"D2" , PictureInsertTypePlaceInCell , "" },
664+ {"D3" , PictureInsertTypePlaceInCell , "Bullseye outline" },
665+ {"D4" , PictureInsertTypePlaceInCell , "" },
666+ {"D5" , PictureInsertTypePlaceInCell , "other alt_text" },
667+ }
668+ for _ , c := range want {
669+ p , err := f .GetPictures ("Sheet1" , c .cell )
670+ assert .NoError (t , err )
671+ assert .Equal (t , 1 , len (p ))
672+ assert .Equal (t , c .insertType , p [0 ].InsertType , c .cell )
673+ }
674+ assert .NoError (t , f .Close ())
675+ }
0 commit comments