@@ -113,7 +113,7 @@ func (f *File) AddPicture(sheet, cell, picture, format string) error {
113
113
if _ , err = os .Stat (picture ); os .IsNotExist (err ) {
114
114
return err
115
115
}
116
- ext , ok := supportImageTypes [path .Ext (picture )]
116
+ ext , ok := supportedImageTypes [path .Ext (picture )]
117
117
if ! ok {
118
118
return ErrImgExt
119
119
}
@@ -154,7 +154,7 @@ func (f *File) AddPicture(sheet, cell, picture, format string) error {
154
154
func (f * File ) AddPictureFromBytes (sheet , cell , format , name , extension string , file []byte ) error {
155
155
var drawingHyperlinkRID int
156
156
var hyperlinkType string
157
- ext , ok := supportImageTypes [extension ]
157
+ ext , ok := supportedImageTypes [extension ]
158
158
if ! ok {
159
159
return ErrImgExt
160
160
}
@@ -366,23 +366,20 @@ func (f *File) addMedia(file []byte, ext string) string {
366
366
// setContentTypePartImageExtensions provides a function to set the content
367
367
// type for relationship parts and the Main Document part.
368
368
func (f * File ) setContentTypePartImageExtensions () {
369
- imageTypes := map [string ]bool {"jpeg" : false , "png" : false , "gif" : false , "tiff" : false }
369
+ imageTypes := map [string ]string {"jpeg" : "image/" , "png" : "image/" , "gif" : "image/" , "tiff" : "image/" , "emf" : "image/x-" }
370
370
content := f .contentTypesReader ()
371
371
content .Lock ()
372
372
defer content .Unlock ()
373
- for _ , v := range content .Defaults {
374
- _ , ok := imageTypes [v .Extension ]
375
- if ok {
376
- imageTypes [v .Extension ] = true
373
+ for _ , file := range content .Defaults {
374
+ if _ , ok := imageTypes [file .Extension ]; ok {
375
+ delete (imageTypes , file .Extension )
377
376
}
378
377
}
379
- for k , v := range imageTypes {
380
- if ! v {
381
- content .Defaults = append (content .Defaults , xlsxDefault {
382
- Extension : k ,
383
- ContentType : "image/" + k ,
384
- })
385
- }
378
+ for extension , prefix := range imageTypes {
379
+ content .Defaults = append (content .Defaults , xlsxDefault {
380
+ Extension : extension ,
381
+ ContentType : prefix + extension ,
382
+ })
386
383
}
387
384
}
388
385
@@ -576,7 +573,7 @@ func (f *File) getPicture(row, col int, drawingXML, drawingRelationships string)
576
573
if err = nil ; deTwoCellAnchor .From != nil && deTwoCellAnchor .Pic != nil {
577
574
if deTwoCellAnchor .From .Col == col && deTwoCellAnchor .From .Row == row {
578
575
drawRel = f .getDrawingRelationships (drawingRelationships , deTwoCellAnchor .Pic .BlipFill .Blip .Embed )
579
- if _ , ok = supportImageTypes [filepath .Ext (drawRel .Target )]; ok {
576
+ if _ , ok = supportedImageTypes [filepath .Ext (drawRel .Target )]; ok {
580
577
ret = filepath .Base (drawRel .Target )
581
578
if buffer , _ := f .Pkg .Load (strings .Replace (drawRel .Target , ".." , "xl" , - 1 )); buffer != nil {
582
579
buf = buffer .([]byte )
@@ -605,7 +602,7 @@ func (f *File) getPictureFromWsDr(row, col int, drawingRelationships string, wsD
605
602
if anchor .From .Col == col && anchor .From .Row == row {
606
603
if drawRel = f .getDrawingRelationships (drawingRelationships ,
607
604
anchor .Pic .BlipFill .Blip .Embed ); drawRel != nil {
608
- if _ , ok = supportImageTypes [filepath .Ext (drawRel .Target )]; ok {
605
+ if _ , ok = supportedImageTypes [filepath .Ext (drawRel .Target )]; ok {
609
606
ret = filepath .Base (drawRel .Target )
610
607
if buffer , _ := f .Pkg .Load (strings .Replace (drawRel .Target , ".." , "xl" , - 1 )); buffer != nil {
611
608
buf = buffer .([]byte )
0 commit comments