diff --git a/internal/tools/bbxt/bbxt.go b/internal/tools/bbxt/bbxt.go index cd1024f..d7d00ef 100644 --- a/internal/tools/bbxt/bbxt.go +++ b/internal/tools/bbxt/bbxt.go @@ -7,6 +7,7 @@ import ( "sort" "time" + "github.com/gofiber/fiber/v2/log" "github.com/xuri/excelize/v2" ) @@ -104,12 +105,11 @@ func (b *BbxtTools) StatisOursProductLossSumTotal(ct []string) (err error) { //总量生成excel if len(total) > 0 { filePath := b.cacheDir + "/kshj_total" + fmt.Sprintf("%d", time.Now().Unix()) + ".xlsx" - err = b.SimpleFillExcel(b.excelTempDir+"/"+"kshj_total_v2.xlsx", filePath, total) + err = b.SimpleFillExcel(b.excelTempDir+"/"+"kshj_total.xlsx", filePath, total) } if len(gt) > 0 { filePath := b.cacheDir + "/kshj_gt" + fmt.Sprintf("%d", time.Now().Unix()) + ".xlsx" - // err = b.SimpleFillExcel(b.excelTempDir+"/"+"kshj_gt.xlsx", filePath, total) err = b.resellerDetailFillExcel(b.excelTempDir+"/"+"kshj_gt.xlsx", filePath, gt) } return err @@ -126,6 +126,20 @@ func (b *BbxtTools) SimpleFillExcel(templatePath, outputPath string, dataSlice i sheet := f.GetSheetName(0) + // 1.1 获取第二行模板样式 + resellerTplRow := 2 + styleIDReseller, err := f.GetCellStyle(sheet, fmt.Sprintf("A%d", resellerTplRow)) + if err != nil { + log.Errorf("获取分销商总计样式失败: %v", err) + styleIDReseller = 0 + } + // 1.2 获取分销商总计行高 + rowHeightReseller, err := f.GetRowHeight(sheet, resellerTplRow) + if err != nil { + log.Errorf("获取分销商总计行高失败: %v", err) + rowHeightReseller = 31 // 默认高度 + } + // 2. 反射获取切片数据 v := reflect.ValueOf(dataSlice) if v.Kind() != reflect.Slice { @@ -157,12 +171,19 @@ func (b *BbxtTools) SimpleFillExcel(templatePath, outputPath string, dataSlice i } else { rowData = []interface{}{item} } + // 4.1 设置行高 + f.SetRowHeight(sheet, currentRow, rowHeightReseller) // 5. 填充到Excel for col, value := range rowData { cell := fmt.Sprintf("%c%d", 'A'+col, currentRow) f.SetCellValue(sheet, cell, value) } + + // 5.1 使用第二行模板样式 + if styleIDReseller != 0 { + f.SetCellStyle(sheet, fmt.Sprintf("A%d", currentRow), fmt.Sprintf("B%d", currentRow), styleIDReseller) + } } // 6. 保存 @@ -188,22 +209,24 @@ func (b *BbxtTools) resellerDetailFillExcel(templatePath, outputPath string, dat resellerTplRow := 2 styleIDReseller, err := f.GetCellStyle(sheet, fmt.Sprintf("A%d", resellerTplRow)) if err != nil { - // 如果获取失败,就不应用样式,或者记录日志,这里选择忽略错误继续 + log.Errorf("获取分销商总计样式失败: %v", err) styleIDReseller = 0 } rowHeightReseller, err := f.GetRowHeight(sheet, resellerTplRow) if err != nil { + log.Errorf("获取分销商总计行高失败: %v", err) rowHeightReseller = 31 // 默认高度 } // 获取模板样式2:第三行-产品亏损明细 productTplRow := 3 styleIDProduct, err := f.GetCellStyle(sheet, fmt.Sprintf("A%d", productTplRow)) if err != nil { - // 如果获取失败,就不应用样式,或者记录日志,这里选择忽略错误继续 + log.Errorf("获取商品详情样式失败: %v", err) styleIDProduct = 0 } rowHeightProduct, err := f.GetRowHeight(sheet, productTplRow) if err != nil { + log.Errorf("获取商品详情行高失败: %v", err) rowHeightProduct = 25 // 默认高度 } diff --git a/tmpl/excel_temp/kshj_gt.xlsx b/tmpl/excel_temp/kshj_gt.xlsx index 9ab76f5..c826635 100755 Binary files a/tmpl/excel_temp/kshj_gt.xlsx and b/tmpl/excel_temp/kshj_gt.xlsx differ diff --git a/tmpl/excel_temp/kshj_total.xlsx b/tmpl/excel_temp/kshj_total.xlsx old mode 100644 new mode 100755 index 2035ef9..b29ae47 Binary files a/tmpl/excel_temp/kshj_total.xlsx and b/tmpl/excel_temp/kshj_total.xlsx differ