zhangqian
2024-06-13 6244276d1943d99439bdb9a4f71a1d733f85f3f9
增加样式,修复错误
3个文件已修改
36 ■■■■■ 已修改文件
.gitignore 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
conf/config.yaml 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/location_forms.go 33 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.gitignore
@@ -29,3 +29,4 @@
wms*
WMS*
*.bleve
conf/config.yaml
conf/config.yaml
@@ -11,7 +11,7 @@
  companyName: jialian
db:
  #  dsn: root:c++java123@tcp(192.168.20.119:3306)/wms?charset=utf8&parseTime=True&loc=Local
  dsn: root:c++java123@tcp(127.0.0.1:3306)/aps_server2?charset=utf8&parseTime=True&loc=Local
  dsn: root:c++java123@tcp(192.168.20.119:3306)/aps_server2?charset=utf8&parseTime=True&loc=Local
  logMode: true
  maxIdleCon: 20
  maxOpenCon: 100
service/location_forms.go
@@ -34,7 +34,8 @@
        resp.Unit = amount.Product.Unit
        resp.Value = resp.Amount.Mul(amount.Product.Cost)
        if *amount.Product.MoreUnit {
        moreUnit := amount.Product.MoreUnit
        if moreUnit != nil && *moreUnit {
            resp.AmountMoreUnits = CreateMoreUnit(resp.Amount, amount.Product.MoreUnitList)
        }
@@ -111,6 +112,7 @@
        } else if childHeaders, ok := h.(map[string][]string); ok {
            for title, list := range childHeaders {
                f.SetCellValue("Sheet1", getColumnAlphabet(i)+"1", title)
                err = f.MergeCell("Sheet1", getColumnAlphabet(i)+"1", getColumnAlphabet(i-1+len(list))+"1") // 合并单元格
                for _, t := range list {
                    f.SetCellValue("Sheet1", getColumnAlphabet(i)+"2", t)
                    i++
@@ -119,13 +121,40 @@
        }
    }
    // 设置表头样式
    style := &excelize.Style{
        Border: nil,
        Fill: excelize.Fill{
            Type:    "pattern",
            Pattern: 1,
            Shading: 0,
        },
        Font: &excelize.Font{
            Bold: true,
        },
        Alignment: &excelize.Alignment{
            Horizontal: "center",
        },
    }
    titleStyle, err := f.NewStyle(style)
    if err != nil {
        return
    }
    lastColumn := getColumnAlphabet(i)
    f.SetCellStyle("Sheet1", "A1", lastColumn+"2", titleStyle)
    // 设置列宽
    f.SetColWidth("Sheet1", "A", "C", 30)
    f.SetColWidth("Sheet1", "D", lastColumn, 15)
    for i, v := range dataList {
        column := strconv.Itoa(i + 2)
        column := strconv.Itoa(i + 3)
        f.SetCellValue("Sheet1", "A"+column, v.LocationName)
        f.SetCellValue("Sheet1", "B"+column, v.ProductName)
        f.SetCellValue("Sheet1", "C"+column, v.ProductTypeName)
        f.SetCellValue("Sheet1", "D"+column, v.Amount)
        FillMoreUnitToExcel(v.Amount, v.AmountMoreUnits, 4, i+2, f)
        f.SetCellValue("Sheet1", "H"+column, v.Value)
    }
    fileName = fmt.Sprintf("位置报表%s.xlsx", time.Now().Format("2006-01-02-1504"))