@@ -546,9 +546,10 @@ func TestGetCellImages(t *testing.T) {
546546 f := NewFile ()
547547 assert .NoError (t , f .AddPicture ("Sheet1" , "A1" , filepath .Join ("test" , "images" , "excel.png" ), nil ))
548548 f .Pkg .Store (defaultXMLMetadata , []byte (`<metadata><valueMetadata count="1"><bk><rc t="1" v="0"/></bk></valueMetadata></metadata>` ))
549- f .Pkg .Store (defaultXMLRdRichValuePart , []byte (`<rvData count="1"><rv s="0"><v>0</v><v>5</v></rv></rvData>` ))
549+ f .Pkg .Store (defaultXMLRdRichValue , []byte (`<rvData count="1"><rv s="0"><v>0</v><v>5</v><v>logo </v></rv></rvData>` ))
550550 f .Pkg .Store (defaultXMLRdRichValueRel , []byte (`<richValueRels><rel r:id="rId1"/></richValueRels>` ))
551551 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>` , SourceRelationshipImage )))
552+ f .Pkg .Store (defaultXMLRdRichValueStructure , []byte (`<rvStructures><s t="_localImage"><k n="_rvRel:LocalImageIdentifier" t="i"/><k n="CalcOrigin" t="i"/><k n="Text" t="s"/></s></rvStructures>` ))
552553 f .Sheet .Store ("xl/worksheets/sheet1.xml" , & xlsxWorksheet {
553554 SheetData : xlsxSheetData {Row : []xlsxRow {
554555 {R : 1 , C : []xlsxC {{R : "A1" , T : "e" , V : formulaErrorVALUE , Vm : uintPtr (1 )}}},
@@ -561,6 +562,7 @@ func TestGetCellImages(t *testing.T) {
561562 assert .NoError (t , err )
562563 assert .Equal (t , 1 , len (pics ))
563564 assert .Equal (t , PictureInsertTypePlaceInCell , pics [0 ].InsertType )
565+ assert .Equal (t , "logo" , pics [0 ].Format .AltText )
564566 cells , err := f .GetPictureCells ("Sheet1" )
565567 assert .NoError (t , err )
566568 assert .Equal (t , []string {"A1" }, cells )
@@ -603,17 +605,18 @@ func TestGetCellImages(t *testing.T) {
603605
604606 f = prepareWorkbook ()
605607 // Test get the cell images with empty image cell rich value
606- f .Pkg .Store (defaultXMLRdRichValuePart , []byte (`<rvData count="1"><rv s="0"><v></v><v>5</v></rv></rvData>` ))
608+ f .Pkg .Store (defaultXMLRdRichValue , []byte (`<rvData count="1"><rv s="0"><v></v><v>5</v><v>logo </v></rv></rvData>` ))
607609 pics , err = f .GetPictures ("Sheet1" , "A1" )
608610 assert .EqualError (t , err , "strconv.Atoi: parsing \" \" : invalid syntax" )
609611 assert .Empty (t , pics )
610612 // Test get the cell images without image cell rich value
611- f .Pkg .Store (defaultXMLRdRichValuePart , []byte (`<rvData count="1"><rv s="0"><v>0</v><v>1</v></rv></rvData>` ))
613+ f .Pkg .Store (defaultXMLRdRichValue , []byte (`<rvData count="1"><rv s="0"><v>0</v><v>1</v></rv></rvData>` ))
614+ f .Pkg .Delete (defaultXMLRdRichValueStructure )
612615 pics , err = f .GetPictures ("Sheet1" , "A1" )
613616 assert .NoError (t , err )
614617 assert .Empty (t , pics )
615618 // Test get the cell images with unsupported charset rich value
616- f .Pkg .Store (defaultXMLRdRichValuePart , MacintoshCyrillicCharset )
619+ f .Pkg .Store (defaultXMLRdRichValue , MacintoshCyrillicCharset )
617620 _ , err = f .GetPictures ("Sheet1" , "A1" )
618621 assert .EqualError (t , err , "XML syntax error on line 1: invalid UTF-8" )
619622
@@ -626,41 +629,59 @@ func TestGetCellImages(t *testing.T) {
626629
627630 f = prepareWorkbook ()
628631 // Test get the cell images inserted by IMAGE formula function
629- f .Pkg .Store (defaultXMLRdRichValuePart , []byte (`<rvData count="1"><rv s="1"><v>0</v><v>1</v><v>0</v><v>0</v></rv></rvData>` ))
630- f .Pkg .Store (defaultXMLRdRichValueWebImagePart , []byte (`<webImagesSrd xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><webImageSrd><address r:id="rId1"/><blip r:id="rId2"/></webImageSrd>
632+ f .Pkg .Store (defaultXMLRdRichValue , []byte (`<rvData count="1"><rv s="1"><v>0</v><v>1</v><v>0</v><v>0</v></rv></rvData>` ))
633+ f .Pkg .Store (defaultXMLRdRichValueStructure , []byte (`<rvStructures><s t="_localImage"><k n="_rvRel:LocalImageIdentifier" t="i"/><k n="CalcOrigin" t="i"/></s><s t="_webimage"><k n="WebImageIdentifier" t="i"/><k n="CalcOrigin" t="i"/><k n="ComputedImage" t="b"/><k n="ImageSizing" t="i"/></s></rvStructures>` ))
634+ f .Pkg .Store (defaultXMLRdRichValueWebImage , []byte (`<webImagesSrd xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><webImageSrd><address r:id="rId1"/><blip r:id="rId2"/></webImageSrd>
631635 </webImagesSrd>` ))
632- f .Pkg .Store (defaultXMLRdRichValueWebImagePartRels , []byte (fmt .Sprintf (`<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="%s" Target="https://github.com/xuri/excelize" TargetMode="External"/><Relationship Id="rId2" Type="%s" Target="../media/image1.png"/></Relationships>` , SourceRelationshipHyperLink , SourceRelationshipImage )))
636+ f .Pkg .Store (defaultXMLRdRichValueWebImageRels , []byte (fmt .Sprintf (`<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="%s" Target="https://github.com/xuri/excelize" TargetMode="External"/><Relationship Id="rId2" Type="%s" Target="../media/image1.png"/></Relationships>` , SourceRelationshipHyperLink , SourceRelationshipImage )))
633637 pics , err = f .GetPictures ("Sheet1" , "A1" )
634638 assert .NoError (t , err )
635639 assert .Equal (t , 1 , len (pics ))
636640 assert .Equal (t , PictureInsertTypeIMAGE , pics [0 ].InsertType )
637641
638642 // Test get the cell images inserted by IMAGE formula function with unsupported charset web images relationships
639- f .Relationships .Delete (defaultXMLRdRichValueWebImagePartRels )
640- f .Pkg .Store (defaultXMLRdRichValueWebImagePartRels , MacintoshCyrillicCharset )
643+ f .Relationships .Delete (defaultXMLRdRichValueWebImageRels )
644+ f .Pkg .Store (defaultXMLRdRichValueWebImageRels , MacintoshCyrillicCharset )
641645 pics , err = f .GetPictures ("Sheet1" , "A1" )
642646 assert .NoError (t , err )
643647 assert .Empty (t , pics )
644648
645649 // Test get the cell images inserted by IMAGE formula function without image part
646- f .Relationships .Delete (defaultXMLRdRichValueWebImagePartRels )
647- f .Pkg .Store (defaultXMLRdRichValueWebImagePartRels , []byte (fmt .Sprintf (`<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="%s" Target="https://github.com/xuri/excelize" TargetMode="External"/><Relationship Id="rId2" Type="%s" Target="../media/image1.png"/></Relationships>` , SourceRelationshipHyperLink , SourceRelationshipHyperLink )))
650+ f .Relationships .Delete (defaultXMLRdRichValueWebImageRels )
651+ f .Pkg .Store (defaultXMLRdRichValueWebImageRels , []byte (fmt .Sprintf (`<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="%s" Target="https://github.com/xuri/excelize" TargetMode="External"/><Relationship Id="rId2" Type="%s" Target="../media/image1.png"/></Relationships>` , SourceRelationshipHyperLink , SourceRelationshipHyperLink )))
648652 pics , err = f .GetPictures ("Sheet1" , "A1" )
649653 assert .NoError (t , err )
650654 assert .Empty (t , pics )
651655 // Test get the cell images inserted by IMAGE formula function with unsupported charset web images part
652- f .Pkg .Store (defaultXMLRdRichValueWebImagePart , MacintoshCyrillicCharset )
656+ f .Pkg .Store (defaultXMLRdRichValueWebImage , MacintoshCyrillicCharset )
653657 _ , err = f .GetPictures ("Sheet1" , "A1" )
654658 assert .EqualError (t , err , "XML syntax error on line 1: invalid UTF-8" )
655659 // Test get the cell images inserted by IMAGE formula function with empty charset web images part
656- f .Pkg .Store (defaultXMLRdRichValueWebImagePart , []byte (`<webImagesSrd xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" />` ))
660+ f .Pkg .Store (defaultXMLRdRichValueWebImage , []byte (`<webImagesSrd xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" />` ))
657661 pics , err = f .GetPictures ("Sheet1" , "A1" )
658662 assert .NoError (t , err )
659663 assert .Empty (t , pics )
660664 // Test get the cell images inserted by IMAGE formula function with invalid rich value index
661- f .Pkg .Store (defaultXMLRdRichValuePart , []byte (`<rvData count="1"><rv s="1"><v></v><v>1</v><v>0</v><v>0</v></rv></rvData>` ))
665+ f .Pkg .Store (defaultXMLRdRichValue , []byte (`<rvData count="1"><rv s="1"><v></v><v>1</v><v>0</v><v>0</v></rv></rvData>` ))
662666 _ , err = f .GetPictures ("Sheet1" , "A1" )
663667 assert .EqualError (t , err , "strconv.Atoi: parsing \" \" : invalid syntax" )
668+
669+ f = prepareWorkbook ()
670+ // Test get the cell images inserted by IMAGE formula function with not matched rich value and structure keys
671+ f .Pkg .Store (defaultXMLRdRichValue , []byte (`<rvData count="1"><rv s="0"><v>0</v></rv></rvData>` ))
672+ f .Pkg .Store (defaultXMLRdRichValueStructure , []byte (`<rvStructures><s t="_localImage"/></rvStructures>` ))
673+ pics , err = f .GetPictures ("Sheet1" , "A1" )
674+ assert .NoError (t , err )
675+ assert .Empty (t , pics )
676+ // Test get the cell images inserted by IMAGE formula function without _rvRel:WebImageIdentifier in rich value structure
677+ f .Pkg .Store (defaultXMLRdRichValueStructure , []byte (`<rvStructures><s t="_localImage"><k n="CalcOrigin" t="i"/></s></rvStructures>` ))
678+ pics , err = f .GetPictures ("Sheet1" , "A1" )
679+ assert .NoError (t , err )
680+ assert .Empty (t , pics )
681+ // Test get the cell images inserted by IMAGE formula function with unsupported charset rich value structures
682+ f .Pkg .Store (defaultXMLRdRichValueStructure , MacintoshCyrillicCharset )
683+ _ , err = f .GetPictures ("Sheet1" , "A1" )
684+ assert .EqualError (t , err , "XML syntax error on line 1: invalid UTF-8" )
664685}
665686
666687func TestGetImageCells (t * testing.T ) {
0 commit comments