浏览代码

fix:设置表格默认宽度

zqbao 6 月之前
父节点
当前提交
47af567e08
共有 1 个文件被更改,包括 29 次插入6 次删除
  1. 29 6
      services/data/excel/mixed_table.go

+ 29 - 6
services/data/excel/mixed_table.go

@@ -465,12 +465,41 @@ func GetMixedTableCellData(mixedTableReq request.MixedTableReq, lang string) (ne
 	if err != nil {
 		return
 	}
+	config = setDefaultCellWidth(config)
 
 	newMixedTableCellDataList = config
 
 	return
 }
 
+func setDefaultCellWidth(config [][]request.MixedTableCellDataReq) (newConfig [][]request.MixedTableCellDataReq) {
+	newConfig = config
+	for i, row := range config {
+		for j, cell := range row {
+			var styleConf request.MixCellShowStyle
+			if cell.ShowStyle == `` {
+				styleConf = request.MixCellShowStyle{
+					Width: 140,
+				}
+			} else {
+				err := json.Unmarshal([]byte(cell.ShowStyle), &styleConf)
+				if err != nil {
+					continue
+				}
+				if styleConf.Width == 0 {
+					styleConf.Width = 140
+				}
+			}
+			tmpStyleConf, err := json.Marshal(styleConf)
+			if err == nil {
+				cell.ShowStyle = string(tmpStyleConf)
+			}
+			newConfig[i][j] = cell
+		}
+	}
+	return
+}
+
 // getCalculateValue 获取公式计算的结果
 func getCalculateValueByCell(calculateCellMap map[string]Cell, key string, cellKeyValMap map[string]float64) (val float64, has bool, err error, errMsg string) {
 	// 单元格的标签名
@@ -1203,9 +1232,6 @@ func handleMixCellShowStyle(showStyleList []string, calculateCellMap map[string]
 				if styleConf.GlObj != nil {
 					styleConf.GlObj = nil
 				}
-				if styleConf.Width == 0 {
-					styleConf.Width = 140
-				}
 				tmpStyleConf, err := json.Marshal(styleConf)
 				if err == nil {
 					cell.ShowStyle = string(tmpStyleConf)
@@ -1230,9 +1256,6 @@ func handleMixCellShowStyle(showStyleList []string, calculateCellMap map[string]
 			if styleConf.GlObj != nil {
 				styleConf.GlObj = nil
 			}
-			if styleConf.Width == 0 {
-				styleConf.Width = 140
-			}
 			tmpStyleConf, err := json.Marshal(styleConf)
 			if err == nil {
 				cell.ShowStyle = string(tmpStyleConf)