generated from kedaya_haitao/template
This commit is contained in:
parent
00e4f26d71
commit
9e5e4d7d27
@ -158,7 +158,7 @@ func addRow(f *excelize.File, sheetName string, rowIndex int, article *v2.Articl
|
||||
// 填充数据
|
||||
cells := []interface{}{
|
||||
article.Name,
|
||||
"", // 图片单元格留空,后面会添加图片
|
||||
article.Image, // 图片单元格留空,后面会添加图片
|
||||
usProvider.Cost.OriginalPrice,
|
||||
usProvider.Cost.FinalPrice,
|
||||
caProvider.Cost.OriginalPrice,
|
||||
@ -181,34 +181,34 @@ func addRow(f *excelize.File, sheetName string, rowIndex int, article *v2.Articl
|
||||
linkCell, _ := excelize.CoordinatesToCellName(1, rowIndex)
|
||||
_ = f.SetCellHyperLink(sheetName, linkCell, caProvider.Link, "External")
|
||||
|
||||
if len(article.Image) > 0 {
|
||||
imgCell, _ := excelize.CoordinatesToCellName(2, rowIndex)
|
||||
|
||||
// 下载图片
|
||||
imgData, err := downloadImage(article.Image)
|
||||
if err != nil {
|
||||
logrus.Warnf("下载图片失败 %s: %v", article.Image, err)
|
||||
// 如果下载失败,至少显示URL
|
||||
_ = f.SetCellValue(sheetName, imgCell, article.Image)
|
||||
} else {
|
||||
// 添加图片到Excel
|
||||
if err = f.AddPictureFromBytes(sheetName, imgCell, &excelize.Picture{
|
||||
Extension: ".jpg",
|
||||
File: imgData,
|
||||
Format: &excelize.GraphicOptions{
|
||||
AutoFit: true,
|
||||
ScaleX: 0.5,
|
||||
ScaleY: 0.5,
|
||||
Positioning: "oneCell",
|
||||
},
|
||||
}); err != nil {
|
||||
logrus.Warnf("添加图片到Excel失败: %v", err)
|
||||
// 如果添加失败,显示URL
|
||||
_ = f.SetCellValue(sheetName, imgCell, article.Image)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//if len(article.Image) > 0 {
|
||||
// imgCell, _ := excelize.CoordinatesToCellName(2, rowIndex)
|
||||
//
|
||||
// // 下载图片
|
||||
// imgData, err := downloadImage(article.Image)
|
||||
// if err != nil {
|
||||
// logrus.Warnf("下载图片失败 %s: %v", article.Image, err)
|
||||
// // 如果下载失败,至少显示URL
|
||||
// _ = f.SetCellValue(sheetName, imgCell, article.Image)
|
||||
// } else {
|
||||
// // 添加图片到Excel
|
||||
// if err = f.AddPictureFromBytes(sheetName, imgCell, &excelize.Picture{
|
||||
// Extension: ".jpg",
|
||||
// File: imgData,
|
||||
// Format: &excelize.GraphicOptions{
|
||||
// AutoFit: true,
|
||||
// ScaleX: 0.5,
|
||||
// ScaleY: 0.5,
|
||||
// Positioning: "oneCell",
|
||||
// },
|
||||
// }); err != nil {
|
||||
// logrus.Warnf("添加图片到Excel失败: %v", err)
|
||||
// // 如果添加失败,显示URL
|
||||
// _ = f.SetCellValue(sheetName, imgCell, article.Image)
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user