Ai
1 Star 0 Fork 0

Alvin Rex/excel

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
pic.go 1.02 KB
一键复制 编辑 原始数据 按行查看 历史
cuishu 提交于 2023-07-14 21:42 +08:00 . 更新到 excelize v2.7.1, trim 表头空白字符
package excel
import (
"bytes"
"errors"
"reflect"
"github.com/gabriel-vasile/mimetype"
"github.com/xuri/excelize/v2"
)
type PicFormat excelize.GraphicOptions
type Picture struct {
Name string
File []byte
Format *PicFormat
withPath bool
}
func getPicExtName(mime string) (string, error) {
switch mime {
case "image/jpeg":
return ".jpeg", nil
case "image/png":
return ".png", nil
default:
return "", errors.New("invalid image type: must be jpeg or png")
}
}
func NewPicture(path string, format *PicFormat) Picture {
return Picture{
Name: path,
Format: format,
withPath: true,
}
}
func NewPictureFromBytes(file []byte, format *PicFormat) (Picture, error) {
extName, err := getPicExtName(mimetype.Detect(file).String())
if err != nil {
return Picture{}, err
}
return Picture{
Name: extName,
File: file,
Format: format,
withPath: false,
}, nil
}
func (pic Picture) Buffer() *bytes.Buffer {
return bytes.NewBuffer(pic.File)
}
var picReflectType = reflect.TypeOf(Picture{})
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rexvonai/excel.git
git@gitee.com:rexvonai/excel.git
rexvonai
excel
excel
825567353a5e

搜索帮助