11package excelize
22
33import (
4- "fmt"
4+ _ "image/gif"
5+ _ "image/jpeg"
56 _ "image/png"
7+
8+ _ "golang.org/x/image/tiff"
9+
10+ "fmt"
611 "io/ioutil"
712 "os"
813 "path/filepath"
@@ -25,37 +30,41 @@ func BenchmarkAddPictureFromBytes(b *testing.B) {
2530}
2631
2732func TestAddPicture (t * testing.T ) {
28- xlsx , err := OpenFile (filepath .Join ("test" , "Book1.xlsx" ))
33+ f , err := OpenFile (filepath .Join ("test" , "Book1.xlsx" ))
2934 if ! assert .NoError (t , err ) {
3035 t .FailNow ()
3136 }
3237
3338 // Test add picture to worksheet with offset and location hyperlink.
34- err = xlsx .AddPicture ("Sheet2" , "I9" , filepath .Join ("test" , "images" , "excel.jpg" ),
39+ err = f .AddPicture ("Sheet2" , "I9" , filepath .Join ("test" , "images" , "excel.jpg" ),
3540 `{"x_offset": 140, "y_offset": 120, "hyperlink": "#Sheet2!D8", "hyperlink_type": "Location"}` )
3641 if ! assert .NoError (t , err ) {
3742 t .FailNow ()
3843 }
3944
4045 // Test add picture to worksheet with offset, external hyperlink and positioning.
41- err = xlsx .AddPicture ("Sheet1" , "F21" , filepath .Join ("test" , "images" , "excel.jpg" ),
46+ err = f .AddPicture ("Sheet1" , "F21" , filepath .Join ("test" , "images" , "excel.jpg" ),
4247 `{"x_offset": 10, "y_offset": 10, "hyperlink": "https://github.com/360EntSecGroup-Skylar/excelize", "hyperlink_type": "External", "positioning": "oneCell"}` )
4348 if ! assert .NoError (t , err ) {
4449 t .FailNow ()
4550 }
4651
47- file , err := ioutil .ReadFile (filepath .Join ("test" , "images" , "excel.jpg " ))
52+ file , err := ioutil .ReadFile (filepath .Join ("test" , "images" , "excel.png " ))
4853 if ! assert .NoError (t , err ) {
4954 t .FailNow ()
5055 }
5156
5257 // Test add picture to worksheet from bytes.
53- assert .NoError (t , xlsx .AddPictureFromBytes ("Sheet1" , "Q1" , "" , "Excel Logo" , ".jpg " , file ))
58+ assert .NoError (t , f .AddPictureFromBytes ("Sheet1" , "Q1" , "" , "Excel Logo" , ".png " , file ))
5459 // Test add picture to worksheet from bytes with illegal cell coordinates.
55- assert .EqualError (t , xlsx .AddPictureFromBytes ("Sheet1" , "A" , "" , "Excel Logo" , ".jpg" , file ), `cannot convert cell "A" to coordinates: invalid cell name "A"` )
60+ assert .EqualError (t , f .AddPictureFromBytes ("Sheet1" , "A" , "" , "Excel Logo" , ".png" , file ), `cannot convert cell "A" to coordinates: invalid cell name "A"` )
61+
62+ assert .NoError (t , f .AddPicture ("Sheet1" , "Q8" , filepath .Join ("test" , "images" , "excel.gif" ), "" ))
63+ assert .NoError (t , f .AddPicture ("Sheet1" , "Q15" , filepath .Join ("test" , "images" , "excel.jpg" ), "" ))
64+ assert .NoError (t , f .AddPicture ("Sheet1" , "Q22" , filepath .Join ("test" , "images" , "excel.tif" ), "" ))
5665
5766 // Test write file to given path.
58- assert .NoError (t , xlsx .SaveAs (filepath .Join ("test" , "TestAddPicture.xlsx" )))
67+ assert .NoError (t , f .SaveAs (filepath .Join ("test" , "TestAddPicture.xlsx" )))
5968}
6069
6170func TestAddPictureErrors (t * testing.T ) {
0 commit comments