lucky_sheet.go 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123
  1. package excel
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "hongze/hongze_chart_lib/models/request"
  6. "hongze/hongze_chart_lib/utils"
  7. "reflect"
  8. "sort"
  9. "strconv"
  10. )
  11. type LuckySheetDataBak struct {
  12. CalcChain []interface{} `json:"calcChain" description:"公式链"`
  13. CellData []LuckySheetCellData `json:"celldata" description:"单元格数据"`
  14. ChWidth int64 `json:"ch_width" description:"工作表区域的宽度"`
  15. Config struct {
  16. BorderInfo []struct {
  17. BorderType string `json:"borderType" description:""`
  18. Color string `json:"color" description:""`
  19. Range []struct {
  20. Column []int64 `json:"column" description:""`
  21. Row []int64 `json:"row" description:""`
  22. } `json:"range" description:""`
  23. RangeType string `json:"rangeType" description:""`
  24. Style string `json:"style" description:""`
  25. Value struct {
  26. B struct {
  27. Color string `json:"color" description:""`
  28. Style string `json:"style" description:""`
  29. } `json:"b" description:""`
  30. ColIndex int64 `json:"col_index" description:""`
  31. L struct {
  32. Color string `json:"color" description:""`
  33. Style string `json:"style" description:""`
  34. } `json:"l" description:""`
  35. R struct {
  36. Color string `json:"color" description:""`
  37. Style string `json:"style" description:""`
  38. } `json:"r" description:""`
  39. RowIndex int64 `json:"row_index" description:""`
  40. T struct {
  41. Color string `json:"color" description:""`
  42. Style string `json:"style" description:""`
  43. } `json:"t" description:""`
  44. } `json:"value" description:"" description:""`
  45. } `json:"borderInfo" description:""`
  46. Colhidden struct{} `json:"colhidden" description:""`
  47. Columnlen map[string]float64 `json:"columnlen" description:""`
  48. CustomHeight struct {
  49. Zero int64 `json:"0"`
  50. } `json:"customHeight" description:""`
  51. CustomWidth struct {
  52. Two int64 `json:"2" description:""`
  53. } `json:"customWidth" description:""`
  54. Merge struct{} `json:"merge" description:""`
  55. Rowlen map[string]float64 `json:"rowlen" description:""`
  56. } `json:"config" description:""`
  57. Data [][]struct {
  58. Ct struct {
  59. Fa string `json:"fa"`
  60. T string `json:"t"`
  61. } `json:"ct"`
  62. M string `json:"m"`
  63. V interface{} `json:"v"`
  64. } `json:"data" description:""`
  65. DataVerification struct{} `json:"dataVerification" description:""`
  66. Filter interface{} `json:"filter" description:""`
  67. FilterSelect interface{} `json:"filter_select" description:""`
  68. Hyperlink struct{} `json:"hyperlink" description:""`
  69. Images struct{} `json:"images" description:""`
  70. Index string `json:"index" description:""`
  71. JfgirdSelectSave []interface{} `json:"jfgird_select_save" description:""`
  72. LuckysheetAlternateformatSave []interface{} `json:"luckysheet_alternateformat_save" description:""`
  73. LuckysheetConditionformatSave []interface{} `json:"luckysheet_conditionformat_save" description:""`
  74. LuckysheetSelectSave []struct {
  75. Column []int64 `json:"column" description:""`
  76. ColumnFocus int64 `json:"column_focus" description:""`
  77. Height int64 `json:"height" description:""`
  78. HeightMove int64 `json:"height_move" description:""`
  79. Left int64 `json:"left" description:""`
  80. LeftMove int64 `json:"left_move" description:""`
  81. Row []int64 `json:"row" description:""`
  82. RowFocus int64 `json:"row_focus" description:""`
  83. Top int64 `json:"top" description:""`
  84. TopMove int64 `json:"top_move" description:""`
  85. Width int64 `json:"width" description:""`
  86. WidthMove int64 `json:"width_move" description:""`
  87. } `json:"luckysheet_select_save" description:"" description:""`
  88. LuckysheetSelectionRange []struct {
  89. Column []int64 `json:"column" description:""`
  90. Row []int64 `json:"row" description:""`
  91. } `json:"luckysheet_selection_range" description:""`
  92. RhHeight float64 `json:"rh_height" description:""`
  93. ScrollLeft float64 `json:"scrollLeft" description:""`
  94. ScrollTop float64 `json:"scrollTop" description:""`
  95. Status int64 `json:"status" description:""`
  96. Visibledatacolumn []int64 `json:"visibledatacolumn" description:""`
  97. Visibledatarow []int64 `json:"visibledatarow" description:""`
  98. ZoomRatio float64 `json:"zoomRatio" description:"sheet缩放比例"`
  99. }
  100. // LuckySheetData sheet表格数据
  101. type LuckySheetData struct {
  102. CellData []LuckySheetCellData `json:"celldata" description:"单元格数据"`
  103. ChWidth int64 `json:"ch_width" description:"工作表区域的宽度"`
  104. Config LuckySheetDataConfig `json:"config" description:""`
  105. //Index int `json:"index" description:"工作表索引"`
  106. RhHeight float64 `json:"rh_height" description:"工作表区域的高度"`
  107. ScrollLeft float64 `json:"scrollLeft" description:"左右滚动条位置"`
  108. ScrollTop float64 `json:"scrollTop" description:"上下滚动条位置"`
  109. Status int64 `json:"status" description:"激活状态"`
  110. VisibleDataColumn []int64 `json:"visibledatacolumn" description:"所有列的位置信息,递增的列位置数据,初始化无需设置"`
  111. VisibleDataRow []int64 `json:"visibledatarow" description:"所有行的位置信息,递增的行位置数据,初始化无需设置"`
  112. ZoomRatio float64 `json:"zoomRatio" description:"sheet缩放比例"`
  113. }
  114. // LuckySheetDataConfig sheet表单的配置
  115. type LuckySheetDataConfig struct {
  116. BorderInfo []LuckySheetDataConfigBorderInfo `json:"borderInfo" description:"边框"`
  117. Colhidden map[string]int64 `json:"colhidden" description:"隐藏列,示例值:\"colhidden\":{\"30\":0,\"31\":0}"`
  118. Columnlen map[string]float64 `json:"columnlen" description:"每个单元格的列宽"`
  119. //CustomHeight struct {
  120. // Zero int64 `json:"0"`
  121. //} `json:"customHeight" description:""`
  122. //CustomWidth struct {
  123. // Two int64 `json:"2" description:""`
  124. //} `json:"customWidth" description:""`
  125. Merge map[string]LuckySheetDataConfigMerge `json:"merge" description:"合并单元格"`
  126. Rowlen map[string]float64 `json:"rowlen" description:"每个单元格的行高"`
  127. }
  128. // LuckySheetDataConfigMerge 合并单元格设置
  129. type LuckySheetDataConfigMerge struct {
  130. Row int `json:"r" description:"行数"`
  131. Column int `json:"c" description:"列数"`
  132. Rs int `json:"rs" description:"合并的行数"`
  133. Cs int `json:"cs" description:"合并的列数"`
  134. }
  135. // LuckySheetDataConfigBorderInfo 单元格边框信息
  136. type LuckySheetDataConfigBorderInfo struct {
  137. BorderType string `json:"borderType" description:"边框类型 border-left | border-right | border-top | border-bottom | border-all | border-outside | border-inside | border-horizontal | border-vertical | border-none"`
  138. Color string `json:"color" description:"边框颜色 color: 16进制颜色值"`
  139. Range []struct {
  140. Column []int64 `json:"column" description:"行"`
  141. Row []int64 `json:"row" description:"列"`
  142. } `json:"range" description:"选区范围 range: 行列信息数组"`
  143. RangeType string `json:"rangeType" description:"选区 rangeType: range | cell "`
  144. Style string `json:"style" description:"边框粗细 style: 1 Thin | 2 Hair | 3 Dotted | 4 Dashed | 5 DashDot | 6 DashDotDot | 7 Double | 8 Medium | 9 MediumDashed | 10 MediumDashDot | 11 MediumDashDotDot | 12 SlantedDashDot | 13 Thick ,和aspose.cells的getLineStyle()的值对应的话,需要自己做个转换,参考 aspose.cells"`
  145. Value LuckySheetDataConfigBorderInfoCellValue `json:"value" description:"" description:"范围类型分单个单元格的数据"`
  146. }
  147. // LuckySheetDataConfigBorderInfoCellValue 单元格边框信息(范围类型为:单个单元格)
  148. type LuckySheetDataConfigBorderInfoCellValue struct {
  149. B LuckySheetDataConfigBorderInfoCell `json:"b" description:"下边框"`
  150. L LuckySheetDataConfigBorderInfoCell `json:"l" description:"左边框"`
  151. R LuckySheetDataConfigBorderInfoCell `json:"r" description:"右边框"`
  152. T LuckySheetDataConfigBorderInfoCell `json:"t" description:"上边框"`
  153. ColIndex int64 `json:"col_index" description:"第几行"`
  154. RowIndex int64 `json:"row_index" description:"第几列"`
  155. }
  156. // LuckySheetDataConfigBorderInfoCell 单元格边框信息(cell类型)
  157. type LuckySheetDataConfigBorderInfoCell struct {
  158. Color string `json:"color" description:"边框颜色 color: 16进制颜色值"`
  159. Style int `description:"边框粗细 style: 1 Thin | 2 Hair | 3 Dotted | 4 Dashed | 5 DashDot | 6 DashDotDot | 7 Double | 8 Medium | 9 MediumDashed | 10 MediumDashDot | 11 MediumDashDotDot | 12 SlantedDashDot | 13 Thick ,和aspose.cells的getLineStyle()的值对应的话,需要自己做个转换,参考 aspose.cells"`
  160. Sl interface{} `json:"style" description:"边框粗细 style: 1 Thin | 2 Hair | 3 Dotted | 4 Dashed | 5 DashDot | 6 DashDotDot | 7 Double | 8 Medium | 9 MediumDashed | 10 MediumDashDot | 11 MediumDashDotDot | 12 SlantedDashDot | 13 Thick ,和aspose.cells的getLineStyle()的值对应的话,需要自己做个转换,参考 aspose.cells"`
  161. }
  162. // LuckySheetCellData 单个单元格数据
  163. type LuckySheetCellData struct {
  164. Col int64 `json:"c" description:"列"`
  165. Row int64 `json:"r" description:"行"`
  166. Value LuckySheetDataValue `json:"v" description:"单元格内值的数据"`
  167. }
  168. // LuckySheetDataValue 单元格内值的数据
  169. type LuckySheetDataValue struct {
  170. CellType LuckySheetDataCellType `json:"ct" description:"单元格值格式:文本、时间等 "`
  171. Value interface{} `json:"v" description:"原始值"`
  172. Monitor string `json:"m" description:"显示值"`
  173. Background string `json:"bg" description:"背景色,实例值:#fff000"`
  174. FontFamily int `description:"字体,0 Times New Roman、 1 Arial、2 Tahoma 、3 Verdana、4 微软雅黑、5 宋体(Song)、6 黑体(ST Heiti)、7 楷体(ST Kaiti)、 8 仿宋(ST FangSong)、9 新宋体(ST Song)、10 华文新魏、11 华文行楷、12 华文隶书 "`
  175. FF interface{} `json:"ff" description:"字体,0 Times New Roman、 1 Arial、2 Tahoma 、3 Verdana、4 微软雅黑、5 宋体(Song)、6 黑体(ST Heiti)、7 楷体(ST Kaiti)、 8 仿宋(ST FangSong)、9 新宋体(ST Song)、10 华文新魏、11 华文行楷、12 华文隶书 "`
  176. FontColor string `json:"fc" description:"字体颜色,示例值:#fff000" `
  177. Bold int `json:"bl" description:"粗体,0 常规 、 1加粗 "`
  178. Italic int `json:"it" description:"斜体,0 常规 、 1 斜体"`
  179. Fontsize int `description:"字体大小,14"`
  180. CancelLine int ` description:"删除线, 0 常规 、 1 删除线"`
  181. HorizontalType int `description:"水平对齐, 0 居中、1 左、2右"`
  182. VerticalType int ` description:"垂直对齐, 0 中间、1 上、2下"`
  183. Fs interface{} `json:"fs" description:"字体大小,14"`
  184. Cl interface{} `json:"cl" description:"删除线, 0 常规 、 1 删除线"`
  185. Ht interface{} `json:"ht" description:"水平对齐, 0 居中、1 左、2右"`
  186. Vt interface{} `json:"vt" description:"垂直对齐, 0 中间、1 上、2下"`
  187. //TextRotate string `json:"tr" description:"竖排文字, 3"`
  188. //RotateText string `json:"rt" description:"文字旋转角度, 介于0~180之间的整数,包含0和180"`
  189. TextBeak int `description:"文本换行, 0 截断、1溢出、2 自动换行"`
  190. Tb interface{} `json:"tb" description:"文本换行, 0 截断、1溢出、2 自动换行"`
  191. Ps LuckySheetDataCellComment `json:"ps" description:"批注"`
  192. Function string `json:"f" description:"公式"`
  193. MergeCell LuckySheetDataConfigMerge `json:"mc" description:"合并单元格信息"`
  194. }
  195. // LuckySheetDataCellType 单元格值格式:文本、时间等
  196. type LuckySheetDataCellType struct {
  197. Fa string `json:"fa" description:"格式名称,例如:“General”为自动格式"`
  198. T string `json:"t" description:"格式类型,例如:“n”为数字类型"`
  199. S []struct {
  200. FontFamily int `description:"字体,0 Times New Roman、 1 Arial、2 Tahoma 、3 Verdana、4 微软雅黑、5 宋体(Song)、6 黑体(ST Heiti)、7 楷体(ST Kaiti)、 8 仿宋(ST FangSong)、9 新宋体(ST Song)、10 华文新魏、11 华文行楷、12 华文隶书 "`
  201. FF interface{} `json:"ff" description:"字体,0 Times New Roman、 1 Arial、2 Tahoma 、3 Verdana、4 微软雅黑、5 宋体(Song)、6 黑体(ST Heiti)、7 楷体(ST Kaiti)、 8 仿宋(ST FangSong)、9 新宋体(ST Song)、10 华文新魏、11 华文行楷、12 华文隶书 "`
  202. FontColor string `json:"fc" description:"字体颜色,示例值:#fff000" `
  203. Fontsize int `description:"字体大小,14"`
  204. CancelLine int ` description:"删除线, 0 常规 、 1 删除线"`
  205. HorizontalType int `description:"水平对齐, 0 居中、1 左、2右"`
  206. VerticalType int `description:"垂直对齐, 0 中间、1 上、2下"`
  207. Fs interface{} `json:"fs" description:"字体大小,14"`
  208. Cl interface{} `json:"cl" description:"删除线, 0 常规 、 1 删除线"`
  209. Ht interface{} `json:"ht" description:"水平对齐, 0 居中、1 左、2右"`
  210. Vt interface{} `json:"vt" description:"垂直对齐, 0 中间、1 上、2下"`
  211. Un interface{} `json:"un" description:""`
  212. Bold interface{} `json:"bl" description:"粗体,0 常规 、 1加粗 "`
  213. Italic interface{} `json:"it" description:"斜体,0 常规 、 1 斜体"`
  214. Value interface{} `json:"v" description:"原始值"`
  215. } `json:"s"`
  216. }
  217. // LuckySheetDataCellComment 批注
  218. type LuckySheetDataCellComment struct {
  219. Left int `json:"left" description:"批注框距离左边工作表边缘位置"`
  220. Top int `json:"top" description:"批注框距离上边工作表边缘位置"`
  221. Width int `json:"width" description:"批注框宽度"`
  222. Height int `json:"height" description:"批注框高度"`
  223. Value string `json:"value" description:"批注内容"`
  224. IsShow bool `json:"isshow" description:"是否显示批注"`
  225. }
  226. // GetLuckySheetData 获取LuckySheetData的结构体
  227. func GetLuckySheetData(jsonStr string) (item *LuckySheetData, err error) {
  228. err = json.Unmarshal([]byte(jsonStr), &item)
  229. for k, v := range item.CellData {
  230. value := v.Value
  231. value.Fontsize = getIntValueByInterface(value.Fs)
  232. value.CancelLine = getIntValueByInterface(value.Cl)
  233. value.HorizontalType = getIntValueByInterface(value.Ht)
  234. value.VerticalType = getIntValueByInterface(value.Vt)
  235. value.FontFamily = getIntValueByInterface(value.FF)
  236. value.TextBeak = getIntValueByInterface(value.Tb)
  237. if len(value.CellType.S) > 0 {
  238. for kk, vv := range value.CellType.S {
  239. vv.Fontsize = getIntValueByInterface(vv.Fs)
  240. vv.CancelLine = getIntValueByInterface(vv.Cl)
  241. vv.HorizontalType = getIntValueByInterface(vv.Ht)
  242. vv.VerticalType = getIntValueByInterface(vv.Vt)
  243. vv.FontFamily = getIntValueByInterface(vv.FF)
  244. value.CellType.S[kk] = vv
  245. }
  246. }
  247. item.CellData[k].Value = value
  248. }
  249. //边框
  250. if len(item.Config.BorderInfo) > 0 {
  251. for k, v := range item.Config.BorderInfo {
  252. v.Value.T.Style = getIntValueByInterface(v.Value.T.Style)
  253. v.Value.B.Style = getIntValueByInterface(v.Value.B.Style)
  254. v.Value.L.Style = getIntValueByInterface(v.Value.L.Style)
  255. v.Value.R.Style = getIntValueByInterface(v.Value.R.Style)
  256. item.Config.BorderInfo[k] = v
  257. }
  258. }
  259. return
  260. }
  261. // 兼容前端js传递的数据类型
  262. func getIntValueByInterface(valInterface interface{}) (val int) {
  263. if valInterface == nil {
  264. return
  265. }
  266. switch reflect.TypeOf(valInterface).Kind() {
  267. case reflect.String:
  268. tmpValue := reflect.ValueOf(valInterface).String()
  269. tmpValInt, err := strconv.Atoi(tmpValue)
  270. if err != nil {
  271. val = 0
  272. } else {
  273. val = tmpValInt
  274. }
  275. case reflect.Int, reflect.Int32, reflect.Int64:
  276. tmpValue := reflect.ValueOf(valInterface).Int()
  277. val = int(tmpValue)
  278. }
  279. return
  280. }
  281. // TableData 表格数据
  282. type TableData struct {
  283. TableDataList [][]LuckySheetDataValue
  284. RowWidthList []float64
  285. RowHeightList []float64
  286. RemoveTopRow int `description:"移除表格上方的行数"`
  287. RemoveBottomRow int `description:"移除表格下方的行数"`
  288. RemoveLeftColumn int `description:"移除表格左侧的列数"`
  289. RemoveRightColumn int `description:"移除表格右侧的列数"`
  290. MergeList []TableDataMerge `description:"合并数据列"`
  291. }
  292. // TableDataMerge 表格数据合并单元格配置
  293. type TableDataMerge struct {
  294. StartRowIndex int `json:"start_row_index" description:"开始的行下标"`
  295. StartColumnIndex int `json:"start_column" description:"开始的列下标"`
  296. MergeRowNum int `json:"merge_row_num" description:"合并的行数"`
  297. MergeColumnNum int `json:"merge_column_num" description:"合并的列数"`
  298. }
  299. // GetTableDataByLuckySheetDataStr 通过LuckySheet的string数据获取表格数据
  300. func (item *LuckySheetData) GetTableDataByLuckySheetDataStr() (selfTableData TableData, err error) {
  301. luckySheetCellDataList := item.CellData
  302. // 表格数据
  303. tableDataMap := make(map[int64]map[int64]LuckySheetDataValue)
  304. // 最大行,最大列
  305. var maxRow, maxCol int64
  306. for _, v := range luckySheetCellDataList {
  307. //fmt.Println("row:", v.Row, "=====col:", v.Col)
  308. if v.Row > maxRow { //最大行
  309. maxRow = v.Row
  310. }
  311. if v.Col > maxCol { //最大列
  312. maxCol = v.Col
  313. }
  314. var tmpRow map[int64]LuckySheetDataValue
  315. tmpRow, ok := tableDataMap[v.Row]
  316. if ok {
  317. tmpRow[v.Col] = v.Value
  318. } else {
  319. tmpRow = make(map[int64]LuckySheetDataValue)
  320. tmpRow[v.Col] = v.Value
  321. }
  322. tableDataMap[v.Row] = tmpRow
  323. }
  324. tableDataList := make([][]LuckySheetDataValue, 0)
  325. var i int64
  326. // 单元格宽度
  327. configColumnConf := item.Config.Columnlen
  328. rowWidthMap := make(map[int]float64)
  329. rowWidthList := make([]float64, 0) //
  330. // 单元格高度
  331. configRowConf := item.Config.Rowlen
  332. rowHeightList := make([]float64, 0) //
  333. for i = 0; i <= maxRow; i++ {
  334. //列
  335. tmpTableColDataList := make([]LuckySheetDataValue, 0)
  336. // 每个单元格的高度
  337. tmpHeight, ok := configRowConf[fmt.Sprint(i)]
  338. if !ok {
  339. tmpHeight = 0
  340. }
  341. rowHeightList = append(rowHeightList, tmpHeight)
  342. tmpRowData, ok := tableDataMap[i]
  343. // 如果没有该行数据,那么就默认添加空行数据处理
  344. if !ok {
  345. tmpRowData = make(map[int64]LuckySheetDataValue)
  346. }
  347. var j int64
  348. for j = 0; j <= maxCol; j++ {
  349. tmpTableColData, ok := tmpRowData[j]
  350. if !ok {
  351. tmpTableColData = LuckySheetDataValue{}
  352. }
  353. //单元格显示的数据处理
  354. tmpTableColData.Monitor = handleCellVal(tmpTableColData)
  355. tmpTableColDataList = append(tmpTableColDataList, tmpTableColData)
  356. // 每个单元格的宽度
  357. tmpWidth, ok := configColumnConf[fmt.Sprint(j)]
  358. if !ok {
  359. tmpWidth = 0
  360. }
  361. rowIndex := len(tmpTableColDataList) - 1
  362. if _, ok2 := rowWidthMap[rowIndex]; !ok2 {
  363. rowWidthList = append(rowWidthList, tmpWidth)
  364. }
  365. rowWidthMap[rowIndex] = tmpWidth
  366. }
  367. tableDataList = append(tableDataList, tmpTableColDataList)
  368. }
  369. // 数据处理,移除上下左右空行空列
  370. tableDataList, tableRemoveNum, rowHeightList, rowWidthList, tableDataMergeList := handleTableDataList(tableDataList, item.Config.Merge, rowHeightList, rowWidthList)
  371. // 表格数据
  372. {
  373. // 移除空白单元格信息
  374. selfTableData.RemoveTopRow = tableRemoveNum.RemoveTopRow
  375. selfTableData.RemoveBottomRow = tableRemoveNum.RemoveBottomRow
  376. selfTableData.RemoveLeftColumn = tableRemoveNum.RemoveLeftColumn
  377. selfTableData.RemoveRightColumn = tableRemoveNum.RemoveRightColumn
  378. }
  379. selfTableData.TableDataList = tableDataList
  380. selfTableData.RowWidthList = rowWidthList
  381. selfTableData.RowHeightList = rowHeightList
  382. selfTableData.MergeList = tableDataMergeList
  383. return
  384. }
  385. // TableRemoveNum 上下左右移除的空行空列数量
  386. type TableRemoveNum struct {
  387. RemoveTopRow int `description:"移除表格上方的行数"`
  388. RemoveBottomRow int `description:"移除表格下方的行数"`
  389. RemoveLeftColumn int `description:"移除表格左侧的列数"`
  390. RemoveRightColumn int `description:"移除表格右侧的列数"`
  391. }
  392. // handleTableDataList 表格数据处理(移除上下左右的空行空列)
  393. func handleTableDataList(tableDataList [][]LuckySheetDataValue, luckySheetDataConfigMergeList map[string]LuckySheetDataConfigMerge, rowHeightList, rowWidthList []float64) ([][]LuckySheetDataValue, TableRemoveNum, []float64, []float64, []TableDataMerge) {
  394. var removeTopRow, removeBottomRow, removeLeftColumn, removeRightColumn int //上下左右需要移除的空行空列
  395. tableDataMergeList := make([]TableDataMerge, 0) //待合并的单元格信息
  396. //总共多少行
  397. lenRow := len(tableDataList)
  398. //移除上下空行
  399. deleteRowIndexList := make([]int, 0)
  400. if lenRow > 0 {
  401. var flag = false
  402. // 移除上方空列
  403. for rowIndex := 0; rowIndex < lenRow; rowIndex++ {
  404. isDelete := true
  405. for _, v := range tableDataList[rowIndex] {
  406. if v.Monitor != `` || (v.MergeCell.Row != rowIndex && v.MergeCell.Row != 0) {
  407. isDelete = false
  408. flag = true
  409. break
  410. }
  411. }
  412. if flag {
  413. break
  414. }
  415. if isDelete {
  416. removeTopRow++
  417. deleteRowIndexList = append(deleteRowIndexList, rowIndex)
  418. }
  419. }
  420. // 移除下方空行
  421. flag = false
  422. //尾部
  423. deleteBottomRowIndexList := make([]int, 0)
  424. for rowIndex := lenRow - 1; rowIndex >= 0; rowIndex-- {
  425. isDelete := true
  426. for _, v := range tableDataList[rowIndex] {
  427. if v.Monitor != `` {
  428. isDelete = false
  429. flag = true
  430. break
  431. }
  432. }
  433. if flag {
  434. break
  435. }
  436. if isDelete {
  437. deleteBottomRowIndexList = append(deleteBottomRowIndexList, rowIndex)
  438. removeBottomRow++
  439. }
  440. }
  441. if len(deleteBottomRowIndexList) > 0 {
  442. deleteRowIndexList = append(deleteRowIndexList, utils.RevSlice(deleteBottomRowIndexList)...)
  443. }
  444. lenDeleteRow := len(deleteRowIndexList)
  445. if lenDeleteRow > 0 {
  446. for rowIndex := lenDeleteRow - 1; rowIndex >= 0; rowIndex-- {
  447. //表格数据
  448. tableDataList = append(tableDataList[:deleteRowIndexList[rowIndex]], tableDataList[deleteRowIndexList[rowIndex]+1:]...) // 删除开头N个元素
  449. //表格高度
  450. rowHeightList = append(rowHeightList[:deleteRowIndexList[rowIndex]], rowHeightList[deleteRowIndexList[rowIndex]+1:]...) // 删除开头N个元素
  451. }
  452. }
  453. }
  454. //移除左右空列
  455. deleteColumnIndexList := make([]int, 0)
  456. if len(tableDataList) > 0 {
  457. var flag = false
  458. lenColumn := len(tableDataList[0])
  459. // 移除左边空列
  460. for columnIndex := 0; columnIndex < lenColumn; columnIndex++ {
  461. isDelete := true
  462. for _, v := range tableDataList {
  463. //如果一列都没有,说明是上面几行是空行,没有数据
  464. if len(v) <= 0 {
  465. continue
  466. }
  467. if v[columnIndex].Monitor != `` || (v[columnIndex].MergeCell.Column != columnIndex && v[columnIndex].MergeCell.Column != 0) {
  468. isDelete = false
  469. flag = true
  470. break
  471. }
  472. }
  473. if flag {
  474. break
  475. }
  476. if isDelete {
  477. removeLeftColumn++
  478. deleteColumnIndexList = append(deleteColumnIndexList, columnIndex)
  479. }
  480. }
  481. // 移除右方空列
  482. flag = false
  483. //右边
  484. deleteTailColumnIndexList := make([]int, 0)
  485. for columnIndex := lenColumn - 1; columnIndex >= 0; columnIndex-- {
  486. isDelete := true
  487. for _, v := range tableDataList {
  488. //如果一列都没有,说明是上面几行是空行,没有数据
  489. if len(v) <= 0 {
  490. continue
  491. }
  492. if v[columnIndex].Monitor != `` || (v[columnIndex].MergeCell.Column != columnIndex && v[columnIndex].MergeCell.Column != 0) {
  493. isDelete = false
  494. flag = true
  495. break
  496. }
  497. }
  498. if flag {
  499. break
  500. }
  501. if isDelete {
  502. deleteTailColumnIndexList = append(deleteTailColumnIndexList, columnIndex)
  503. removeRightColumn++
  504. }
  505. }
  506. if len(deleteTailColumnIndexList) > 0 {
  507. deleteColumnIndexList = append(deleteColumnIndexList, utils.RevSlice(deleteTailColumnIndexList)...)
  508. }
  509. lenDeleteColumn := len(deleteColumnIndexList)
  510. if lenDeleteColumn > 0 {
  511. for columnIndex := lenDeleteColumn - 1; columnIndex >= 0; columnIndex-- {
  512. //表格数据
  513. for k, v := range tableDataList {
  514. tableDataList[k] = append(v[:deleteColumnIndexList[columnIndex]], v[deleteColumnIndexList[columnIndex]+1:]...) // 删除开头N个元素
  515. }
  516. //表格宽度
  517. rowWidthList = append(rowWidthList[:deleteColumnIndexList[columnIndex]], rowWidthList[deleteColumnIndexList[columnIndex]+1:]...) // 删除开头N个元素
  518. }
  519. }
  520. }
  521. //处理合并单元格
  522. for _, v := range luckySheetDataConfigMergeList {
  523. indexRow := v.Row - removeTopRow
  524. indexColumn := v.Column - removeLeftColumn
  525. tableDataMerge := TableDataMerge{
  526. StartRowIndex: indexRow,
  527. StartColumnIndex: indexColumn,
  528. MergeRowNum: v.Rs - 1,
  529. MergeColumnNum: v.Cs - 1,
  530. }
  531. tableDataMergeList = append(tableDataMergeList, tableDataMerge)
  532. }
  533. return tableDataList, TableRemoveNum{
  534. RemoveTopRow: removeTopRow,
  535. RemoveBottomRow: removeBottomRow,
  536. RemoveLeftColumn: removeLeftColumn,
  537. RemoveRightColumn: removeRightColumn,
  538. }, rowHeightList, rowWidthList, tableDataMergeList
  539. }
  540. // handleCellVal 处理单元格数据
  541. func handleCellVal(tmpTableColData LuckySheetDataValue) (valueStr string) {
  542. valueStr = tmpTableColData.Monitor
  543. if valueStr == `` {
  544. //valueStr = fmt.Sprint(cellInfo.Value)
  545. if valueStr == `` && tmpTableColData.CellType.S != nil {
  546. //不是设置在单元格上面,而是设置在文本上
  547. for _, cellS := range tmpTableColData.CellType.S {
  548. valueStr += fmt.Sprint(cellS.Value)
  549. }
  550. }
  551. }
  552. return
  553. }
  554. type CellPosition struct {
  555. RowIndex int
  556. ColumnIndex int
  557. }
  558. // HandleTableCell 前端d毛需要我根据合并单元格处理掉多余的单元格
  559. func HandleTableCell(oldTableData TableData) (newTableData TableData) {
  560. newTableData = oldTableData
  561. mergeList := oldTableData.MergeList
  562. lenMergeList := len(mergeList)
  563. if lenMergeList <= 0 {
  564. return
  565. }
  566. deleteRowMap := make(map[int]map[int]int)
  567. deleteRowList := make([]int, 0)
  568. deleteColumnMap := make(map[int][]int, 0)
  569. for i := lenMergeList - 1; i >= 0; i-- {
  570. tmpMerge := mergeList[i]
  571. //
  572. for rowIndex := tmpMerge.MergeRowNum; rowIndex >= 0; rowIndex-- {
  573. tmpColumnMap := make(map[int]int)
  574. if columnMap, ok := deleteRowMap[tmpMerge.StartRowIndex+rowIndex]; ok {
  575. tmpColumnMap = columnMap
  576. } else {
  577. deleteRowList = append(deleteRowList, tmpMerge.StartRowIndex+rowIndex)
  578. }
  579. deleteColumnList := make([]int, 0)
  580. if columnList, ok := deleteColumnMap[tmpMerge.StartRowIndex+rowIndex]; ok {
  581. deleteColumnList = columnList
  582. }
  583. for columnIndex := tmpMerge.MergeColumnNum; columnIndex >= 0; columnIndex-- {
  584. if rowIndex == 0 && columnIndex == 0 {
  585. continue
  586. }
  587. tmpColumnMap[tmpMerge.StartColumnIndex+columnIndex] = tmpMerge.StartColumnIndex + columnIndex
  588. deleteColumnList = append(deleteColumnList, tmpMerge.StartColumnIndex+columnIndex)
  589. }
  590. // 待删除的行
  591. deleteRowMap[tmpMerge.StartRowIndex+rowIndex] = tmpColumnMap
  592. // 该行待删除的列
  593. deleteColumnMap[tmpMerge.StartRowIndex+rowIndex] = deleteColumnList
  594. }
  595. }
  596. sort.Ints(deleteRowList)
  597. //for k, v := range deleteRowList {
  598. // fmt.Println("k:", k, "v:", v)
  599. //}
  600. //return
  601. //fmt.Println("===============")
  602. for i := len(deleteRowList) - 1; i >= 0; i-- {
  603. rowIndex := deleteRowList[i]
  604. deleteColumnList := deleteColumnMap[rowIndex]
  605. sort.Ints(deleteColumnList)
  606. for i := len(deleteColumnList) - 1; i >= 0; i-- {
  607. columnIndex := deleteColumnList[i]
  608. // 最后一行合并单元格时,就不再次移除合并的单元格,避免数组越界
  609. if rowIndex >= len(newTableData.TableDataList) {
  610. continue
  611. }
  612. tmpColumnDataList := newTableData.TableDataList[rowIndex]
  613. // 最后一列合并单元格时,就不再次移除合并的单元格,避免数组越界
  614. if columnIndex >= len(tmpColumnDataList) {
  615. continue
  616. }
  617. newTableData.TableDataList[rowIndex] = append(tmpColumnDataList[:columnIndex], tmpColumnDataList[columnIndex+1:]...) // 删除开头N个元素
  618. //fmt.Println("row:", rowIndex, "===column:", columnIndex)
  619. }
  620. }
  621. return
  622. }
  623. // GetTableDataByLuckySheetDataStrBak 通过LuckySheet的string数据获取表格数据(备份:2022-08-23 10:30:32)
  624. func (item *LuckySheetData) GetTableDataByLuckySheetDataStrBak() (selfTableData TableData, err error) {
  625. luckySheetCellDataList := item.CellData
  626. // 表格数据
  627. tableDataMap := make(map[int64]map[int64]LuckySheetDataValue)
  628. // 最大行,最大列
  629. var maxRow, maxCol int64
  630. for _, v := range luckySheetCellDataList {
  631. //fmt.Println("row:", v.Row, "=====col:", v.Col)
  632. if v.Row > maxRow { //最大行
  633. maxRow = v.Row
  634. }
  635. if v.Col > maxCol { //最大列
  636. maxCol = v.Col
  637. }
  638. var tmpRow map[int64]LuckySheetDataValue
  639. tmpRow, ok := tableDataMap[v.Row]
  640. if ok {
  641. tmpRow[v.Col] = v.Value
  642. } else {
  643. tmpRow = make(map[int64]LuckySheetDataValue)
  644. tmpRow[v.Col] = v.Value
  645. }
  646. tableDataMap[v.Row] = tmpRow
  647. }
  648. tableDataList := make([][]LuckySheetDataValue, 0)
  649. var i int64
  650. // 单元格宽度
  651. configColumnConf := item.Config.Columnlen
  652. rowWidthMap := make(map[int]float64)
  653. rowWidthList := make([]float64, 0) //
  654. // 单元格高度
  655. configRowConf := item.Config.Rowlen
  656. rowHeightList := make([]float64, 0) //
  657. for i = 0; i <= maxRow; i++ {
  658. //列
  659. tmpTableColDataList := make([]LuckySheetDataValue, 0)
  660. // 每个单元格的高度
  661. tmpHeight, ok := configRowConf[fmt.Sprint(i)]
  662. if !ok {
  663. tmpHeight = 0
  664. }
  665. rowHeightList = append(rowHeightList, tmpHeight)
  666. tmpRowData, ok := tableDataMap[i]
  667. // 如果没有该行数据,那么就默认添加空行数据处理
  668. if !ok {
  669. tmpRowData = make(map[int64]LuckySheetDataValue)
  670. }
  671. var j int64
  672. for j = 0; j <= maxCol; j++ {
  673. tmpTableColData, ok := tmpRowData[j]
  674. if !ok {
  675. tmpTableColData = LuckySheetDataValue{}
  676. }
  677. //单元格显示的数据处理
  678. tmpTableColData.Monitor = handleCellVal(tmpTableColData)
  679. tmpTableColDataList = append(tmpTableColDataList, tmpTableColData)
  680. // 每个单元格的宽度
  681. tmpWidth, ok := configColumnConf[fmt.Sprint(j)]
  682. if !ok {
  683. tmpWidth = 0
  684. }
  685. rowIndex := len(tmpTableColDataList) - 1
  686. if _, ok2 := rowWidthMap[rowIndex]; !ok2 {
  687. rowWidthList = append(rowWidthList, tmpWidth)
  688. }
  689. rowWidthMap[rowIndex] = tmpWidth
  690. }
  691. tableDataList = append(tableDataList, tmpTableColDataList)
  692. }
  693. //总共多少行
  694. lenRow := len(tableDataList)
  695. //移除上下空行
  696. deleteRowIndexList := make([]int, 0)
  697. if lenRow > 0 {
  698. var flag = false
  699. // 移除上方空列
  700. for rowIndex := 0; rowIndex < lenRow; rowIndex++ {
  701. isDelete := true
  702. for _, v := range tableDataList[rowIndex] {
  703. if v.Monitor != `` {
  704. isDelete = false
  705. flag = true
  706. break
  707. }
  708. }
  709. if flag {
  710. break
  711. }
  712. if isDelete {
  713. selfTableData.RemoveTopRow++
  714. deleteRowIndexList = append(deleteRowIndexList, rowIndex)
  715. }
  716. }
  717. // 移除下方空行
  718. flag = false
  719. //尾部
  720. deleteBottomRowIndexList := make([]int, 0)
  721. for rowIndex := lenRow - 1; rowIndex >= 0; rowIndex-- {
  722. isDelete := true
  723. for _, v := range tableDataList[rowIndex] {
  724. if v.Monitor != `` || (v.MergeCell.Row != rowIndex && v.MergeCell.Row != 0) {
  725. isDelete = false
  726. flag = true
  727. break
  728. }
  729. }
  730. if flag {
  731. break
  732. }
  733. if isDelete {
  734. deleteBottomRowIndexList = append(deleteBottomRowIndexList, rowIndex)
  735. selfTableData.RemoveBottomRow++
  736. }
  737. }
  738. if len(deleteBottomRowIndexList) > 0 {
  739. deleteRowIndexList = append(deleteRowIndexList, utils.RevSlice(deleteBottomRowIndexList)...)
  740. }
  741. lenDeleteRow := len(deleteRowIndexList)
  742. if lenDeleteRow > 0 {
  743. for rowIndex := lenDeleteRow - 1; rowIndex >= 0; rowIndex-- {
  744. //表格数据
  745. tableDataList = append(tableDataList[:deleteRowIndexList[rowIndex]], tableDataList[deleteRowIndexList[rowIndex]+1:]...) // 删除开头N个元素
  746. //表格高度
  747. rowHeightList = append(rowHeightList[:deleteRowIndexList[rowIndex]], rowHeightList[deleteRowIndexList[rowIndex]+1:]...) // 删除开头N个元素
  748. }
  749. }
  750. }
  751. //移除前后空列
  752. deleteColumnIndexList := make([]int, 0)
  753. if len(tableDataList) > 0 {
  754. var flag = false
  755. lenColumn := len(tableDataList[0])
  756. // 移除前方空列
  757. for columnIndex := 0; columnIndex < lenColumn; columnIndex++ {
  758. isDelete := true
  759. for _, v := range tableDataList {
  760. //如果一列都没有,说明是上面几行是空行,没有数据
  761. if len(v) <= 0 {
  762. continue
  763. }
  764. if v[columnIndex].Monitor != `` {
  765. isDelete = false
  766. flag = true
  767. break
  768. }
  769. }
  770. if flag {
  771. break
  772. }
  773. if isDelete {
  774. selfTableData.RemoveLeftColumn++
  775. deleteColumnIndexList = append(deleteColumnIndexList, columnIndex)
  776. }
  777. }
  778. // 移除后方空列
  779. flag = false
  780. //后方
  781. deleteTailColumnIndexList := make([]int, 0)
  782. for columnIndex := lenColumn - 1; columnIndex >= 0; columnIndex-- {
  783. isDelete := true
  784. for _, v := range tableDataList {
  785. if v[columnIndex].Monitor != `` || (v[columnIndex].MergeCell.Column != columnIndex && v[columnIndex].MergeCell.Column != 0) {
  786. isDelete = false
  787. flag = true
  788. break
  789. }
  790. }
  791. if flag {
  792. break
  793. }
  794. if isDelete {
  795. deleteTailColumnIndexList = append(deleteTailColumnIndexList, columnIndex)
  796. selfTableData.RemoveRightColumn++
  797. }
  798. }
  799. if len(deleteTailColumnIndexList) > 0 {
  800. deleteColumnIndexList = append(deleteColumnIndexList, utils.RevSlice(deleteTailColumnIndexList)...)
  801. }
  802. lenDeleteColumn := len(deleteColumnIndexList)
  803. if lenDeleteColumn > 0 {
  804. for columnIndex := lenDeleteColumn - 1; columnIndex >= 0; columnIndex-- {
  805. //表格数据
  806. for k, v := range tableDataList {
  807. tableDataList[k] = append(v[:deleteColumnIndexList[columnIndex]], v[deleteColumnIndexList[columnIndex]+1:]...) // 删除开头N个元素
  808. }
  809. //表格宽度
  810. rowWidthList = append(rowWidthList[:deleteColumnIndexList[columnIndex]], rowWidthList[deleteColumnIndexList[columnIndex]+1:]...) // 删除开头N个元素
  811. }
  812. }
  813. }
  814. //处理合并单元格
  815. tableDataMergeList := make([]TableDataMerge, 0)
  816. for _, v := range item.Config.Merge {
  817. indexRow := v.Row - selfTableData.RemoveTopRow
  818. indexColumn := v.Column - selfTableData.RemoveLeftColumn
  819. tableDataMerge := TableDataMerge{
  820. StartRowIndex: indexRow,
  821. StartColumnIndex: indexColumn,
  822. MergeRowNum: v.Rs - 1,
  823. MergeColumnNum: v.Cs - 1,
  824. }
  825. tableDataMergeList = append(tableDataMergeList, tableDataMerge)
  826. }
  827. // 表格数据
  828. selfTableData.TableDataList = tableDataList
  829. selfTableData.RowWidthList = rowWidthList
  830. selfTableData.RowHeightList = rowHeightList
  831. selfTableData.MergeList = tableDataMergeList
  832. return
  833. }
  834. // GetTableDataByCustomData 通过自定义表格数据获取表格数据
  835. func GetTableDataByCustomData(excelType int, data request.TableDataReq) (selfTableData TableData, err error) {
  836. tableDataList := make([][]LuckySheetDataValue, 0)
  837. // 指标数
  838. lenEdb := len(data.Data)
  839. if lenEdb <= 0 {
  840. return
  841. }
  842. // 日期数
  843. lenCol := len(data.Data[0].Data)
  844. if lenCol <= 0 {
  845. return
  846. }
  847. // 指标列:1;指标行:2
  848. if excelType == 1 {
  849. // 第一行
  850. {
  851. firstCol := make([]LuckySheetDataValue, 0)
  852. firstCol = append(firstCol, LuckySheetDataValue{
  853. Value: "日期",
  854. Monitor: "日期",
  855. MergeCell: LuckySheetDataConfigMerge{
  856. Row: 0, //行数
  857. Column: 0, //列数
  858. Rs: 2, //合并的行数
  859. Cs: 1, //合并的列数
  860. },
  861. })
  862. for _, v := range data.Data {
  863. edbName := v.EdbName
  864. if v.EdbAliasName != `` {
  865. edbName = v.EdbAliasName
  866. }
  867. firstCol = append(firstCol, LuckySheetDataValue{
  868. Value: edbName,
  869. Monitor: edbName,
  870. MergeCell: LuckySheetDataConfigMerge{},
  871. })
  872. }
  873. tableDataList = append(tableDataList, firstCol)
  874. }
  875. // 第二行
  876. {
  877. secondCol := make([]LuckySheetDataValue, 0)
  878. //secondCol = append(secondCol, LuckySheetDataValue{})
  879. for _, v := range data.Data {
  880. name := v.Unit + " / " + v.Frequency
  881. secondCol = append(secondCol, LuckySheetDataValue{
  882. Value: name,
  883. Monitor: name,
  884. MergeCell: LuckySheetDataConfigMerge{},
  885. })
  886. }
  887. tableDataList = append(tableDataList, secondCol)
  888. }
  889. // 开始数据了
  890. {
  891. for i := 0; i < lenCol; i++ {
  892. dataCol := make([]LuckySheetDataValue, 0)
  893. // 日期
  894. dataCol = append(dataCol, LuckySheetDataValue{
  895. Value: data.Data[0].Data[i].DataTime,
  896. Monitor: data.Data[0].Data[i].DataTime,
  897. MergeCell: LuckySheetDataConfigMerge{},
  898. })
  899. // 数据值
  900. for _, v := range data.Data {
  901. dataCol = append(dataCol, LuckySheetDataValue{
  902. Value: v.Data[i].Value,
  903. Monitor: v.Data[i].ShowValue,
  904. MergeCell: LuckySheetDataConfigMerge{},
  905. })
  906. }
  907. tableDataList = append(tableDataList, dataCol)
  908. }
  909. }
  910. // 开始文本行了
  911. {
  912. for _, textColList := range data.TextRowData {
  913. dataCol := make([]LuckySheetDataValue, 0)
  914. for _, v := range textColList {
  915. dataCol = append(dataCol, LuckySheetDataValue{
  916. Value: v.Value,
  917. Monitor: v.ShowValue,
  918. MergeCell: LuckySheetDataConfigMerge{},
  919. })
  920. }
  921. tableDataList = append(tableDataList, dataCol)
  922. }
  923. }
  924. } else {
  925. // 指标行
  926. // 第一行
  927. {
  928. firstCol := make([]LuckySheetDataValue, 0)
  929. firstCol = append(firstCol, LuckySheetDataValue{
  930. Value: "日期",
  931. Monitor: "日期",
  932. MergeCell: LuckySheetDataConfigMerge{
  933. Row: 0, //行数
  934. Column: 0, //列数
  935. Rs: 1, //合并的行数
  936. Cs: 2, //合并的列数
  937. },
  938. })
  939. // 日期列
  940. for _, v := range data.Data[0].Data {
  941. firstCol = append(firstCol, LuckySheetDataValue{
  942. Value: v.DataTime,
  943. Monitor: v.DataTime,
  944. MergeCell: LuckySheetDataConfigMerge{},
  945. })
  946. }
  947. // 文本列
  948. for _, textColList := range data.TextRowData {
  949. firstCol = append(firstCol, LuckySheetDataValue{
  950. Value: textColList[0].Value,
  951. Monitor: textColList[0].ShowValue,
  952. MergeCell: LuckySheetDataConfigMerge{},
  953. })
  954. }
  955. tableDataList = append(tableDataList, firstCol)
  956. }
  957. // 日期列+文本列+两列表头(日期这个文案表头)
  958. //colLen := lenCol+2+len(data.TextRowData)
  959. for i := 0; i < lenEdb; i++ {
  960. dataCol := make([]LuckySheetDataValue, 0)
  961. // 指标信息
  962. tmpEdbInfo := data.Data[i]
  963. // 指标名称
  964. {
  965. edbName := tmpEdbInfo.EdbName
  966. if tmpEdbInfo.EdbAliasName != `` {
  967. edbName = tmpEdbInfo.EdbAliasName
  968. }
  969. dataCol = append(dataCol, LuckySheetDataValue{
  970. Value: edbName,
  971. Monitor: edbName,
  972. MergeCell: LuckySheetDataConfigMerge{},
  973. })
  974. }
  975. // 指标单位、频度
  976. {
  977. name := tmpEdbInfo.Unit + " / " + tmpEdbInfo.Frequency
  978. dataCol = append(dataCol, LuckySheetDataValue{
  979. Value: name,
  980. Monitor: name,
  981. MergeCell: LuckySheetDataConfigMerge{},
  982. })
  983. }
  984. // 指标数据列
  985. for _, tmpData := range tmpEdbInfo.Data {
  986. dataCol = append(dataCol, LuckySheetDataValue{
  987. Value: tmpData.Value,
  988. Monitor: tmpData.ShowValue,
  989. MergeCell: LuckySheetDataConfigMerge{},
  990. })
  991. }
  992. // 文本列
  993. for _, textColList := range data.TextRowData {
  994. dataCol = append(dataCol, LuckySheetDataValue{
  995. Value: textColList[i+1].Value,
  996. Monitor: textColList[i+1].ShowValue,
  997. MergeCell: LuckySheetDataConfigMerge{},
  998. })
  999. }
  1000. tableDataList = append(tableDataList, dataCol)
  1001. }
  1002. }
  1003. selfTableData.TableDataList = tableDataList
  1004. return
  1005. }