@@ -246,7 +246,7 @@ func TestGetPicture(t *testing.T) {
246
246
assert .NoError (t , err )
247
247
assert .NoError (t , f .SetCellFormula ("Sheet1" , "F21" , "=_xlfn.DISPIMG(\" ID_********************************\" ,1)" ))
248
248
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 ) ))
250
250
pics , err = f .GetPictures ("Sheet1" , "F21" )
251
251
assert .NoError (t , err )
252
252
assert .Len (t , pics , 2 )
@@ -457,9 +457,9 @@ func TestGetCellImages(t *testing.T) {
457
457
f := NewFile ()
458
458
assert .NoError (t , f .AddPicture ("Sheet1" , "A1" , filepath .Join ("test" , "images" , "excel.png" ), nil ))
459
459
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 )))
463
463
f .Sheet .Store ("xl/worksheets/sheet1.xml" , & xlsxWorksheet {
464
464
SheetData : xlsxSheetData {Row : []xlsxRow {
465
465
{R : 1 , C : []xlsxC {{R : "A1" , T : "e" , V : formulaErrorVALUE , Vm : uintPtr (1 )}}},
@@ -477,19 +477,19 @@ func TestGetCellImages(t *testing.T) {
477
477
assert .Equal (t , []string {"A1" }, cells )
478
478
479
479
// 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 )))
482
482
pics , err = f .GetPictures ("Sheet1" , "A1" )
483
483
assert .NoError (t , err )
484
484
assert .Empty (t , pics )
485
485
// 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 )
488
488
pics , err = f .GetPictures ("Sheet1" , "A1" )
489
489
assert .NoError (t , err )
490
490
assert .Empty (t , pics )
491
491
// Test get the cell images with unsupported charset rich data rich value
492
- f .Pkg .Store (defaultXMLRichDataRichValueRel , MacintoshCyrillicCharset )
492
+ f .Pkg .Store (defaultXMLRdRichValueRel , MacintoshCyrillicCharset )
493
493
_ , err = f .GetPictures ("Sheet1" , "A1" )
494
494
assert .EqualError (t , err , "XML syntax error on line 1: invalid UTF-8" )
495
495
// Test get the image cells without block of metadata records
@@ -498,7 +498,7 @@ func TestGetCellImages(t *testing.T) {
498
498
assert .Empty (t , cells )
499
499
// Test get the cell images with rich data rich value relationships
500
500
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/>` ))
502
502
pics , err = f .GetPictures ("Sheet1" , "A1" )
503
503
assert .NoError (t , err )
504
504
assert .Empty (t , pics )
@@ -514,17 +514,17 @@ func TestGetCellImages(t *testing.T) {
514
514
515
515
f = prepareWorkbook ()
516
516
// 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>` ))
518
518
pics , err = f .GetPictures ("Sheet1" , "A1" )
519
519
assert .EqualError (t , err , "strconv.Atoi: parsing \" \" : invalid syntax" )
520
520
assert .Empty (t , pics )
521
521
// 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>` ))
523
523
pics , err = f .GetPictures ("Sheet1" , "A1" )
524
524
assert .NoError (t , err )
525
525
assert .Empty (t , pics )
526
526
// Test get the cell images with unsupported charset rich value
527
- f .Pkg .Store (defaultXMLRichDataRichValue , MacintoshCyrillicCharset )
527
+ f .Pkg .Store (defaultXMLRdRichValuePart , MacintoshCyrillicCharset )
528
528
_ , err = f .GetPictures ("Sheet1" , "A1" )
529
529
assert .EqualError (t , err , "XML syntax error on line 1: invalid UTF-8" )
530
530
@@ -534,6 +534,44 @@ func TestGetCellImages(t *testing.T) {
534
534
pics , err = f .GetPictures ("Sheet1" , "A1" )
535
535
assert .NoError (t , err )
536
536
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" )
537
575
}
538
576
539
577
func TestGetImageCells (t * testing.T ) {
0 commit comments