代码拉取完成,页面将自动刷新
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{})
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。