@@ -246,7 +246,7 @@ func TestGetPicture(t *testing.T) {
246246 assert .NoError (t , err )
247247 assert .NoError (t , f .SetCellFormula ("Sheet1" , "F21" , "=_xlfn.DISPIMG(\" ID_********************************\" ,1)" ))
248248 f .Pkg .Store (defaultXMLPathCellImages , []byte (`<etc:cellImages xmlns:etc="http://www.wps.cn/officeDocument/2017/etCustomData"><etc:cellImage><xdr:pic><xdr:nvPicPr><xdr:cNvPr id="1" name="ID_********************************" descr="CellImage1"/></xdr:nvPicPr><xdr:blipFill><a:blip r:embed="rId1"/></xdr:blipFill></xdr:pic></etc:cellImage></etc:cellImages>` ))
249- f .Pkg .Store (defaultXMLPathCellImagesRels , []byte (`<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image " Target="media/image1.jpeg"/></Relationships>` ))
249+ f .Pkg .Store (defaultXMLPathCellImagesRels , []byte (fmt . Sprintf ( `<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="%s " Target="media/image1.jpeg"/></Relationships>` , SourceRelationshipImage ) ))
250250 pics , err = f .GetPictures ("Sheet1" , "F21" )
251251 assert .NoError (t , err )
252252 assert .Len (t , pics , 2 )
@@ -457,9 +457,9 @@ func TestGetCellImages(t *testing.T) {
457457 f := NewFile ()
458458 assert .NoError (t , f .AddPicture ("Sheet1" , "A1" , filepath .Join ("test" , "images" , "excel.png" ), nil ))
459459 f .Pkg .Store (defaultXMLMetadata , []byte (`<metadata><valueMetadata count="1"><bk><rc t="1" v="0"/></bk></valueMetadata></metadata>` ))
460- f .Pkg .Store (defaultXMLRichDataRichValue , []byte (`<rvData count="1"><rv s="0"><v>0</v><v>5</v></rv></rvData>` ))
461- f .Pkg .Store (defaultXMLRichDataRichValueRel , []byte (`<richValueRels><rel r:id="rId1"/></richValueRels>` ))
462- f .Pkg .Store (defaultXMLRichDataRichValueRelRels , []byte (fmt .Sprintf (`<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="%s" Target="../media/image1.png"/></Relationships>` , SourceRelationshipImage )))
460+ f .Pkg .Store (defaultXMLRdRichValuePart , []byte (`<rvData count="1"><rv s="0"><v>0</v><v>5</v></rv></rvData>` ))
461+ f .Pkg .Store (defaultXMLRdRichValueRel , []byte (`<richValueRels><rel r:id="rId1"/></richValueRels>` ))
462+ 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 )))
463463 f .Sheet .Store ("xl/worksheets/sheet1.xml" , & xlsxWorksheet {
464464 SheetData : xlsxSheetData {Row : []xlsxRow {
465465 {R : 1 , C : []xlsxC {{R : "A1" , T : "e" , V : formulaErrorVALUE , Vm : uintPtr (1 )}}},
@@ -477,19 +477,19 @@ func TestGetCellImages(t *testing.T) {
477477 assert .Equal (t , []string {"A1" }, cells )
478478
479479 // Test get the cell images without image relationships parts
480- f .Relationships .Delete (defaultXMLRichDataRichValueRelRels )
481- f .Pkg .Store (defaultXMLRichDataRichValueRelRels , []byte (fmt .Sprintf (`<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="%s" Target="../media/image1.png"/></Relationships>` , SourceRelationshipHyperLink )))
480+ f .Relationships .Delete (defaultXMLRdRichValueRelRels )
481+ 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 )))
482482 pics , err = f .GetPictures ("Sheet1" , "A1" )
483483 assert .NoError (t , err )
484484 assert .Empty (t , pics )
485485 // Test get the cell images with unsupported charset rich data rich value relationships
486- f .Relationships .Delete (defaultXMLRichDataRichValueRelRels )
487- f .Pkg .Store (defaultXMLRichDataRichValueRelRels , MacintoshCyrillicCharset )
486+ f .Relationships .Delete (defaultXMLRdRichValueRelRels )
487+ f .Pkg .Store (defaultXMLRdRichValueRelRels , MacintoshCyrillicCharset )
488488 pics , err = f .GetPictures ("Sheet1" , "A1" )
489489 assert .NoError (t , err )
490490 assert .Empty (t , pics )
491491 // Test get the cell images with unsupported charset rich data rich value
492- f .Pkg .Store (defaultXMLRichDataRichValueRel , MacintoshCyrillicCharset )
492+ f .Pkg .Store (defaultXMLRdRichValueRel , MacintoshCyrillicCharset )
493493 _ , err = f .GetPictures ("Sheet1" , "A1" )
494494 assert .EqualError (t , err , "XML syntax error on line 1: invalid UTF-8" )
495495 // Test get the image cells without block of metadata records
@@ -498,7 +498,7 @@ func TestGetCellImages(t *testing.T) {
498498 assert .Empty (t , cells )
499499 // Test get the cell images with rich data rich value relationships
500500 f .Pkg .Store (defaultXMLMetadata , []byte (`<metadata><valueMetadata count="1"><bk><rc t="1" v="0"/></bk></valueMetadata></metadata>` ))
501- f .Pkg .Store (defaultXMLRichDataRichValueRel , []byte (`<richValueRels/>` ))
501+ f .Pkg .Store (defaultXMLRdRichValueRel , []byte (`<richValueRels/>` ))
502502 pics , err = f .GetPictures ("Sheet1" , "A1" )
503503 assert .NoError (t , err )
504504 assert .Empty (t , pics )
@@ -514,17 +514,17 @@ func TestGetCellImages(t *testing.T) {
514514
515515 f = prepareWorkbook ()
516516 // Test get the cell images with empty image cell rich value
517- f .Pkg .Store (defaultXMLRichDataRichValue , []byte (`<rvData count="1"><rv s="0"><v></v><v>5</v></rv></rvData>` ))
517+ f .Pkg .Store (defaultXMLRdRichValuePart , []byte (`<rvData count="1"><rv s="0"><v></v><v>5</v></rv></rvData>` ))
518518 pics , err = f .GetPictures ("Sheet1" , "A1" )
519519 assert .EqualError (t , err , "strconv.Atoi: parsing \" \" : invalid syntax" )
520520 assert .Empty (t , pics )
521521 // Test get the cell images without image cell rich value
522- f .Pkg .Store (defaultXMLRichDataRichValue , []byte (`<rvData count="1"><rv s="0"><v>0</v><v>1</v></rv></rvData>` ))
522+ f .Pkg .Store (defaultXMLRdRichValuePart , []byte (`<rvData count="1"><rv s="0"><v>0</v><v>1</v></rv></rvData>` ))
523523 pics , err = f .GetPictures ("Sheet1" , "A1" )
524524 assert .NoError (t , err )
525525 assert .Empty (t , pics )
526526 // Test get the cell images with unsupported charset rich value
527- f .Pkg .Store (defaultXMLRichDataRichValue , MacintoshCyrillicCharset )
527+ f .Pkg .Store (defaultXMLRdRichValuePart , MacintoshCyrillicCharset )
528528 _ , err = f .GetPictures ("Sheet1" , "A1" )
529529 assert .EqualError (t , err , "XML syntax error on line 1: invalid UTF-8" )
530530
@@ -534,6 +534,44 @@ func TestGetCellImages(t *testing.T) {
534534 pics , err = f .GetPictures ("Sheet1" , "A1" )
535535 assert .NoError (t , err )
536536 assert .Empty (t , pics )
537+
538+ f = prepareWorkbook ()
539+ // Test get the cell images inserted by IMAGE formula function
540+ 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>` ))
541+ 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>
542+ </webImagesSrd>` ))
543+ 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 )))
544+ pics , err = f .GetPictures ("Sheet1" , "A1" )
545+ assert .NoError (t , err )
546+ assert .Equal (t , 1 , len (pics ))
547+ assert .Equal (t , PictureInsertTypeIMAGE , pics [0 ].InsertType )
548+
549+ // Test get the cell images inserted by IMAGE formula function with unsupported charset web images relationships
550+ f .Relationships .Delete (defaultXMLRdRichValueWebImagePartRels )
551+ f .Pkg .Store (defaultXMLRdRichValueWebImagePartRels , MacintoshCyrillicCharset )
552+ pics , err = f .GetPictures ("Sheet1" , "A1" )
553+ assert .NoError (t , err )
554+ assert .Empty (t , pics )
555+
556+ // Test get the cell images inserted by IMAGE formula function without image part
557+ f .Relationships .Delete (defaultXMLRdRichValueWebImagePartRels )
558+ 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 )))
559+ pics , err = f .GetPictures ("Sheet1" , "A1" )
560+ assert .NoError (t , err )
561+ assert .Empty (t , pics )
562+ // Test get the cell images inserted by IMAGE formula function with unsupported charset web images part
563+ f .Pkg .Store (defaultXMLRdRichValueWebImagePart , MacintoshCyrillicCharset )
564+ _ , err = f .GetPictures ("Sheet1" , "A1" )
565+ assert .EqualError (t , err , "XML syntax error on line 1: invalid UTF-8" )
566+ // Test get the cell images inserted by IMAGE formula function with empty charset web images part
567+ f .Pkg .Store (defaultXMLRdRichValueWebImagePart , []byte (`<webImagesSrd xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" />` ))
568+ pics , err = f .GetPictures ("Sheet1" , "A1" )
569+ assert .NoError (t , err )
570+ assert .Empty (t , pics )
571+ // Test get the cell images inserted by IMAGE formula function with invalid rich value index
572+ f .Pkg .Store (defaultXMLRdRichValuePart , []byte (`<rvData count="1"><rv s="1"><v></v><v>1</v><v>0</v><v>0</v></rv></rvData>` ))
573+ _ , err = f .GetPictures ("Sheet1" , "A1" )
574+ assert .EqualError (t , err , "strconv.Atoi: parsing \" \" : invalid syntax" )
537575}
538576
539577func TestGetImageCells (t * testing.T ) {
0 commit comments