forked from p30928647/excelize
This closes #1503, case-insensitive for the file extension name
This commit is contained in:
parent
a34c81e1cc
commit
5878fbd282
5
file.go
5
file.go
|
@ -18,6 +18,7 @@ import (
|
|||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
|
@ -73,7 +74,7 @@ func (f *File) SaveAs(name string, opts ...Options) error {
|
|||
return ErrMaxFilePathLength
|
||||
}
|
||||
f.Path = name
|
||||
if _, ok := supportedContentTypes[filepath.Ext(f.Path)]; !ok {
|
||||
if _, ok := supportedContentTypes[strings.ToLower(filepath.Ext(f.Path))]; !ok {
|
||||
return ErrWorkbookFileFormat
|
||||
}
|
||||
file, err := os.OpenFile(filepath.Clean(name), os.O_WRONLY|os.O_TRUNC|os.O_CREATE, os.ModePerm)
|
||||
|
@ -116,7 +117,7 @@ func (f *File) WriteTo(w io.Writer, opts ...Options) (int64, error) {
|
|||
f.options = &opts[i]
|
||||
}
|
||||
if len(f.Path) != 0 {
|
||||
contentType, ok := supportedContentTypes[filepath.Ext(f.Path)]
|
||||
contentType, ok := supportedContentTypes[strings.ToLower(filepath.Ext(f.Path))]
|
||||
if !ok {
|
||||
return 0, ErrWorkbookFileFormat
|
||||
}
|
||||
|
|
|
@ -151,7 +151,7 @@ func (f *File) AddPicture(sheet, cell, name string, opts *GraphicOptions) error
|
|||
if _, err = os.Stat(name); os.IsNotExist(err) {
|
||||
return err
|
||||
}
|
||||
ext, ok := supportedImageTypes[path.Ext(name)]
|
||||
ext, ok := supportedImageTypes[strings.ToLower(path.Ext(name))]
|
||||
if !ok {
|
||||
return ErrImgExt
|
||||
}
|
||||
|
@ -202,7 +202,7 @@ func (f *File) AddPicture(sheet, cell, name string, opts *GraphicOptions) error
|
|||
func (f *File) AddPictureFromBytes(sheet, cell string, pic *Picture) error {
|
||||
var drawingHyperlinkRID int
|
||||
var hyperlinkType string
|
||||
ext, ok := supportedImageTypes[pic.Extension]
|
||||
ext, ok := supportedImageTypes[strings.ToLower(pic.Extension)]
|
||||
if !ok {
|
||||
return ErrImgExt
|
||||
}
|
||||
|
@ -659,7 +659,7 @@ func (f *File) getPicture(row, col int, drawingXML, drawingRelationships string)
|
|||
if err = nil; deTwoCellAnchor.From != nil && deTwoCellAnchor.Pic != nil {
|
||||
if deTwoCellAnchor.From.Col == col && deTwoCellAnchor.From.Row == row {
|
||||
drawRel = f.getDrawingRelationships(drawingRelationships, deTwoCellAnchor.Pic.BlipFill.Blip.Embed)
|
||||
if _, ok = supportedImageTypes[filepath.Ext(drawRel.Target)]; ok {
|
||||
if _, ok = supportedImageTypes[strings.ToLower(filepath.Ext(drawRel.Target))]; ok {
|
||||
pic := Picture{Extension: filepath.Ext(drawRel.Target), Format: &GraphicOptions{}}
|
||||
if buffer, _ := f.Pkg.Load(strings.ReplaceAll(drawRel.Target, "..", "xl")); buffer != nil {
|
||||
pic.File = buffer.([]byte)
|
||||
|
@ -690,7 +690,7 @@ func (f *File) getPicturesFromWsDr(row, col int, drawingRelationships string, ws
|
|||
if anchor.From.Col == col && anchor.From.Row == row {
|
||||
if drawRel = f.getDrawingRelationships(drawingRelationships,
|
||||
anchor.Pic.BlipFill.Blip.Embed); drawRel != nil {
|
||||
if _, ok = supportedImageTypes[filepath.Ext(drawRel.Target)]; ok {
|
||||
if _, ok = supportedImageTypes[strings.ToLower(filepath.Ext(drawRel.Target))]; ok {
|
||||
pic := Picture{Extension: filepath.Ext(drawRel.Target), Format: &GraphicOptions{}}
|
||||
if buffer, _ := f.Pkg.Load(strings.ReplaceAll(drawRel.Target, "..", "xl")); buffer != nil {
|
||||
pic.File = buffer.([]byte)
|
||||
|
|
2
sheet.go
2
sheet.go
|
@ -525,7 +525,7 @@ func (f *File) SetSheetBackgroundFromBytes(sheet, extension string, picture []by
|
|||
// setSheetBackground provides a function to set background picture by given
|
||||
// worksheet name, file name extension and image data.
|
||||
func (f *File) setSheetBackground(sheet, extension string, file []byte) error {
|
||||
imageType, ok := supportedImageTypes[extension]
|
||||
imageType, ok := supportedImageTypes[strings.ToLower(extension)]
|
||||
if !ok {
|
||||
return ErrImgExt
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue