lucky_sheet.go 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200
  1. package excel
  2. import (
  3. "encoding/json"
  4. "eta/eta_chart_lib/models/request"
  5. "eta/eta_chart_lib/utils"
  6. "fmt"
  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 interface{} `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. if len(tableDataList) > 1 {
  425. for rowIndex := lenRow - 1; rowIndex >= 0; rowIndex-- {
  426. isDelete := true
  427. for _, v := range tableDataList[rowIndex] {
  428. if v.Monitor != `` {
  429. isDelete = false
  430. flag = true
  431. break
  432. }
  433. }
  434. if flag {
  435. break
  436. }
  437. if isDelete {
  438. deleteBottomRowIndexList = append(deleteBottomRowIndexList, rowIndex)
  439. removeBottomRow++
  440. }
  441. }
  442. }
  443. if len(deleteBottomRowIndexList) > 0 {
  444. deleteRowIndexList = append(deleteRowIndexList, utils.RevSlice(deleteBottomRowIndexList)...)
  445. }
  446. lenDeleteRow := len(deleteRowIndexList)
  447. if lenDeleteRow > 0 {
  448. for rowIndex := lenDeleteRow - 1; rowIndex >= 0; rowIndex-- {
  449. //表格数据
  450. tableDataList = append(tableDataList[:deleteRowIndexList[rowIndex]], tableDataList[deleteRowIndexList[rowIndex]+1:]...) // 删除开头N个元素
  451. //表格高度
  452. rowHeightList = append(rowHeightList[:deleteRowIndexList[rowIndex]], rowHeightList[deleteRowIndexList[rowIndex]+1:]...) // 删除开头N个元素
  453. }
  454. }
  455. }
  456. //移除左右空列
  457. deleteColumnIndexList := make([]int, 0)
  458. if len(tableDataList) > 0 {
  459. var flag = false
  460. lenColumn := len(tableDataList[0])
  461. // 移除左边空列
  462. for columnIndex := 0; columnIndex < lenColumn; columnIndex++ {
  463. isDelete := true
  464. for _, v := range tableDataList {
  465. //如果一列都没有,说明是上面几行是空行,没有数据
  466. if len(v) <= 0 {
  467. continue
  468. }
  469. if v[columnIndex].Monitor != `` || (v[columnIndex].MergeCell.Column != columnIndex && v[columnIndex].MergeCell.Column != 0) {
  470. isDelete = false
  471. flag = true
  472. break
  473. }
  474. }
  475. if flag {
  476. break
  477. }
  478. if isDelete {
  479. removeLeftColumn++
  480. deleteColumnIndexList = append(deleteColumnIndexList, columnIndex)
  481. }
  482. }
  483. // 移除右方空列
  484. flag = false
  485. //右边
  486. deleteTailColumnIndexList := make([]int, 0)
  487. // 数据要大于1列才会处理
  488. if lenColumn > 1 {
  489. for columnIndex := lenColumn - 1; columnIndex >= 0; columnIndex-- {
  490. isDelete := true
  491. for _, v := range tableDataList {
  492. //如果一列都没有,说明是上面几行是空行,没有数据
  493. if len(v) <= 0 {
  494. continue
  495. }
  496. if v[columnIndex].Monitor != `` || (v[columnIndex].MergeCell.Column != columnIndex && v[columnIndex].MergeCell.Column != 0) {
  497. isDelete = false
  498. flag = true
  499. break
  500. }
  501. }
  502. if flag {
  503. break
  504. }
  505. if isDelete {
  506. deleteTailColumnIndexList = append(deleteTailColumnIndexList, columnIndex)
  507. removeRightColumn++
  508. }
  509. }
  510. }
  511. if len(deleteTailColumnIndexList) > 0 {
  512. deleteColumnIndexList = append(deleteColumnIndexList, utils.RevSlice(deleteTailColumnIndexList)...)
  513. }
  514. lenDeleteColumn := len(deleteColumnIndexList)
  515. if lenDeleteColumn > 0 {
  516. for columnIndex := lenDeleteColumn - 1; columnIndex >= 0; columnIndex-- {
  517. //表格数据
  518. for k, v := range tableDataList {
  519. tableDataList[k] = append(v[:deleteColumnIndexList[columnIndex]], v[deleteColumnIndexList[columnIndex]+1:]...) // 删除开头N个元素
  520. }
  521. //表格宽度
  522. rowWidthList = append(rowWidthList[:deleteColumnIndexList[columnIndex]], rowWidthList[deleteColumnIndexList[columnIndex]+1:]...) // 删除开头N个元素
  523. }
  524. }
  525. }
  526. //处理合并单元格
  527. for _, v := range luckySheetDataConfigMergeList {
  528. indexRow := v.Row - removeTopRow
  529. indexColumn := v.Column - removeLeftColumn
  530. tableDataMerge := TableDataMerge{
  531. StartRowIndex: indexRow,
  532. StartColumnIndex: indexColumn,
  533. MergeRowNum: v.Rs - 1,
  534. MergeColumnNum: v.Cs - 1,
  535. }
  536. tableDataMergeList = append(tableDataMergeList, tableDataMerge)
  537. }
  538. return tableDataList, TableRemoveNum{
  539. RemoveTopRow: removeTopRow,
  540. RemoveBottomRow: removeBottomRow,
  541. RemoveLeftColumn: removeLeftColumn,
  542. RemoveRightColumn: removeRightColumn,
  543. }, rowHeightList, rowWidthList, tableDataMergeList
  544. }
  545. // handleCellVal 处理单元格数据
  546. func handleCellVal(tmpTableColData LuckySheetDataValue) (valueStr string) {
  547. valueStr = tmpTableColData.Monitor
  548. if valueStr == `` {
  549. //valueStr = fmt.Sprint(cellInfo.Value)
  550. if valueStr == `` && tmpTableColData.CellType.S != nil {
  551. //不是设置在单元格上面,而是设置在文本上
  552. for _, cellS := range tmpTableColData.CellType.S {
  553. valueStr += fmt.Sprint(cellS.Value)
  554. }
  555. }
  556. }
  557. return
  558. }
  559. type CellPosition struct {
  560. RowIndex int
  561. ColumnIndex int
  562. }
  563. // HandleTableCell 前端d毛需要我根据合并单元格处理掉多余的单元格
  564. func HandleTableCell(oldTableData TableData) (newTableData TableData) {
  565. newTableData = oldTableData
  566. mergeList := oldTableData.MergeList
  567. lenMergeList := len(mergeList)
  568. if lenMergeList <= 0 {
  569. return
  570. }
  571. deleteRowMap := make(map[int]map[int]int)
  572. deleteRowList := make([]int, 0)
  573. deleteColumnMap := make(map[int][]int, 0)
  574. for i := lenMergeList - 1; i >= 0; i-- {
  575. tmpMerge := mergeList[i]
  576. //
  577. for rowIndex := tmpMerge.MergeRowNum; rowIndex >= 0; rowIndex-- {
  578. tmpColumnMap := make(map[int]int)
  579. if columnMap, ok := deleteRowMap[tmpMerge.StartRowIndex+rowIndex]; ok {
  580. tmpColumnMap = columnMap
  581. } else {
  582. deleteRowList = append(deleteRowList, tmpMerge.StartRowIndex+rowIndex)
  583. }
  584. deleteColumnList := make([]int, 0)
  585. if columnList, ok := deleteColumnMap[tmpMerge.StartRowIndex+rowIndex]; ok {
  586. deleteColumnList = columnList
  587. }
  588. for columnIndex := tmpMerge.MergeColumnNum; columnIndex >= 0; columnIndex-- {
  589. if rowIndex == 0 && columnIndex == 0 {
  590. continue
  591. }
  592. tmpColumnMap[tmpMerge.StartColumnIndex+columnIndex] = tmpMerge.StartColumnIndex + columnIndex
  593. deleteColumnList = append(deleteColumnList, tmpMerge.StartColumnIndex+columnIndex)
  594. }
  595. // 待删除的行
  596. deleteRowMap[tmpMerge.StartRowIndex+rowIndex] = tmpColumnMap
  597. // 该行待删除的列
  598. deleteColumnMap[tmpMerge.StartRowIndex+rowIndex] = deleteColumnList
  599. }
  600. }
  601. sort.Ints(deleteRowList)
  602. //for k, v := range deleteRowList {
  603. // fmt.Println("k:", k, "v:", v)
  604. //}
  605. //return
  606. //fmt.Println("===============")
  607. for i := len(deleteRowList) - 1; i >= 0; i-- {
  608. rowIndex := deleteRowList[i]
  609. deleteColumnList := deleteColumnMap[rowIndex]
  610. sort.Ints(deleteColumnList)
  611. for i := len(deleteColumnList) - 1; i >= 0; i-- {
  612. columnIndex := deleteColumnList[i]
  613. // 最后一行合并单元格时,就不再次移除合并的单元格,避免数组越界
  614. if rowIndex >= len(newTableData.TableDataList) {
  615. continue
  616. }
  617. tmpColumnDataList := newTableData.TableDataList[rowIndex]
  618. // 最后一列合并单元格时,就不再次移除合并的单元格,避免数组越界
  619. if columnIndex >= len(tmpColumnDataList) {
  620. continue
  621. }
  622. newTableData.TableDataList[rowIndex] = append(tmpColumnDataList[:columnIndex], tmpColumnDataList[columnIndex+1:]...) // 删除开头N个元素
  623. //fmt.Println("row:", rowIndex, "===column:", columnIndex)
  624. }
  625. }
  626. return
  627. }
  628. // GetTableDataByLuckySheetDataStrBak 通过LuckySheet的string数据获取表格数据(备份:2022-08-23 10:30:32)
  629. func (item *LuckySheetData) GetTableDataByLuckySheetDataStrBak() (selfTableData TableData, err error) {
  630. luckySheetCellDataList := item.CellData
  631. // 表格数据
  632. tableDataMap := make(map[int64]map[int64]LuckySheetDataValue)
  633. // 最大行,最大列
  634. var maxRow, maxCol int64
  635. for _, v := range luckySheetCellDataList {
  636. //fmt.Println("row:", v.Row, "=====col:", v.Col)
  637. if v.Row > maxRow { //最大行
  638. maxRow = v.Row
  639. }
  640. if v.Col > maxCol { //最大列
  641. maxCol = v.Col
  642. }
  643. var tmpRow map[int64]LuckySheetDataValue
  644. tmpRow, ok := tableDataMap[v.Row]
  645. if ok {
  646. tmpRow[v.Col] = v.Value
  647. } else {
  648. tmpRow = make(map[int64]LuckySheetDataValue)
  649. tmpRow[v.Col] = v.Value
  650. }
  651. tableDataMap[v.Row] = tmpRow
  652. }
  653. tableDataList := make([][]LuckySheetDataValue, 0)
  654. var i int64
  655. // 单元格宽度
  656. configColumnConf := item.Config.Columnlen
  657. rowWidthMap := make(map[int]float64)
  658. rowWidthList := make([]float64, 0) //
  659. // 单元格高度
  660. configRowConf := item.Config.Rowlen
  661. rowHeightList := make([]float64, 0) //
  662. for i = 0; i <= maxRow; i++ {
  663. //列
  664. tmpTableColDataList := make([]LuckySheetDataValue, 0)
  665. // 每个单元格的高度
  666. tmpHeight, ok := configRowConf[fmt.Sprint(i)]
  667. if !ok {
  668. tmpHeight = 0
  669. }
  670. rowHeightList = append(rowHeightList, tmpHeight)
  671. tmpRowData, ok := tableDataMap[i]
  672. // 如果没有该行数据,那么就默认添加空行数据处理
  673. if !ok {
  674. tmpRowData = make(map[int64]LuckySheetDataValue)
  675. }
  676. var j int64
  677. for j = 0; j <= maxCol; j++ {
  678. tmpTableColData, ok := tmpRowData[j]
  679. if !ok {
  680. tmpTableColData = LuckySheetDataValue{}
  681. }
  682. //单元格显示的数据处理
  683. tmpTableColData.Monitor = handleCellVal(tmpTableColData)
  684. tmpTableColDataList = append(tmpTableColDataList, tmpTableColData)
  685. // 每个单元格的宽度
  686. tmpWidth, ok := configColumnConf[fmt.Sprint(j)]
  687. if !ok {
  688. tmpWidth = 0
  689. }
  690. rowIndex := len(tmpTableColDataList) - 1
  691. if _, ok2 := rowWidthMap[rowIndex]; !ok2 {
  692. rowWidthList = append(rowWidthList, tmpWidth)
  693. }
  694. rowWidthMap[rowIndex] = tmpWidth
  695. }
  696. tableDataList = append(tableDataList, tmpTableColDataList)
  697. }
  698. //总共多少行
  699. lenRow := len(tableDataList)
  700. //移除上下空行
  701. deleteRowIndexList := make([]int, 0)
  702. if lenRow > 0 {
  703. var flag = false
  704. // 移除上方空列
  705. for rowIndex := 0; rowIndex < lenRow; rowIndex++ {
  706. isDelete := true
  707. for _, v := range tableDataList[rowIndex] {
  708. if v.Monitor != `` {
  709. isDelete = false
  710. flag = true
  711. break
  712. }
  713. }
  714. if flag {
  715. break
  716. }
  717. if isDelete {
  718. selfTableData.RemoveTopRow++
  719. deleteRowIndexList = append(deleteRowIndexList, rowIndex)
  720. }
  721. }
  722. // 移除下方空行
  723. flag = false
  724. //尾部
  725. deleteBottomRowIndexList := make([]int, 0)
  726. for rowIndex := lenRow - 1; rowIndex >= 0; rowIndex-- {
  727. isDelete := true
  728. for _, v := range tableDataList[rowIndex] {
  729. if v.Monitor != `` || (v.MergeCell.Row != rowIndex && v.MergeCell.Row != 0) {
  730. isDelete = false
  731. flag = true
  732. break
  733. }
  734. }
  735. if flag {
  736. break
  737. }
  738. if isDelete {
  739. deleteBottomRowIndexList = append(deleteBottomRowIndexList, rowIndex)
  740. selfTableData.RemoveBottomRow++
  741. }
  742. }
  743. if len(deleteBottomRowIndexList) > 0 {
  744. deleteRowIndexList = append(deleteRowIndexList, utils.RevSlice(deleteBottomRowIndexList)...)
  745. }
  746. lenDeleteRow := len(deleteRowIndexList)
  747. if lenDeleteRow > 0 {
  748. for rowIndex := lenDeleteRow - 1; rowIndex >= 0; rowIndex-- {
  749. //表格数据
  750. tableDataList = append(tableDataList[:deleteRowIndexList[rowIndex]], tableDataList[deleteRowIndexList[rowIndex]+1:]...) // 删除开头N个元素
  751. //表格高度
  752. rowHeightList = append(rowHeightList[:deleteRowIndexList[rowIndex]], rowHeightList[deleteRowIndexList[rowIndex]+1:]...) // 删除开头N个元素
  753. }
  754. }
  755. }
  756. //移除前后空列
  757. deleteColumnIndexList := make([]int, 0)
  758. if len(tableDataList) > 0 {
  759. var flag = false
  760. lenColumn := len(tableDataList[0])
  761. // 移除前方空列
  762. for columnIndex := 0; columnIndex < lenColumn; columnIndex++ {
  763. isDelete := true
  764. for _, v := range tableDataList {
  765. //如果一列都没有,说明是上面几行是空行,没有数据
  766. if len(v) <= 0 {
  767. continue
  768. }
  769. if v[columnIndex].Monitor != `` {
  770. isDelete = false
  771. flag = true
  772. break
  773. }
  774. }
  775. if flag {
  776. break
  777. }
  778. if isDelete {
  779. selfTableData.RemoveLeftColumn++
  780. deleteColumnIndexList = append(deleteColumnIndexList, columnIndex)
  781. }
  782. }
  783. // 移除后方空列
  784. flag = false
  785. //后方
  786. deleteTailColumnIndexList := make([]int, 0)
  787. for columnIndex := lenColumn - 1; columnIndex >= 0; columnIndex-- {
  788. isDelete := true
  789. for _, v := range tableDataList {
  790. if v[columnIndex].Monitor != `` || (v[columnIndex].MergeCell.Column != columnIndex && v[columnIndex].MergeCell.Column != 0) {
  791. isDelete = false
  792. flag = true
  793. break
  794. }
  795. }
  796. if flag {
  797. break
  798. }
  799. if isDelete {
  800. deleteTailColumnIndexList = append(deleteTailColumnIndexList, columnIndex)
  801. selfTableData.RemoveRightColumn++
  802. }
  803. }
  804. if len(deleteTailColumnIndexList) > 0 {
  805. deleteColumnIndexList = append(deleteColumnIndexList, utils.RevSlice(deleteTailColumnIndexList)...)
  806. }
  807. lenDeleteColumn := len(deleteColumnIndexList)
  808. if lenDeleteColumn > 0 {
  809. for columnIndex := lenDeleteColumn - 1; columnIndex >= 0; columnIndex-- {
  810. //表格数据
  811. for k, v := range tableDataList {
  812. tableDataList[k] = append(v[:deleteColumnIndexList[columnIndex]], v[deleteColumnIndexList[columnIndex]+1:]...) // 删除开头N个元素
  813. }
  814. //表格宽度
  815. rowWidthList = append(rowWidthList[:deleteColumnIndexList[columnIndex]], rowWidthList[deleteColumnIndexList[columnIndex]+1:]...) // 删除开头N个元素
  816. }
  817. }
  818. }
  819. //处理合并单元格
  820. tableDataMergeList := make([]TableDataMerge, 0)
  821. for _, v := range item.Config.Merge {
  822. indexRow := v.Row - selfTableData.RemoveTopRow
  823. indexColumn := v.Column - selfTableData.RemoveLeftColumn
  824. tableDataMerge := TableDataMerge{
  825. StartRowIndex: indexRow,
  826. StartColumnIndex: indexColumn,
  827. MergeRowNum: v.Rs - 1,
  828. MergeColumnNum: v.Cs - 1,
  829. }
  830. tableDataMergeList = append(tableDataMergeList, tableDataMerge)
  831. }
  832. // 表格数据
  833. selfTableData.TableDataList = tableDataList
  834. selfTableData.RowWidthList = rowWidthList
  835. selfTableData.RowHeightList = rowHeightList
  836. selfTableData.MergeList = tableDataMergeList
  837. return
  838. }
  839. // GetTableDataByCustomData 通过自定义表格数据获取表格数据
  840. func GetTableDataByCustomData(excelType int, data request.TableDataReq) (selfTableData TableData, err error) {
  841. tableDataList := make([][]LuckySheetDataValue, 0)
  842. mergeList := make([]TableDataMerge, 0)
  843. // 指标数
  844. lenEdb := len(data.Data)
  845. if lenEdb <= 0 {
  846. return
  847. }
  848. // 日期数
  849. lenCol := len(data.Data[0].Data)
  850. if lenCol <= 0 {
  851. return
  852. }
  853. // 指标列:1;指标行:2
  854. if excelType == 1 {
  855. mergeList = append(mergeList, TableDataMerge{
  856. StartRowIndex: 0,
  857. StartColumnIndex: 0,
  858. MergeRowNum: 1,
  859. MergeColumnNum: 0,
  860. })
  861. // 第一行
  862. {
  863. firstCol := make([]LuckySheetDataValue, 0)
  864. firstCol = append(firstCol, LuckySheetDataValue{
  865. Value: "日期",
  866. Monitor: "日期",
  867. Background: "#505b78",
  868. FontColor: "#FFFFFF",
  869. MergeCell: LuckySheetDataConfigMerge{
  870. Row: 0, //行数
  871. Column: 0, //列数
  872. Rs: 2, //合并的行数
  873. Cs: 1, //合并的列数
  874. },
  875. })
  876. for _, v := range data.Data {
  877. edbName := v.EdbName
  878. if v.EdbAliasName != `` {
  879. edbName = v.EdbAliasName
  880. }
  881. firstCol = append(firstCol, LuckySheetDataValue{
  882. Value: edbName,
  883. Monitor: edbName,
  884. Background: "#505b78",
  885. FontColor: "#FFFFFF",
  886. MergeCell: LuckySheetDataConfigMerge{},
  887. })
  888. }
  889. tableDataList = append(tableDataList, firstCol)
  890. }
  891. // 第二行
  892. {
  893. secondCol := make([]LuckySheetDataValue, 0)
  894. secondCol = append(secondCol, LuckySheetDataValue{})
  895. for _, v := range data.Data {
  896. name := v.Unit + " / " + v.Frequency
  897. secondCol = append(secondCol, LuckySheetDataValue{
  898. Value: name,
  899. Monitor: name,
  900. Background: "#505b78",
  901. FontColor: "#FFFFFF",
  902. MergeCell: LuckySheetDataConfigMerge{},
  903. })
  904. }
  905. tableDataList = append(tableDataList, secondCol)
  906. }
  907. // 开始数据了
  908. {
  909. for i := 0; i < lenCol; i++ {
  910. dataCol := make([]LuckySheetDataValue, 0)
  911. // 日期
  912. dataCol = append(dataCol, LuckySheetDataValue{
  913. Value: data.Data[0].Data[i].DataTime,
  914. Monitor: data.Data[0].Data[i].DataTime,
  915. MergeCell: LuckySheetDataConfigMerge{},
  916. })
  917. // 数据值
  918. for _, v := range data.Data {
  919. background := ``
  920. if v.Data[i].DataType == 5 {
  921. background = "#ffefdd"
  922. }
  923. dataCol = append(dataCol, LuckySheetDataValue{
  924. Value: v.Data[i].Value,
  925. Monitor: v.Data[i].ShowValue,
  926. MergeCell: LuckySheetDataConfigMerge{},
  927. Background: background,
  928. })
  929. }
  930. tableDataList = append(tableDataList, dataCol)
  931. }
  932. }
  933. // 开始文本行了
  934. {
  935. for _, textColList := range data.TextRowData {
  936. dataCol := make([]LuckySheetDataValue, 0)
  937. for _, v := range textColList {
  938. dataCol = append(dataCol, LuckySheetDataValue{
  939. Value: v.Value,
  940. Monitor: v.ShowValue,
  941. MergeCell: LuckySheetDataConfigMerge{},
  942. })
  943. }
  944. tableDataList = append(tableDataList, dataCol)
  945. }
  946. }
  947. } else {
  948. // 指标行
  949. mergeList = append(mergeList, TableDataMerge{
  950. StartRowIndex: 0,
  951. StartColumnIndex: 0,
  952. MergeRowNum: 0,
  953. MergeColumnNum: 1,
  954. })
  955. // 第一行
  956. {
  957. firstCol := make([]LuckySheetDataValue, 0)
  958. firstCol = append(firstCol, LuckySheetDataValue{
  959. Value: "日期",
  960. Monitor: "日期",
  961. Background: "#505b78",
  962. FontColor: "#FFFFFF",
  963. MergeCell: LuckySheetDataConfigMerge{
  964. Row: 0, //行数
  965. Column: 0, //列数
  966. Rs: 1, //合并的行数
  967. Cs: 2, //合并的列数
  968. },
  969. })
  970. firstCol = append(firstCol, LuckySheetDataValue{})
  971. // 日期列
  972. for _, v := range data.Data[0].Data {
  973. firstCol = append(firstCol, LuckySheetDataValue{
  974. Value: v.DataTime,
  975. Monitor: v.DataTime,
  976. Background: "#efeef1",
  977. FontColor: "#666666",
  978. MergeCell: LuckySheetDataConfigMerge{},
  979. })
  980. }
  981. // 文本列
  982. for _, textColList := range data.TextRowData {
  983. firstCol = append(firstCol, LuckySheetDataValue{
  984. Value: textColList[0].Value,
  985. Monitor: textColList[0].ShowValue,
  986. Background: "#efeef1",
  987. FontColor: "#666666",
  988. MergeCell: LuckySheetDataConfigMerge{},
  989. })
  990. }
  991. tableDataList = append(tableDataList, firstCol)
  992. }
  993. // 日期列+文本列+两列表头(日期这个文案表头)
  994. //colLen := lenCol+2+len(data.TextRowData)
  995. for i := 0; i < lenEdb; i++ {
  996. dataCol := make([]LuckySheetDataValue, 0)
  997. // 指标信息
  998. tmpEdbInfo := data.Data[i]
  999. // 指标名称
  1000. {
  1001. edbName := tmpEdbInfo.EdbName
  1002. if tmpEdbInfo.EdbAliasName != `` {
  1003. edbName = tmpEdbInfo.EdbAliasName
  1004. }
  1005. dataCol = append(dataCol, LuckySheetDataValue{
  1006. Value: edbName,
  1007. Monitor: edbName,
  1008. Background: "#505b78",
  1009. FontColor: "#FFFFFF",
  1010. MergeCell: LuckySheetDataConfigMerge{},
  1011. })
  1012. }
  1013. // 指标单位、频度
  1014. {
  1015. name := tmpEdbInfo.Unit + " / " + tmpEdbInfo.Frequency
  1016. dataCol = append(dataCol, LuckySheetDataValue{
  1017. Value: name,
  1018. Monitor: name,
  1019. Background: "#505b78",
  1020. FontColor: "#FFFFFF",
  1021. MergeCell: LuckySheetDataConfigMerge{},
  1022. })
  1023. }
  1024. // 指标数据列
  1025. for _, tmpData := range tmpEdbInfo.Data {
  1026. background := ``
  1027. if tmpData.DataType == 5 {
  1028. background = "#ffefdd"
  1029. }
  1030. dataCol = append(dataCol, LuckySheetDataValue{
  1031. Value: tmpData.Value,
  1032. Monitor: tmpData.ShowValue,
  1033. MergeCell: LuckySheetDataConfigMerge{},
  1034. Background: background,
  1035. })
  1036. }
  1037. // 文本列
  1038. for _, textColList := range data.TextRowData {
  1039. dataCol = append(dataCol, LuckySheetDataValue{
  1040. Value: textColList[i+1].Value,
  1041. Monitor: textColList[i+1].ShowValue,
  1042. MergeCell: LuckySheetDataConfigMerge{},
  1043. })
  1044. }
  1045. tableDataList = append(tableDataList, dataCol)
  1046. }
  1047. }
  1048. selfTableData.MergeList = mergeList
  1049. selfTableData.TableDataList = tableDataList
  1050. return
  1051. }
  1052. // GetTableDataByMixedTableData 通过混合表格数据获取表格数据
  1053. func GetTableDataByMixedTableData(config [][]request.MixedTableCellDataReq) (selfTableData TableData, err error) {
  1054. tableDataList := make([][]LuckySheetDataValue, 0)
  1055. mergeList := make([]TableDataMerge, 0)
  1056. // 开始文本行了
  1057. {
  1058. for _, row := range config {
  1059. dataCol := make([]LuckySheetDataValue, 0)
  1060. for _, cell := range row {
  1061. tmp := LuckySheetDataValue{
  1062. Value: cell.Value,
  1063. Monitor: cell.ShowValue,
  1064. MergeCell: LuckySheetDataConfigMerge{},
  1065. }
  1066. if cell.ShowStyle != "" {
  1067. tmp.Monitor = cell.ShowFormatValue
  1068. }
  1069. dataCol = append(dataCol, tmp)
  1070. }
  1071. tableDataList = append(tableDataList, dataCol)
  1072. }
  1073. }
  1074. selfTableData.MergeList = mergeList
  1075. selfTableData.TableDataList = tableDataList
  1076. return
  1077. }