update 不在尝试添加图片
All checks were successful
Build image / build (push) Successful in 1m5s

This commit is contained in:
timerzz 2025-03-30 21:29:26 +08:00
parent 00e4f26d71
commit 9e5e4d7d27

View File

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