@@ -36,17 +36,22 @@ func TestAddPicture(t *testing.T) {
3636 assert .NoError (t , err )
3737
3838 // Test add picture to worksheet with offset and location hyperlink
39- assert .NoError (t , f .AddPicture ("Sheet2" , "I9" , filepath .Join ("test" , "images" , "excel.jpg" ),
40- & GraphicOptions {OffsetX : 140 , OffsetY : 120 , Hyperlink : "#Sheet2!D8" , HyperlinkType : "Location" }))
39+ opts := []GraphicOptions {
40+ {Hyperlink : "#Sheet2!D8" , HyperlinkType : "Location" },
41+ {OffsetX : 10 , OffsetY : 10 , ScaleX : 0.5 , ScaleY : 0.5 , Hyperlink : "https://github.com/xuri/excelize" , HyperlinkType : "External" , Positioning : "oneCell" },
42+ {OffsetX : 10 , OffsetY : 10 , ScaleX : 1.5 , ScaleY : 1.5 , Hyperlink : "https://github.com/xuri/excelize" , HyperlinkType : "External" },
43+ {PrintObject : boolPtr (true ), Locked : boolPtr (true ), OffsetX : 200 , ScaleX : 1 , ScaleY : 1 , Positioning : "oneCell" },
44+ {PrintObject : boolPtr (true ), Locked : boolPtr (true ), AltText : "Excel Logo" , LockAspectRatio : true , ScaleX : 1 , ScaleY : 1 },
45+ }
46+ assert .NoError (t , f .AddPicture ("Sheet2" , "I9" , filepath .Join ("test" , "images" , "excel.jpg" ), & opts [0 ]))
4147 // Test add picture to worksheet with offset, external hyperlink and positioning
42- assert .NoError (t , f .AddPicture ("Sheet1" , "F21" , filepath .Join ("test" , "images" , "excel.jpg" ),
43- & GraphicOptions { OffsetX : 10 , OffsetY : 10 , Hyperlink : "https://github.com/xuri/excelize" , HyperlinkType : "External " , Positioning : "oneCell" } ))
48+ assert .NoError (t , f .AddPicture ("Sheet1" , "F21" , filepath .Join ("test" , "images" , "excel.jpg" ), & opts [ 1 ]))
49+ assert . NoError ( t , f . AddPicture ( "Sheet1" , "H21" , filepath . Join ( "test" , "images " , "excel.jpg" ), & opts [ 2 ] ))
4450
4551 // Test add pictures to single cell with offsets
4652 assert .NoError (t , f .AddPicture ("Sheet2" , "K22" , filepath .Join ("test" , "images" , "excel.jpg" ),
4753 & GraphicOptions {Positioning : "oneCell" }))
48- assert .NoError (t , f .AddPicture ("Sheet2" , "K22" , filepath .Join ("test" , "images" , "excel.jpg" ),
49- & GraphicOptions {OffsetX : 200 , Positioning : "oneCell" }))
54+ assert .NoError (t , f .AddPicture ("Sheet2" , "K22" , filepath .Join ("test" , "images" , "excel.jpg" ), & opts [3 ]))
5055 assert .NoError (t , f .AddPicture ("Sheet2" , "K22" , filepath .Join ("test" , "images" , "excel.jpg" ),
5156 & GraphicOptions {OffsetX : 400 , Positioning : "oneCell" }))
5257 assert .NoError (t , f .AddPicture ("Sheet2" , "K22" , filepath .Join ("test" , "images" , "excel.jpg" ),
@@ -68,7 +73,7 @@ func TestAddPicture(t *testing.T) {
6873 assert .NoError (t , f .AddPicture ("AddPicture" , "A1" , filepath .Join ("test" , "images" , "excel.jpg" ), & GraphicOptions {AutoFit : true }))
6974
7075 // Test add picture to worksheet from bytes
71- assert .NoError (t , f .AddPictureFromBytes ("Sheet1" , "Q1" , & Picture {Extension : ".png" , File : file , Format : & GraphicOptions { AltText : "Excel Logo" } }))
76+ assert .NoError (t , f .AddPictureFromBytes ("Sheet1" , "Q1" , & Picture {Extension : ".png" , File : file , Format : & opts [ 4 ] }))
7277 // Test add picture to worksheet from bytes with unsupported insert type
7378 assert .Equal (t , ErrParameterInvalid , f .AddPictureFromBytes ("Sheet1" , "Q1" , & Picture {Extension : ".png" , File : file , Format : & GraphicOptions {AltText : "Excel Logo" }, InsertType : PictureInsertTypePlaceInCell }))
7479 // Test add picture to worksheet from bytes with illegal cell reference
@@ -77,6 +82,31 @@ func TestAddPicture(t *testing.T) {
7782 for _ , preset := range [][]string {{"Q8" , "gif" }, {"Q15" , "jpg" }, {"Q22" , "tif" }, {"Q28" , "bmp" }} {
7883 assert .NoError (t , f .AddPicture ("Sheet1" , preset [0 ], filepath .Join ("test" , "images" , fmt .Sprintf ("excel.%s" , preset [1 ])), nil ))
7984 }
85+ // Test get one cell anchor pictures from worksheet which added pictures with offset
86+ pics , err := f .GetPictures ("Sheet2" , "K22" )
87+ assert .NoError (t , err )
88+ assert .Len (t , pics , 4 )
89+ assert .Equal (t , opts [3 ], * pics [1 ].Format )
90+ // Test get one cell anchor pictures from worksheet which added pictures with offset and scale
91+ pics , err = f .GetPictures ("Sheet1" , "F21" )
92+ assert .NoError (t , err )
93+ assert .Len (t , pics , 1 )
94+ assert .Equal (t , opts [1 ], * pics [0 ].Format )
95+ // Test get two cell anchor pictures from worksheet which added pictures with offset and scale
96+ pics , err = f .GetPictures ("Sheet1" , "H21" )
97+ assert .NoError (t , err )
98+ assert .Len (t , pics , 1 )
99+ assert .Equal (t , opts [2 ], * pics [0 ].Format )
100+ // Test get two cell anchor pictures from worksheet which added pictures with alternative text
101+ pics , err = f .GetPictures ("Sheet1" , "Q1" )
102+ assert .NoError (t , err )
103+ assert .Len (t , pics , 1 )
104+ assert .Equal (t , opts [4 ], * pics [0 ].Format )
105+ // Test get two cell anchor pictures from worksheet which added pictures with location hyperlink
106+ pics , err = f .GetPictures ("Sheet2" , "I9" )
107+ assert .NoError (t , err )
108+ assert .Len (t , pics , 1 )
109+ assert .Equal (t , opts [0 ], * pics [0 ].Format )
80110
81111 // Test write file to given path
82112 assert .NoError (t , f .SaveAs (filepath .Join ("test" , "TestAddPicture1.xlsx" )))
@@ -86,14 +116,40 @@ func TestAddPicture(t *testing.T) {
86116 f , err = OpenFile (filepath .Join ("test" , "TestAddPicture1.xlsx" ))
87117 assert .NoError (t , err )
88118 assert .NoError (t , f .AddPicture ("Sheet1" , "A30" , filepath .Join ("test" , "images" , "excel.jpg" ), nil ))
89- pics , err : = f .GetPictures ("Sheet1" , "A30" )
119+ pics , err = f .GetPictures ("Sheet1" , "A30" )
90120 assert .NoError (t , err )
91121 assert .Len (t , pics , 2 )
92122
123+ // Test get one cell anchor pictures from worksheet which already contains pictures
124+ pics , err = f .GetPictures ("Sheet2" , "K22" )
125+ assert .NoError (t , err )
126+ assert .Len (t , pics , 4 )
127+ assert .Equal (t , opts [3 ], * pics [1 ].Format )
128+ // Test get one cell anchor pictures from worksheet which already contains pictures with offset and scale
129+ pics , err = f .GetPictures ("Sheet1" , "F21" )
130+ assert .NoError (t , err )
131+ assert .Len (t , pics , 1 )
132+ assert .Equal (t , opts [1 ], * pics [0 ].Format )
133+ // Test get two cell anchor pictures from worksheet which already contains pictures
134+ pics , err = f .GetPictures ("Sheet1" , "H21" )
135+ assert .NoError (t , err )
136+ assert .Len (t , pics , 1 )
137+ assert .Equal (t , opts [2 ], * pics [0 ].Format )
138+ // Test get two cell anchor pictures from worksheet which already contains pictures with alternative text
139+ pics , err = f .GetPictures ("Sheet1" , "Q1" )
140+ assert .NoError (t , err )
141+ assert .Len (t , pics , 1 )
142+ assert .Equal (t , opts [4 ], * pics [0 ].Format )
143+ // Test get two cell anchor pictures from worksheet which already contains pictures with location hyperlink
144+ pics , err = f .GetPictures ("Sheet2" , "I9" )
145+ assert .NoError (t , err )
146+ assert .Len (t , pics , 1 )
147+ assert .Equal (t , opts [0 ], * pics [0 ].Format )
148+
93149 // Test get picture cells
94150 cells , err := f .GetPictureCells ("Sheet1" )
95151 assert .NoError (t , err )
96- assert .Equal (t , []string {"A30" , "B30" , "C30" , "Q1" , "Q8" , "Q15" , "Q22" , "Q28" , "F21" }, cells )
152+ assert .Equal (t , []string {"H21" , " A30" , "B30" , "C30" , "Q1" , "Q8" , "Q15" , "Q22" , "Q28" , "F21" }, cells )
97153 assert .NoError (t , f .Close ())
98154
99155 f , err = OpenFile (filepath .Join ("test" , "TestAddPicture1.xlsx" ))
@@ -102,7 +158,7 @@ func TestAddPicture(t *testing.T) {
102158 f .Drawings .Delete (path )
103159 cells , err = f .GetPictureCells ("Sheet1" )
104160 assert .NoError (t , err )
105- assert .Equal (t , []string {"A30" , "B30" , "C30" , "Q1" , "Q8" , "Q15" , "Q22" , "Q28" , "F21" }, cells )
161+ assert .Equal (t , []string {"H21" , " A30" , "B30" , "C30" , "Q1" , "Q8" , "Q15" , "Q22" , "Q28" , "F21" }, cells )
106162 // Test get picture cells with unsupported charset
107163 f .Drawings .Delete (path )
108164 f .Pkg .Store (path , MacintoshCyrillicCharset )
@@ -473,7 +529,7 @@ func TestGetPictureCells(t *testing.T) {
473529func TestExtractDecodeCellAnchor (t * testing.T ) {
474530 f := NewFile ()
475531 cond := func (a * decodeFrom ) bool { return true }
476- cb := func (a * decodeCellAnchor , r * xlsxRelationship ) {}
532+ cb := func (a * decodeCellAnchor , r * xlsxRelationship , drawingRelationships string ) {}
477533 f .extractDecodeCellAnchor (& xdrCellAnchor {GraphicFrame : string (MacintoshCyrillicCharset )}, "" , cond , cb )
478534}
479535
0 commit comments