@@ -500,6 +500,11 @@ func TestGetCellImages(t *testing.T) {
500
500
})
501
501
return f
502
502
}
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
+ }
503
508
f = prepareWorkbook ()
504
509
pics , err := f .GetPictures ("Sheet1" , "A1" )
505
510
assert .NoError (t , err )
@@ -509,6 +514,17 @@ func TestGetCellImages(t *testing.T) {
509
514
assert .NoError (t , err )
510
515
assert .Equal (t , []string {"A1" }, cells )
511
516
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 ()
512
528
// Test get the cell images without image relationships parts
513
529
f .Relationships .Delete (defaultXMLRdRichValueRelRels )
514
530
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) {
605
621
f .Pkg .Store (defaultXMLRdRichValuePart , []byte (`<rvData count="1"><rv s="1"><v></v><v>1</v><v>0</v><v>0</v></rv></rvData>` ))
606
622
_ , err = f .GetPictures ("Sheet1" , "A1" )
607
623
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" )
608
636
}
609
637
610
638
func TestGetImageCells (t * testing.T ) {
@@ -615,3 +643,33 @@ func TestGetImageCells(t *testing.T) {
615
643
assert .EqualError (t , err , "XML syntax error on line 1: invalid UTF-8" )
616
644
assert .NoError (t , f .Close ())
617
645
}
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