|
|
|
|
@ -4,16 +4,22 @@ import (
|
|
|
|
|
"cu-helper/wms/service"
|
|
|
|
|
"fmt"
|
|
|
|
|
"github.com/mizuki1412/go-core-kit/library/mathkit"
|
|
|
|
|
"github.com/mizuki1412/go-core-kit/service/configkit"
|
|
|
|
|
"github.com/mizuki1412/go-core-kit/service/logkit"
|
|
|
|
|
"github.com/spf13/cast"
|
|
|
|
|
"github.com/xuri/excelize/v2"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"strconv"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func GenExcelFile(m1 map[string]*service.HighOptLossUnder, m2 map[string]*service.HighOptLossHistory) {
|
|
|
|
|
// Open the Excel file
|
|
|
|
|
f, err := excelize.OpenFile("/Users/leo/Documents/光衰通报/光衰/2025/光衰通报(5月30日).xlsx")
|
|
|
|
|
open := configkit.GetString("loss.open", "")
|
|
|
|
|
if open == "" {
|
|
|
|
|
open = "/Users/leo/Documents/光衰通报/光衰/2025/光衰通报(11月5日).xlsx"
|
|
|
|
|
}
|
|
|
|
|
f, err := excelize.OpenFile(open)
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
return
|
|
|
|
|
@ -123,9 +129,9 @@ func GenExcelFile(m1 map[string]*service.HighOptLossUnder, m2 map[string]*servic
|
|
|
|
|
NumFmt: 10, // 或使用自定义格式代码:"0.00%"
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Cut and paste data from E4:E23 to C4:C23
|
|
|
|
|
// Cut and paste data from E4:E25 to C4:C25
|
|
|
|
|
//TODO
|
|
|
|
|
for i := 4; i <= 23; i++ {
|
|
|
|
|
for i := 4; i <= 25; i++ {
|
|
|
|
|
eCell := "E" + strconv.Itoa(i)
|
|
|
|
|
cCell := "C" + strconv.Itoa(i)
|
|
|
|
|
value, _ := f.GetCellValue("汇总", eCell)
|
|
|
|
|
@ -133,9 +139,9 @@ func GenExcelFile(m1 map[string]*service.HighOptLossUnder, m2 map[string]*servic
|
|
|
|
|
f.SetCellValue("汇总", eCell, "")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Populate E4:L23 with data from the map
|
|
|
|
|
// Populate E4:L25 with data from the map
|
|
|
|
|
//TODO
|
|
|
|
|
for i := 4; i <= 23; i++ {
|
|
|
|
|
for i := 4; i <= 25; i++ {
|
|
|
|
|
bCell := "B" + strconv.Itoa(i)
|
|
|
|
|
key, _ := f.GetCellValue("汇总", bCell)
|
|
|
|
|
if data, ok := m1[key]; ok {
|
|
|
|
|
@ -234,9 +240,9 @@ func GenExcelFile(m1 map[string]*service.HighOptLossUnder, m2 map[string]*servic
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Calculate D4:D23 as C-E
|
|
|
|
|
// Calculate D4:D25 as C-E
|
|
|
|
|
//TODO
|
|
|
|
|
for i := 4; i <= 23; i++ {
|
|
|
|
|
for i := 4; i <= 25; i++ {
|
|
|
|
|
cCell := "C" + strconv.Itoa(i)
|
|
|
|
|
eCell := "E" + strconv.Itoa(i)
|
|
|
|
|
dCell := "D" + strconv.Itoa(i)
|
|
|
|
|
@ -261,19 +267,19 @@ func GenExcelFile(m1 map[string]*service.HighOptLossUnder, m2 map[string]*servic
|
|
|
|
|
f.SetCellStyle("汇总", dCell, dCell, styleGreen)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Sum columns C:H and place the results in row 24
|
|
|
|
|
// Sum columns C:H and place the results in row 26
|
|
|
|
|
for col := 'C'; col <= 'L'; col++ {
|
|
|
|
|
//TODO
|
|
|
|
|
sumCell := string(col) + "24"
|
|
|
|
|
sumCell := string(col) + "26"
|
|
|
|
|
//TODO
|
|
|
|
|
sumFormula := fmt.Sprintf("SUM(%s4:%s23)", string(col), string(col))
|
|
|
|
|
sumFormula := fmt.Sprintf("SUM(%s4:%s25)", string(col), string(col))
|
|
|
|
|
f.SetCellFormula("汇总", sumCell, sumFormula)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Recalculate the sum for each cell to ensure it appears without manual intervention
|
|
|
|
|
for col := 'C'; col <= 'L'; col++ {
|
|
|
|
|
//TODO
|
|
|
|
|
sumCell := string(col) + "24"
|
|
|
|
|
sumCell := string(col) + "26"
|
|
|
|
|
value, err := f.CalcCellValue("汇总", sumCell)
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
@ -282,16 +288,17 @@ func GenExcelFile(m1 map[string]*service.HighOptLossUnder, m2 map[string]*servic
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//TODO 3行
|
|
|
|
|
done, _ := f.GetCellValue("汇总", "K24")
|
|
|
|
|
total, _ := f.GetCellValue("汇总", "L24")
|
|
|
|
|
f.SetCellValue("汇总", "M24", mathkit.FloatRound(cast.ToFloat64(done)/cast.ToFloat64(total), 4))
|
|
|
|
|
done, _ := f.GetCellValue("汇总", "K26")
|
|
|
|
|
total, _ := f.GetCellValue("汇总", "L26")
|
|
|
|
|
f.SetCellValue("汇总", "M26", mathkit.FloatRound(cast.ToFloat64(done)/cast.ToFloat64(total), 4))
|
|
|
|
|
|
|
|
|
|
//设置表头
|
|
|
|
|
content := fmt.Sprintf("西湖智家光衰通报:%s", time.Now().Format("1月2日"))
|
|
|
|
|
f.SetCellValue("汇总", "A1", content)
|
|
|
|
|
|
|
|
|
|
// Save the file
|
|
|
|
|
if err := f.SaveAs("/Users/leo/Documents/光衰通报/光衰/2025/光衰通报(" + time.Now().Format("1月2日") + ").xlsx"); err != nil {
|
|
|
|
|
save := filepath.Dir(open) + "/光衰通报(" + time.Now().Format("1月2日") + ").xlsx"
|
|
|
|
|
if err := f.SaveAs(save); err != nil {
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
}
|
|
|
|
|
logkit.Info("生成结束...")
|
|
|
|
|
|