Kaynağa Gözat

Merge branch 'bzq/excel_size' of eta_gn_server/eta_api into master

baoziqiang 1 ay önce
ebeveyn
işleme
884180a436

+ 3 - 0
models/data_manage/excel/request/mixed_table.go

@@ -134,10 +134,13 @@ type MixCellShowStyle struct {
 	Pn              int         `description:"小数点位数增加或减少,正数表述增加,负数表示减少" json:"pn"`
 	Nt              string      `description:"变换类型:number 小数点位数改变,percent百分比," json:"nt"`
 	GlObj           interface{} `description:"公式对象:1:数值,2:百分比,3:文本" json:"glObj"`
+	Width           float64     `description:"单元格宽度" json:"width"`
+	Height          float64     `description:"单元格高度" json:"height"`
 	Decimal         *int        `description:"小数点位数" json:"decimal"`
 	Last            string      `description:"起始操作:nt|decimal" json:"last"`
 	Color           string      `description:"颜色值,#RRG" json:"color"`
 	BackgroundColor string      `description:"背景颜色值,#RRG" json:"background-color"`
+	Align           string      `description:"对齐方式:left|center|right" json:"align"`
 }
 
 type DateDataBeforeAfterReq struct {

+ 34 - 0
services/data/excel/mixed_table.go

@@ -466,11 +466,45 @@ func GetMixedTableCellData(mixedTableReq request.MixedTableReq, lang string) (ne
 		return
 	}
 
+	config = setDefaultCellSize(config)
+
 	newMixedTableCellDataList = config
 
 	return
 }
 
+func setDefaultCellSize(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,
+					Height: 35,
+				}
+			} else {
+				err := json.Unmarshal([]byte(cell.ShowStyle), &styleConf)
+				if err != nil {
+					continue
+				}
+				if styleConf.Width == 0 {
+					styleConf.Width = 140
+				}
+				if styleConf.Height == 0 {
+					styleConf.Height = 35
+				}
+			}
+			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) {
 	// 单元格的标签名

+ 11 - 0
services/excel/lucky_sheet.go

@@ -1756,6 +1756,17 @@ func GetTableDataByMixedTableData(config [][]request.MixedTableCellDataReq, hide
 					if styleConfig.Color != "" {
 						tmp.FontColor = styleConfig.Color
 					}
+					switch styleConfig.Align {
+					case "center":
+						tmp.HorizontalType = 0
+						tmp.Ht = 0
+					case "left":
+						tmp.HorizontalType = 1
+						tmp.Ht = 1
+					case "right":
+						tmp.HorizontalType = 2
+						tmp.Ht = 2
+					}
 					tmp.Monitor = showFormatValue
 					// 如果没有showValue, 则使用value
 					if cell.ShowValue == "" {