lucky_sheet.go 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692
  1. package excel
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "eta/eta_api/models/data_manage/excel/request"
  6. "eta/eta_api/utils"
  7. "fmt"
  8. "github.com/tealeg/xlsx"
  9. "github.com/xuri/excelize/v2"
  10. "os"
  11. "reflect"
  12. "strconv"
  13. "strings"
  14. "time"
  15. )
  16. type LuckySheetDataBak struct {
  17. CalcChain []interface{} `json:"calcChain" description:"公式链"`
  18. CellData []LuckySheetCellData `json:"celldata" description:"单元格数据"`
  19. ChWidth int64 `json:"ch_width" description:"工作表区域的宽度"`
  20. Config struct {
  21. BorderInfo []struct {
  22. BorderType string `json:"borderType" description:""`
  23. Color string `json:"color" description:""`
  24. Range []struct {
  25. Column []int64 `json:"column" description:""`
  26. Row []int64 `json:"row" description:""`
  27. } `json:"range" description:""`
  28. RangeType string `json:"rangeType" description:""`
  29. Style string `json:"style" description:""`
  30. Value struct {
  31. B struct {
  32. Color string `json:"color" description:""`
  33. Style string `json:"style" description:""`
  34. } `json:"b" description:""`
  35. ColIndex int64 `json:"col_index" description:""`
  36. L struct {
  37. Color string `json:"color" description:""`
  38. Style string `json:"style" description:""`
  39. } `json:"l" description:""`
  40. R struct {
  41. Color string `json:"color" description:""`
  42. Style string `json:"style" description:""`
  43. } `json:"r" description:""`
  44. RowIndex int64 `json:"row_index" description:""`
  45. T struct {
  46. Color string `json:"color" description:""`
  47. Style string `json:"style" description:""`
  48. } `json:"t" description:""`
  49. } `json:"value" description:"" description:""`
  50. } `json:"borderInfo" description:""`
  51. Colhidden struct{} `json:"colhidden" description:""`
  52. Columnlen map[string]float64 `json:"columnlen" description:""`
  53. CustomHeight struct {
  54. Zero int64 `json:"0"`
  55. } `json:"customHeight" description:""`
  56. CustomWidth struct {
  57. Two int64 `json:"2" description:""`
  58. } `json:"customWidth" description:""`
  59. Merge struct{} `json:"merge" description:""`
  60. Rowlen map[string]float64 `json:"rowlen" description:""`
  61. } `json:"config" description:""`
  62. Data [][]struct {
  63. Ct struct {
  64. Fa string `json:"fa"`
  65. T string `json:"t"`
  66. } `json:"ct"`
  67. M string `json:"m"`
  68. V interface{} `json:"v"`
  69. } `json:"data" description:""`
  70. DataVerification struct{} `json:"dataVerification" description:""`
  71. Filter interface{} `json:"filter" description:""`
  72. FilterSelect interface{} `json:"filter_select" description:""`
  73. Hyperlink struct{} `json:"hyperlink" description:""`
  74. Images struct{} `json:"images" description:""`
  75. Index string `json:"index" description:""`
  76. JfgirdSelectSave []interface{} `json:"jfgird_select_save" description:""`
  77. LuckysheetAlternateformatSave []interface{} `json:"luckysheet_alternateformat_save" description:""`
  78. LuckysheetConditionformatSave []interface{} `json:"luckysheet_conditionformat_save" description:""`
  79. LuckysheetSelectSave []struct {
  80. Column []int64 `json:"column" description:""`
  81. ColumnFocus int64 `json:"column_focus" description:""`
  82. Height int64 `json:"height" description:""`
  83. HeightMove int64 `json:"height_move" description:""`
  84. Left int64 `json:"left" description:""`
  85. LeftMove int64 `json:"left_move" description:""`
  86. Row []int64 `json:"row" description:""`
  87. RowFocus int64 `json:"row_focus" description:""`
  88. Top int64 `json:"top" description:""`
  89. TopMove int64 `json:"top_move" description:""`
  90. Width int64 `json:"width" description:""`
  91. WidthMove int64 `json:"width_move" description:""`
  92. } `json:"luckysheet_select_save" description:"" description:""`
  93. LuckysheetSelectionRange []struct {
  94. Column []int64 `json:"column" description:""`
  95. Row []int64 `json:"row" description:""`
  96. } `json:"luckysheet_selection_range" description:""`
  97. RhHeight float64 `json:"rh_height" description:""`
  98. ScrollLeft float64 `json:"scrollLeft" description:""`
  99. ScrollTop float64 `json:"scrollTop" description:""`
  100. Status int64 `json:"status" description:""`
  101. Visibledatacolumn []int64 `json:"visibledatacolumn" description:""`
  102. Visibledatarow []int64 `json:"visibledatarow" description:""`
  103. ZoomRatio float64 `json:"zoomRatio" description:"sheet缩放比例"`
  104. }
  105. // LuckySheetData sheet表格数据
  106. type LuckySheetData struct {
  107. Name string `json:"name" description:"工作表名称"`
  108. Index int `json:"index" description:"工作表索引"`
  109. Row int `json:"row" description:"行数"`
  110. Column int `json:"column" description:"列数"`
  111. CellData []LuckySheetCellData `json:"celldata" description:"单元格数据"`
  112. ChWidth int64 `json:"ch_width" description:"工作表区域的宽度"`
  113. Config LuckySheetDataConfig `json:"config" description:""`
  114. //Index int `json:"index" description:"工作表索引"`
  115. RhHeight float64 `json:"rh_height" description:"工作表区域的高度"`
  116. ScrollLeft float64 `json:"scrollLeft" description:"左右滚动条位置"`
  117. ScrollTop float64 `json:"scrollTop" description:"上下滚动条位置"`
  118. CalcChain []interface{} `json:"calcChain" description:"公式链"`
  119. Status int64 `json:"status" description:"激活状态"`
  120. VisibleDataColumn []int64 `json:"visibledatacolumn" description:"所有列的位置信息,递增的列位置数据,初始化无需设置"`
  121. VisibleDataRow []int64 `json:"visibledatarow" description:"所有行的位置信息,递增的行位置数据,初始化无需设置"`
  122. ZoomRatio float64 `json:"zoomRatio" description:"sheet缩放比例"`
  123. }
  124. // LuckySheetDataConfig sheet表单的配置
  125. type LuckySheetDataConfig struct {
  126. BorderInfo []LuckySheetDataConfigBorderInfo `json:"borderInfo" description:"边框"`
  127. Colhidden map[string]int64 `json:"colhidden" description:"隐藏列,示例值:\"colhidden\":{\"30\":0,\"31\":0}"`
  128. Columnlen map[string]float64 `json:"columnlen" description:"每个单元格的列宽"`
  129. //CustomHeight struct {
  130. // Zero int64 `json:"0"`
  131. //} `json:"customHeight" description:""`
  132. //CustomWidth struct {
  133. // Two int64 `json:"2" description:""`
  134. //} `json:"customWidth" description:""`
  135. Merge map[string]LuckySheetDataConfigMerge `json:"merge" description:"合并单元格"`
  136. Rowlen map[string]float64 `json:"rowlen" description:"每个单元格的行高"`
  137. }
  138. // LuckySheetDataConfigMerge 合并单元格设置
  139. type LuckySheetDataConfigMerge struct {
  140. Row int `json:"r" description:"行数"`
  141. Column int `json:"c" description:"列数"`
  142. Rs int `json:"rs" description:"合并的行数"`
  143. Cs int `json:"cs" description:"合并的列数"`
  144. }
  145. // LuckySheetDataConfigBorderInfo 单元格边框信息
  146. type LuckySheetDataConfigBorderInfo struct {
  147. 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"`
  148. Color string `json:"color" description:"边框颜色 color: 16进制颜色值"`
  149. Range []struct {
  150. Column []int64 `json:"column" description:"行"`
  151. Row []int64 `json:"row" description:"列"`
  152. } `json:"range" description:"选区范围 range: 行列信息数组"`
  153. RangeType string `json:"rangeType" description:"选区 rangeType: range | cell "`
  154. 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"`
  155. Value LuckySheetDataConfigBorderInfoCellValue `json:"value" description:"" description:"范围类型分单个单元格的数据"`
  156. }
  157. // LuckySheetDataConfigBorderInfoCellValue 单元格边框信息(范围类型为:单个单元格)
  158. type LuckySheetDataConfigBorderInfoCellValue struct {
  159. B LuckySheetDataConfigBorderInfoCell `json:"b" description:"下边框"`
  160. L LuckySheetDataConfigBorderInfoCell `json:"l" description:"左边框"`
  161. R LuckySheetDataConfigBorderInfoCell `json:"r" description:"右边框"`
  162. T LuckySheetDataConfigBorderInfoCell `json:"t" description:"上边框"`
  163. ColIndex int64 `json:"col_index" description:"第几行"`
  164. RowIndex int64 `json:"row_index" description:"第几列"`
  165. }
  166. // LuckySheetDataConfigBorderInfoCell 单元格边框信息(cell类型)
  167. type LuckySheetDataConfigBorderInfoCell struct {
  168. Color string `json:"color" description:"边框颜色 color: 16进制颜色值"`
  169. 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"`
  170. 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"`
  171. }
  172. // LuckySheetCellData 单个单元格数据
  173. type LuckySheetCellData struct {
  174. Col int64 `json:"c" description:"列"`
  175. Row int64 `json:"r" description:"行"`
  176. Value LuckySheetDataValue `json:"v" description:"单元格内值的数据"`
  177. }
  178. // LuckySheetDataValue 单元格内值的数据
  179. type LuckySheetDataValue struct {
  180. CellType LuckySheetDataCellType `json:"ct" description:"单元格值格式:文本、时间等 "`
  181. Value interface{} `json:"v" description:"原始值"`
  182. Monitor string `json:"m" description:"显示值"`
  183. Background string `json:"bg" description:"背景色,实例值:#fff000"`
  184. 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 华文隶书 "`
  185. 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 华文隶书 "`
  186. FontColor string `json:"fc" description:"字体颜色,示例值:#fff000" `
  187. Bold int `json:"bl" description:"粗体,0 常规 、 1加粗 "`
  188. Italic int `json:"it" description:"斜体,0 常规 、 1 斜体"`
  189. Fontsize int `description:"字体大小,14"`
  190. CancelLine int ` description:"删除线, 0 常规 、 1 删除线"`
  191. HorizontalType int `description:"水平对齐, 0 居中、1 左、2右"`
  192. VerticalType int ` description:"垂直对齐, 0 中间、1 上、2下"`
  193. Fs interface{} `json:"fs" description:"字体大小,14"`
  194. Cl interface{} `json:"cl" description:"删除线, 0 常规 、 1 删除线"`
  195. Ht interface{} `json:"ht" description:"水平对齐, 0 居中、1 左、2右"`
  196. Vt interface{} `json:"vt" description:"垂直对齐, 0 中间、1 上、2下"`
  197. //TextRotate string `json:"tr" description:"竖排文字, 3"`
  198. //RotateText string `json:"rt" description:"文字旋转角度, 介于0~180之间的整数,包含0和180"`
  199. TextBeak int `description:"文本换行, 0 截断、1溢出、2 自动换行"`
  200. Tb interface{} `json:"tb" description:"文本换行, 0 截断、1溢出、2 自动换行"`
  201. Ps LuckySheetDataCellComment `json:"ps" description:"批注"`
  202. Function string `json:"f" description:"公式"`
  203. MergeCell LuckySheetDataConfigMerge `json:"mc" description:"合并单元格信息"`
  204. }
  205. // LuckySheetDataCellType 单元格值格式:文本、时间等
  206. type LuckySheetDataCellType struct {
  207. Fa string `json:"fa" description:"格式名称,例如:“General”为自动格式"`
  208. T string `json:"t" description:"格式类型,例如:“n”为数字类型"`
  209. S []struct {
  210. 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 华文隶书 "`
  211. 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 华文隶书 "`
  212. FontColor string `json:"fc" description:"字体颜色,示例值:#fff000" `
  213. Fontsize int `description:"字体大小,14"`
  214. CancelLine int ` description:"删除线, 0 常规 、 1 删除线"`
  215. HorizontalType int `description:"水平对齐, 0 居中、1 左、2右"`
  216. VerticalType int `description:"垂直对齐, 0 中间、1 上、2下"`
  217. Fs interface{} `json:"fs" description:"字体大小,14"`
  218. Cl interface{} `json:"cl" description:"删除线, 0 常规 、 1 删除线"`
  219. Ht interface{} `json:"ht" description:"水平对齐, 0 居中、1 左、2右"`
  220. Vt interface{} `json:"vt" description:"垂直对齐, 0 中间、1 上、2下"`
  221. Un int `json:"un" description:""`
  222. Bold int `json:"bl" description:"粗体,0 常规 、 1加粗 "`
  223. Italic int `json:"it" description:"斜体,0 常规 、 1 斜体"`
  224. Value interface{} `json:"v" description:"原始值"`
  225. } `json:"s"`
  226. }
  227. // LuckySheetDataCellComment 批注
  228. type LuckySheetDataCellComment struct {
  229. Left int `json:"left" description:"批注框距离左边工作表边缘位置"`
  230. Top int `json:"top" description:"批注框距离上边工作表边缘位置"`
  231. Width int `json:"width" description:"批注框宽度"`
  232. Height int `json:"height" description:"批注框高度"`
  233. Value string `json:"value" description:"批注内容"`
  234. IsShow bool `json:"isshow" description:"是否显示批注"`
  235. }
  236. // GetLuckySheetData 获取LuckySheetData的结构体
  237. func GetLuckySheetData(jsonStr string) (item *LuckySheetData, err error) {
  238. err = json.Unmarshal([]byte(jsonStr), &item)
  239. for k, v := range item.CellData {
  240. value := v.Value
  241. value.Fontsize = getIntValueByInterface(value.Fs)
  242. value.CancelLine = getIntValueByInterface(value.Cl)
  243. value.HorizontalType = getIntValueByInterface(value.Ht)
  244. value.VerticalType = getIntValueByInterface(value.Vt)
  245. value.FontFamily = getIntValueByInterface(value.FF)
  246. value.TextBeak = getIntValueByInterface(value.Tb)
  247. if len(value.CellType.S) > 0 {
  248. for kk, vv := range value.CellType.S {
  249. vv.Fontsize = getIntValueByInterface(vv.Fs)
  250. vv.CancelLine = getIntValueByInterface(vv.Cl)
  251. vv.HorizontalType = getIntValueByInterface(vv.Ht)
  252. vv.VerticalType = getIntValueByInterface(vv.Vt)
  253. vv.FontFamily = getIntValueByInterface(vv.FF)
  254. value.CellType.S[kk] = vv
  255. }
  256. }
  257. item.CellData[k].Value = value
  258. }
  259. if len(item.Config.BorderInfo) > 0 {
  260. for k, v := range item.Config.BorderInfo {
  261. v.Value.T.Style = getIntValueByInterface(v.Value.T.Style)
  262. v.Value.B.Style = getIntValueByInterface(v.Value.B.Style)
  263. v.Value.L.Style = getIntValueByInterface(v.Value.L.Style)
  264. v.Value.R.Style = getIntValueByInterface(v.Value.R.Style)
  265. item.Config.BorderInfo[k] = v
  266. }
  267. }
  268. return
  269. }
  270. func getIntValueByInterface(valInterface interface{}) (val int) {
  271. if valInterface == nil {
  272. return
  273. }
  274. switch reflect.TypeOf(valInterface).Kind() {
  275. case reflect.String:
  276. tmpValue := reflect.ValueOf(valInterface).String()
  277. tmpValInt, err := strconv.Atoi(tmpValue)
  278. if err != nil {
  279. val = 0
  280. } else {
  281. val = tmpValInt
  282. }
  283. case reflect.Int, reflect.Int32, reflect.Int64:
  284. tmpValue := reflect.ValueOf(valInterface).Int()
  285. val = int(tmpValue)
  286. }
  287. return
  288. }
  289. // TableData 表格数据
  290. type TableData struct {
  291. TableDataList [][]LuckySheetDataValue
  292. RowWidthList []float64
  293. RowHeightList []float64
  294. RemoveTopRow int `description:"移除表格上方的行数"`
  295. RemoveBottomRow int `description:"移除表格下方的行数"`
  296. RemoveLeftColumn int `description:"移除表格左侧的列数"`
  297. RemoveRightColumn int `description:"移除表格右侧的列数"`
  298. MergeList []TableDataMerge `description:"合并数据列"`
  299. }
  300. // TableDataMerge 表格数据合并单元格配置
  301. type TableDataMerge struct {
  302. StartRowIndex int `json:"start_row_index" description:"开始的行下标"`
  303. StartColumnIndex int `json:"start_column" description:"开始的列下标"`
  304. MergeRowNum int `json:"merge_row_num" description:"合并的行数"`
  305. MergeColumnNum int `json:"merge_column_num" description:"合并的列数"`
  306. }
  307. // ToExcel 通过 TableData生成excel表格
  308. func (tableData TableData) ToExcel() (downloadFilePath string, err error) {
  309. //dir, err := os.Executable()
  310. //exPath := filepath.Dir(dir)
  311. //downloadFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  312. downloadFilePath, err = getDownloadPath()
  313. if err != nil {
  314. return
  315. }
  316. xlsxFile := xlsx.NewFile()
  317. if err != nil {
  318. return
  319. }
  320. // 将单个sheet的数据写入到excel
  321. err = tableData.WriteExcelSheetData(xlsxFile, "sheet1")
  322. if err != nil {
  323. return
  324. }
  325. //return
  326. err = xlsxFile.Save(downloadFilePath)
  327. if err != nil {
  328. return
  329. }
  330. //randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  331. //downloadFileName := "即将到期客户数据_" + randStr + ".xlsx"
  332. //this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  333. return
  334. }
  335. // WriteExcelSheetData 通过 TableData生成excel表格数据
  336. func (tableData TableData) WriteExcelSheetData(xlsxFile *xlsx.File, sheetName string) (err error) {
  337. style := xlsx.NewStyle()
  338. alignment := xlsx.Alignment{
  339. Horizontal: "center",
  340. Vertical: "center",
  341. WrapText: true,
  342. }
  343. style.Alignment = alignment
  344. style.ApplyAlignment = true
  345. sheet, err := xlsxFile.AddSheet(sheetName)
  346. if err != nil {
  347. return
  348. }
  349. for k, v := range tableData.RowWidthList {
  350. err = sheet.SetColWidth(k, k, v/10)
  351. if err != nil {
  352. return
  353. }
  354. }
  355. // 单元格高度配置列表
  356. lenRowHeight := len(tableData.RowHeightList)
  357. for index, v := range tableData.TableDataList {
  358. tmpRow := sheet.AddRow()
  359. //设置单元格高度
  360. if index < lenRowHeight && tableData.RowHeightList[index] > 0 {
  361. tmpRow.SetHeight(tableData.RowHeightList[index] / 2)
  362. }
  363. for _, cellInfo := range v {
  364. tmpStyle := new(xlsx.Style)
  365. //xlsx.Style{
  366. // Fill: xlsx.Fill{},
  367. // ApplyBorder: false,
  368. // ApplyFill: false,
  369. // ApplyFont: false,
  370. // NamedStyleIndex: nil,
  371. //}
  372. //fill := *NewFill("solid", "FF000000", "00FF0000")
  373. defaultFill := xlsx.DefaultFill()
  374. if cellInfo.Background != `` {
  375. defaultFill.PatternType = "solid"
  376. backgroundColor := cellInfo.Background
  377. // 这么做是为了避免传入的是RGB的格式(rgb(255, 255, 255))
  378. backgroundColor = getColor(backgroundColor)
  379. defaultFill.BgColor = strings.TrimPrefix(backgroundColor, "#")
  380. defaultFill.FgColor = strings.TrimPrefix(backgroundColor, "#")
  381. }
  382. tmpStyle.Fill = *defaultFill
  383. // 获取表格字体配置
  384. tmpStyle.Font = getExcelFontConf(cellInfo)
  385. //获取表格单元格排列配置
  386. tmpStyle.ApplyAlignment = true
  387. tmpStyle.Alignment = getExcelAlignmentConf(cellInfo)
  388. //边框配置
  389. tmpStyle.Border = xlsx.Border{
  390. Left: "thin",
  391. LeftColor: "000000",
  392. Right: "thin",
  393. RightColor: "000000",
  394. Top: "thin",
  395. TopColor: "000000",
  396. Bottom: "thin",
  397. BottomColor: "000000",
  398. }
  399. //tmpStyle.ApplyAlignment = true
  400. //tmpStyle.Alignment.WrapText = true
  401. tmpRow := tmpRow.AddCell()
  402. tmpRow.SetStyle(tmpStyle)
  403. valueStr := cellInfo.Monitor
  404. if valueStr == `` {
  405. //valueStr = fmt.Sprint(cellInfo.Value)
  406. if valueStr == `` && cellInfo.CellType.S != nil {
  407. //不是设置在单元格上面,而是设置在文本上
  408. for _, cellS := range cellInfo.CellType.S {
  409. valueStr += fmt.Sprint(cellS.Value)
  410. }
  411. }
  412. }
  413. //tmpRow.SetString(valueStr)
  414. switch cellInfo.CellType.Fa {
  415. case "General":
  416. if cellInfo.CellType.S != nil {
  417. tmpRow.SetString(valueStr)
  418. } else {
  419. tmpRow.SetValue(cellInfo.Value)
  420. }
  421. case "@":
  422. tmpRow.SetString(valueStr)
  423. default:
  424. tmpRow.SetString(valueStr)
  425. }
  426. if cellInfo.Function != `` {
  427. //xlsxFile.
  428. //xlsxFile.SetCellFormula
  429. tmpRow.SetFormula(cellInfo.Function)
  430. }
  431. //if cellInfo.Function != `` {
  432. // tmpRow.SetFormula(cellInfo.Function)
  433. //}
  434. }
  435. }
  436. for _, v := range tableData.MergeList {
  437. for k, cell := range sheet.Row(v.StartRowIndex).Cells {
  438. if v.StartColumnIndex == k {
  439. cell.Merge(v.MergeColumnNum, v.MergeRowNum)
  440. }
  441. }
  442. }
  443. return
  444. }
  445. // GetTableDataByLuckySheetDataStr 通过LuckySheet的string数据获取表格数据
  446. func (item *LuckySheetData) GetTableDataByLuckySheetDataStr() (selfTableData TableData, err error) {
  447. luckySheetCellDataList := item.CellData
  448. // 表格数据
  449. tableDataMap := make(map[int64]map[int64]LuckySheetDataValue)
  450. // 最大行,最大列
  451. var maxRow, maxCol int64
  452. for _, v := range luckySheetCellDataList {
  453. //fmt.Println("row:", v.Row, "=====col:", v.Col)
  454. if v.Row > maxRow { //最大行
  455. maxRow = v.Row
  456. }
  457. if v.Col > maxCol { //最大列
  458. maxCol = v.Col
  459. }
  460. var tmpRow map[int64]LuckySheetDataValue
  461. tmpRow, ok := tableDataMap[v.Row]
  462. if ok {
  463. tmpRow[v.Col] = v.Value
  464. } else {
  465. tmpRow = make(map[int64]LuckySheetDataValue)
  466. tmpRow[v.Col] = v.Value
  467. }
  468. tableDataMap[v.Row] = tmpRow
  469. }
  470. tableDataList := make([][]LuckySheetDataValue, 0)
  471. var i int64
  472. // 单元格宽度
  473. configColumnConf := item.Config.Columnlen
  474. rowWidthMap := make(map[int]float64)
  475. rowWidthList := make([]float64, 0) //
  476. // 单元格高度
  477. configRowConf := item.Config.Rowlen
  478. rowHeightList := make([]float64, 0) //
  479. for i = 0; i <= maxRow; i++ {
  480. //列
  481. tmpTableColDataList := make([]LuckySheetDataValue, 0)
  482. // 每个单元格的高度
  483. tmpHeight, ok := configRowConf[fmt.Sprint(i)]
  484. if !ok {
  485. tmpHeight = 0
  486. }
  487. rowHeightList = append(rowHeightList, tmpHeight)
  488. tmpRowData, ok := tableDataMap[i]
  489. // 如果没有该行数据,那么就默认添加空行数据处理
  490. if !ok {
  491. tmpRowData = make(map[int64]LuckySheetDataValue)
  492. }
  493. var j int64
  494. for j = 0; j <= maxCol; j++ {
  495. tmpTableColData, ok := tmpRowData[j]
  496. if !ok {
  497. tmpTableColData = LuckySheetDataValue{}
  498. }
  499. //单元格显示的数据处理
  500. tmpTableColData.Monitor = handleCellVal(tmpTableColData)
  501. tmpTableColDataList = append(tmpTableColDataList, tmpTableColData)
  502. // 每个单元格的宽度
  503. tmpWidth, ok := configColumnConf[fmt.Sprint(j)]
  504. if !ok {
  505. tmpWidth = 0
  506. }
  507. rowIndex := len(tmpTableColDataList) - 1
  508. if _, ok2 := rowWidthMap[rowIndex]; !ok2 {
  509. rowWidthList = append(rowWidthList, tmpWidth)
  510. }
  511. rowWidthMap[rowIndex] = tmpWidth
  512. }
  513. tableDataList = append(tableDataList, tmpTableColDataList)
  514. }
  515. // 数据处理,移除上下左右空行空列
  516. tableDataList, tableRemoveNum, rowHeightList, rowWidthList, tableDataMergeList := handleTableDataList(tableDataList, item.Config.Merge, rowHeightList, rowWidthList)
  517. // 表格数据
  518. {
  519. // 移除空白单元格信息
  520. selfTableData.RemoveTopRow = tableRemoveNum.RemoveTopRow
  521. selfTableData.RemoveBottomRow = tableRemoveNum.RemoveBottomRow
  522. selfTableData.RemoveLeftColumn = tableRemoveNum.RemoveLeftColumn
  523. selfTableData.RemoveRightColumn = tableRemoveNum.RemoveRightColumn
  524. }
  525. selfTableData.TableDataList = tableDataList
  526. selfTableData.RowWidthList = rowWidthList
  527. selfTableData.RowHeightList = rowHeightList
  528. selfTableData.MergeList = tableDataMergeList
  529. return
  530. }
  531. // TableRemoveNum 上下左右移除的空行空列数量
  532. type TableRemoveNum struct {
  533. RemoveTopRow int `description:"移除表格上方的行数"`
  534. RemoveBottomRow int `description:"移除表格下方的行数"`
  535. RemoveLeftColumn int `description:"移除表格左侧的列数"`
  536. RemoveRightColumn int `description:"移除表格右侧的列数"`
  537. }
  538. // handleTableDataList 表格数据处理(移除上下左右的空行空列)
  539. func handleTableDataList(tableDataList [][]LuckySheetDataValue, luckySheetDataConfigMergeList map[string]LuckySheetDataConfigMerge, rowHeightList, rowWidthList []float64) ([][]LuckySheetDataValue, TableRemoveNum, []float64, []float64, []TableDataMerge) {
  540. var removeTopRow, removeBottomRow, removeLeftColumn, removeRightColumn int //上下左右需要移除的空行空列
  541. tableDataMergeList := make([]TableDataMerge, 0) //待合并的单元格信息
  542. //总共多少行
  543. lenRow := len(tableDataList)
  544. //移除上下空行
  545. deleteRowIndexList := make([]int, 0)
  546. if lenRow > 0 {
  547. var flag = false
  548. // 移除上方空列
  549. for rowIndex := 0; rowIndex < lenRow; rowIndex++ {
  550. isDelete := true
  551. for _, v := range tableDataList[rowIndex] {
  552. if v.Monitor != `` || (v.MergeCell.Row != rowIndex && v.MergeCell.Row != 0) {
  553. isDelete = false
  554. flag = true
  555. break
  556. }
  557. }
  558. if flag {
  559. break
  560. }
  561. if isDelete {
  562. removeTopRow++
  563. deleteRowIndexList = append(deleteRowIndexList, rowIndex)
  564. }
  565. }
  566. // 移除下方空行
  567. flag = false
  568. //尾部
  569. deleteBottomRowIndexList := make([]int, 0)
  570. // 数据第1行不处理
  571. for rowIndex := lenRow - 1; rowIndex > removeTopRow; rowIndex-- {
  572. isDelete := true
  573. for _, v := range tableDataList[rowIndex] {
  574. if v.Monitor != `` {
  575. isDelete = false
  576. flag = true
  577. break
  578. }
  579. }
  580. if flag {
  581. break
  582. }
  583. if isDelete {
  584. deleteBottomRowIndexList = append(deleteBottomRowIndexList, rowIndex)
  585. removeBottomRow++
  586. }
  587. }
  588. if len(deleteBottomRowIndexList) > 0 {
  589. deleteRowIndexList = append(deleteRowIndexList, utils.RevSlice(deleteBottomRowIndexList)...)
  590. }
  591. lenDeleteRow := len(deleteRowIndexList)
  592. if lenDeleteRow > 0 {
  593. for rowIndex := lenDeleteRow - 1; rowIndex >= 0; rowIndex-- {
  594. //表格数据
  595. tableDataList = append(tableDataList[:deleteRowIndexList[rowIndex]], tableDataList[deleteRowIndexList[rowIndex]+1:]...) // 删除开头N个元素
  596. //表格高度
  597. rowHeightList = append(rowHeightList[:deleteRowIndexList[rowIndex]], rowHeightList[deleteRowIndexList[rowIndex]+1:]...) // 删除开头N个元素
  598. }
  599. }
  600. }
  601. //移除左右空列
  602. deleteColumnIndexList := make([]int, 0)
  603. if len(tableDataList) > 0 {
  604. var flag = false
  605. lenColumn := len(tableDataList[0])
  606. // 移除左边空列
  607. for columnIndex := 0; columnIndex < lenColumn; columnIndex++ {
  608. isDelete := true
  609. for _, v := range tableDataList {
  610. //如果一列都没有,说明是上面几行是空行,没有数据
  611. if len(v) <= 0 {
  612. continue
  613. }
  614. if v[columnIndex].Monitor != `` || (v[columnIndex].MergeCell.Column != columnIndex && v[columnIndex].MergeCell.Column != 0) {
  615. isDelete = false
  616. flag = true
  617. break
  618. }
  619. }
  620. if flag {
  621. break
  622. }
  623. if isDelete {
  624. removeLeftColumn++
  625. deleteColumnIndexList = append(deleteColumnIndexList, columnIndex)
  626. }
  627. }
  628. // 移除右方空列
  629. flag = false
  630. //右边
  631. deleteTailColumnIndexList := make([]int, 0)
  632. // 数据第1列不处理
  633. for columnIndex := lenColumn - 1; columnIndex > removeLeftColumn; columnIndex-- {
  634. isDelete := true
  635. for _, v := range tableDataList {
  636. //如果一列都没有,说明是上面几行是空行,没有数据
  637. if len(v) <= 0 {
  638. continue
  639. }
  640. if v[columnIndex].Monitor != `` || (v[columnIndex].MergeCell.Column != columnIndex && v[columnIndex].MergeCell.Column != 0) {
  641. isDelete = false
  642. flag = true
  643. break
  644. }
  645. }
  646. if flag {
  647. break
  648. }
  649. if isDelete {
  650. deleteTailColumnIndexList = append(deleteTailColumnIndexList, columnIndex)
  651. removeRightColumn++
  652. }
  653. }
  654. if len(deleteTailColumnIndexList) > 0 {
  655. deleteColumnIndexList = append(deleteColumnIndexList, utils.RevSlice(deleteTailColumnIndexList)...)
  656. }
  657. lenDeleteColumn := len(deleteColumnIndexList)
  658. if lenDeleteColumn > 0 {
  659. for columnIndex := lenDeleteColumn - 1; columnIndex >= 0; columnIndex-- {
  660. //表格数据
  661. for k, v := range tableDataList {
  662. tableDataList[k] = append(v[:deleteColumnIndexList[columnIndex]], v[deleteColumnIndexList[columnIndex]+1:]...) // 删除开头N个元素
  663. }
  664. //表格宽度
  665. rowWidthList = append(rowWidthList[:deleteColumnIndexList[columnIndex]], rowWidthList[deleteColumnIndexList[columnIndex]+1:]...) // 删除开头N个元素
  666. }
  667. }
  668. }
  669. //处理合并单元格
  670. for _, v := range luckySheetDataConfigMergeList {
  671. indexRow := v.Row - removeTopRow
  672. indexColumn := v.Column - removeLeftColumn
  673. tableDataMerge := TableDataMerge{
  674. StartRowIndex: indexRow,
  675. StartColumnIndex: indexColumn,
  676. MergeRowNum: v.Rs - 1,
  677. MergeColumnNum: v.Cs - 1,
  678. }
  679. tableDataMergeList = append(tableDataMergeList, tableDataMerge)
  680. }
  681. return tableDataList, TableRemoveNum{
  682. RemoveTopRow: removeTopRow,
  683. RemoveBottomRow: removeBottomRow,
  684. RemoveLeftColumn: removeLeftColumn,
  685. RemoveRightColumn: removeRightColumn,
  686. }, rowHeightList, rowWidthList, tableDataMergeList
  687. }
  688. // ToExcel 通过 luckySheetData生成excel表格
  689. func (item *LuckySheetData) ToExcel() (downloadFilePath string, err error) {
  690. tableData, err := item.GetTableDataByLuckySheetDataStr()
  691. if err != nil {
  692. return
  693. }
  694. downloadFilePath, err = tableData.ToExcel()
  695. return
  696. }
  697. // getDownloadPath 获取下载地址
  698. func getDownloadPath() (fpath string, err error) {
  699. dateDir := time.Now().Format("20060102")
  700. uploadDir := "static/xls/" + dateDir
  701. err = os.MkdirAll(uploadDir, 0766)
  702. if err != nil {
  703. return
  704. }
  705. randStr := utils.GetRandStringNoSpecialChar(28)
  706. fileName := randStr + ".xlsx"
  707. fpath = uploadDir + "/" + fileName
  708. return
  709. }
  710. // getExcelFontConf 获取表格字体配置
  711. func getExcelFontConf(cellInfo LuckySheetDataValue) xlsx.Font {
  712. fontSize := 10
  713. familyName := ``
  714. var isBold, isItalic, isUnderline bool
  715. // 字体
  716. {
  717. if cellInfo.Bold == 1 {
  718. isBold = true
  719. }
  720. if cellInfo.Italic == 1 {
  721. isItalic = true
  722. }
  723. if cellInfo.CancelLine == 1 {
  724. isUnderline = true
  725. }
  726. //if cellInfo.Fontsize != `` {
  727. // convSize, _ := strconv.Atoi(cellInfo.Fontsize)
  728. // if convSize > 0 {
  729. // fontSize = convSize
  730. // }
  731. //}
  732. if cellInfo.Fontsize > 0 {
  733. fontSize = cellInfo.Fontsize
  734. }
  735. tmpFamilyName, familyNameOk := LuckyFontFamilyMap[cellInfo.FontFamily]
  736. if !familyNameOk {
  737. tmpFamilyName = "宋体"
  738. }
  739. familyName = tmpFamilyName
  740. }
  741. return xlsx.Font{
  742. Size: fontSize,
  743. Name: familyName,
  744. //Family: v2.FontFamily,
  745. //Charset: 0,
  746. Color: strings.TrimPrefix(cellInfo.FontColor, "#"),
  747. Bold: isBold,
  748. Italic: isItalic,
  749. Underline: isUnderline,
  750. }
  751. }
  752. // getExcelAlignmentConf 获取表格单元格排列配置
  753. func getExcelAlignmentConf(cellInfo LuckySheetDataValue) xlsx.Alignment {
  754. //自动换行
  755. isWrapText := false
  756. if cellInfo.TextBeak == 2 {
  757. isWrapText = true
  758. }
  759. rotateText := 0
  760. //if cellInfo.RotateText != `` {
  761. // convSize, _ := strconv.Atoi(cellInfo.RotateText)
  762. // if convSize > 0 {
  763. // rotateText = convSize
  764. // }
  765. //}
  766. return xlsx.Alignment{
  767. Horizontal: LuckyHorizontalMap[cellInfo.HorizontalType],
  768. //Indent: 0,
  769. //ShrinkToFit: false,
  770. TextRotation: rotateText,
  771. Vertical: LuckyVerticalMap[cellInfo.VerticalType],
  772. WrapText: isWrapText,
  773. }
  774. }
  775. // getExcelBorderConf 获取表格边框配置
  776. //func getExcelBorderConf(list []LuckySheetDataConfigBorderInfo) (v xlsx.Border) {
  777. // // 字体
  778. // for _, v := range list {
  779. // //v.BorderType
  780. // //v.Style
  781. //
  782. // if v.RangeType == "cell" {
  783. //
  784. // xlsx.Border{
  785. // Left: LuckyBorderMap[v.Value.L.Style],
  786. // LeftColor: strings.TrimPrefix(v.Value.L.Color, "#"),
  787. // Right: LuckyBorderMap[v.Value.R.Style],
  788. // RightColor: strings.TrimPrefix(v.Value.R.Color, "#"),
  789. // Top: LuckyBorderMap[v.Value.T.Style],
  790. // TopColor: strings.TrimPrefix(v.Value.T.Color, "#"),
  791. // Bottom: LuckyBorderMap[v.Value.B.Style],
  792. // BottomColor: strings.TrimPrefix(v.Value.B.Color, "#"),
  793. // }
  794. // } else {
  795. // xlsx.Border{
  796. // Left: LuckyBorderMap[v.Style],
  797. // LeftColor: strings.TrimPrefix(v.Color, "#"),
  798. // Right: LuckyBorderMap[v.Style],
  799. // RightColor: strings.TrimPrefix(v.Color, "#"),
  800. // Top: LuckyBorderMap[v.Style],
  801. // TopColor: strings.TrimPrefix(v.Color, "#"),
  802. // Bottom: LuckyBorderMap[v.Style],
  803. // BottomColor: strings.TrimPrefix(v.Color, "#"),
  804. // }
  805. // }
  806. // //v.Value.T.Style
  807. //
  808. // }
  809. //
  810. // return
  811. //}
  812. // LuckyFontFamilyMap 字体map
  813. var LuckyFontFamilyMap = map[int]string{
  814. 0: "Times New Roman",
  815. 1: "Arial",
  816. 2: "Tahoma",
  817. 3: "Verdana",
  818. 4: "微软雅黑",
  819. 5: "宋体", //宋体(Song)、
  820. 6: "黑体", // 黑体(ST Heiti)
  821. 7: "楷体", //楷体(ST Kaiti),
  822. 8: "仿宋", //仿宋(ST FangSong),
  823. 9: "新宋体", //新宋体(ST Song),
  824. 10: "华文新魏",
  825. 11: "华文行楷",
  826. 12: "华文隶书",
  827. }
  828. // LuckyBorderMap 边框map
  829. var LuckyBorderMap = map[string]string{
  830. "": "Thin",
  831. "1": "Thin",
  832. "2": "Hair",
  833. "3": "Dotted",
  834. "4": "Dashed",
  835. "5": "DashDot", //宋体(Song)、
  836. "6": "DashDotDot", // 黑体(ST Heiti)
  837. "7": "Double", //楷体(ST Kaiti),
  838. "8": "Medium", //仿宋(ST FangSong),
  839. "9": "MediumDashed", //新宋体(ST Song),
  840. "10": "MediumDashDot",
  841. "11": "MediumDashDotDot",
  842. "12": "SlantedDashDot",
  843. "13": "Thick",
  844. }
  845. // LuckyHorizontalMap 水平对齐map
  846. var LuckyHorizontalMap = map[int]string{
  847. //"": "general",
  848. 0: "center",
  849. 1: "left",
  850. 2: "right",
  851. }
  852. // LuckyVerticalMap 垂直对齐map
  853. var LuckyVerticalMap = map[int]string{
  854. //"": "center",
  855. 0: "center",
  856. 1: "top",
  857. //2: "bottom",
  858. }
  859. // GetColumnName Return the ColumnName
  860. func GetColumnName(rowNumber int, colNumber int) (colName string, err error) {
  861. if rowNumber < 1 || colNumber < 1 {
  862. err = errors.New("Row and Column Number can not be less than 1")
  863. return
  864. }
  865. dividend := colNumber
  866. var modulo int
  867. for dividend > 0 {
  868. modulo = (dividend - 1) % 26
  869. // Convert int to char
  870. colName = string(65+modulo) + colName
  871. dividend = (int)((dividend - modulo) / 26)
  872. }
  873. colName = colName + strconv.Itoa(rowNumber)
  874. return
  875. }
  876. // GetTableDataByLuckySheetDataStrBak 通过LuckySheet的string数据获取表格数据(备份:2022-08-23 10:30:32)
  877. func (item *LuckySheetData) GetTableDataByLuckySheetDataStrBak() (selfTableData TableData, err error) {
  878. luckySheetCellDataList := item.CellData
  879. // 表格数据
  880. tableDataMap := make(map[int64]map[int64]LuckySheetDataValue)
  881. // 最大行,最大列
  882. var maxRow, maxCol int64
  883. for _, v := range luckySheetCellDataList {
  884. //fmt.Println("row:", v.Row, "=====col:", v.Col)
  885. if v.Row > maxRow { //最大行
  886. maxRow = v.Row
  887. }
  888. if v.Col > maxCol { //最大列
  889. maxCol = v.Col
  890. }
  891. var tmpRow map[int64]LuckySheetDataValue
  892. tmpRow, ok := tableDataMap[v.Row]
  893. if ok {
  894. tmpRow[v.Col] = v.Value
  895. } else {
  896. tmpRow = make(map[int64]LuckySheetDataValue)
  897. tmpRow[v.Col] = v.Value
  898. }
  899. tableDataMap[v.Row] = tmpRow
  900. }
  901. tableDataList := make([][]LuckySheetDataValue, 0)
  902. var i int64
  903. // 单元格宽度
  904. configColumnConf := item.Config.Columnlen
  905. rowWidthMap := make(map[int]float64)
  906. rowWidthList := make([]float64, 0) //
  907. // 单元格高度
  908. configRowConf := item.Config.Rowlen
  909. rowHeightList := make([]float64, 0) //
  910. for i = 0; i <= maxRow; i++ {
  911. //列
  912. tmpTableColDataList := make([]LuckySheetDataValue, 0)
  913. // 每个单元格的高度
  914. tmpHeight, ok := configRowConf[fmt.Sprint(i)]
  915. if !ok {
  916. tmpHeight = 0
  917. }
  918. rowHeightList = append(rowHeightList, tmpHeight)
  919. tmpRowData, ok := tableDataMap[i]
  920. // 如果没有该行数据,那么就默认添加空行数据处理
  921. if !ok {
  922. tmpRowData = make(map[int64]LuckySheetDataValue)
  923. }
  924. var j int64
  925. for j = 0; j <= maxCol; j++ {
  926. tmpTableColData, ok := tmpRowData[j]
  927. if !ok {
  928. tmpTableColData = LuckySheetDataValue{}
  929. }
  930. tmpTableColDataList = append(tmpTableColDataList, tmpTableColData)
  931. // 每个单元格的宽度
  932. tmpWidth, ok := configColumnConf[fmt.Sprint(j)]
  933. if !ok {
  934. tmpWidth = 0
  935. }
  936. rowIndex := len(tmpTableColDataList) - 1
  937. if _, ok2 := rowWidthMap[rowIndex]; !ok2 {
  938. rowWidthList = append(rowWidthList, tmpWidth)
  939. }
  940. rowWidthMap[rowIndex] = tmpWidth
  941. }
  942. tableDataList = append(tableDataList, tmpTableColDataList)
  943. }
  944. //总共多少行
  945. lenRow := len(tableDataList)
  946. //移除上下空行
  947. deleteRowIndexList := make([]int, 0)
  948. if lenRow > 0 {
  949. var flag = false
  950. // 移除上方空列
  951. for rowIndex := 0; rowIndex < lenRow; rowIndex++ {
  952. isDelete := true
  953. for _, v := range tableDataList[rowIndex] {
  954. if v.Monitor != `` || (v.MergeCell.Row != rowIndex && v.MergeCell.Row != 0) {
  955. isDelete = false
  956. flag = true
  957. break
  958. }
  959. }
  960. if flag {
  961. break
  962. }
  963. if isDelete {
  964. selfTableData.RemoveTopRow++
  965. deleteRowIndexList = append(deleteRowIndexList, rowIndex)
  966. }
  967. }
  968. // 移除下方空行
  969. flag = false
  970. //尾部
  971. deleteBottomRowIndexList := make([]int, 0)
  972. for rowIndex := lenRow - 1; rowIndex >= 0; rowIndex-- {
  973. isDelete := true
  974. for _, v := range tableDataList[rowIndex] {
  975. if v.Monitor != `` {
  976. isDelete = false
  977. flag = true
  978. break
  979. }
  980. }
  981. if flag {
  982. break
  983. }
  984. if isDelete {
  985. deleteBottomRowIndexList = append(deleteBottomRowIndexList, rowIndex)
  986. selfTableData.RemoveBottomRow++
  987. }
  988. }
  989. if len(deleteBottomRowIndexList) > 0 {
  990. deleteRowIndexList = append(deleteRowIndexList, utils.RevSlice(deleteBottomRowIndexList)...)
  991. }
  992. lenDeleteRow := len(deleteRowIndexList)
  993. if lenDeleteRow > 0 {
  994. for rowIndex := lenDeleteRow - 1; rowIndex >= 0; rowIndex-- {
  995. //表格数据
  996. tableDataList = append(tableDataList[:deleteRowIndexList[rowIndex]], tableDataList[deleteRowIndexList[rowIndex]+1:]...) // 删除开头N个元素
  997. //表格高度
  998. rowHeightList = append(rowHeightList[:deleteRowIndexList[rowIndex]], rowHeightList[deleteRowIndexList[rowIndex]+1:]...) // 删除开头N个元素
  999. }
  1000. }
  1001. }
  1002. //移除左右空列
  1003. deleteColumnIndexList := make([]int, 0)
  1004. if len(tableDataList) > 0 {
  1005. var flag = false
  1006. lenColumn := len(tableDataList[0])
  1007. // 移除左边空列
  1008. for columnIndex := 0; columnIndex < lenColumn; columnIndex++ {
  1009. isDelete := true
  1010. for _, v := range tableDataList {
  1011. //如果一列都没有,说明是上面几行是空行,没有数据
  1012. if len(v) <= 0 {
  1013. continue
  1014. }
  1015. if v[columnIndex].Monitor != `` || (v[columnIndex].MergeCell.Column != columnIndex && v[columnIndex].MergeCell.Column != 0) {
  1016. isDelete = false
  1017. flag = true
  1018. break
  1019. }
  1020. }
  1021. if flag {
  1022. break
  1023. }
  1024. if isDelete {
  1025. selfTableData.RemoveLeftColumn++
  1026. deleteColumnIndexList = append(deleteColumnIndexList, columnIndex)
  1027. }
  1028. }
  1029. // 移除右方空列
  1030. flag = false
  1031. //右边
  1032. deleteTailColumnIndexList := make([]int, 0)
  1033. for columnIndex := lenColumn - 1; columnIndex >= 0; columnIndex-- {
  1034. isDelete := true
  1035. for _, v := range tableDataList {
  1036. //如果一列都没有,说明是上面几行是空行,没有数据
  1037. if len(v) <= 0 {
  1038. continue
  1039. }
  1040. if v[columnIndex].Monitor != `` || (v[columnIndex].MergeCell.Column != columnIndex && v[columnIndex].MergeCell.Column != 0) {
  1041. isDelete = false
  1042. flag = true
  1043. break
  1044. }
  1045. }
  1046. if flag {
  1047. break
  1048. }
  1049. if isDelete {
  1050. deleteTailColumnIndexList = append(deleteTailColumnIndexList, columnIndex)
  1051. selfTableData.RemoveRightColumn++
  1052. }
  1053. }
  1054. if len(deleteTailColumnIndexList) > 0 {
  1055. deleteColumnIndexList = append(deleteColumnIndexList, utils.RevSlice(deleteTailColumnIndexList)...)
  1056. }
  1057. lenDeleteColumn := len(deleteColumnIndexList)
  1058. if lenDeleteColumn > 0 {
  1059. for columnIndex := lenDeleteColumn - 1; columnIndex >= 0; columnIndex-- {
  1060. //表格数据
  1061. for k, v := range tableDataList {
  1062. tableDataList[k] = append(v[:deleteColumnIndexList[columnIndex]], v[deleteColumnIndexList[columnIndex]+1:]...) // 删除开头N个元素
  1063. }
  1064. //表格宽度
  1065. rowWidthList = append(rowWidthList[:deleteColumnIndexList[columnIndex]], rowWidthList[deleteColumnIndexList[columnIndex]+1:]...) // 删除开头N个元素
  1066. }
  1067. }
  1068. }
  1069. //处理合并单元格
  1070. tableDataMergeList := make([]TableDataMerge, 0)
  1071. for _, v := range item.Config.Merge {
  1072. indexRow := v.Row - selfTableData.RemoveTopRow
  1073. indexColumn := v.Column - selfTableData.RemoveLeftColumn
  1074. tableDataMerge := TableDataMerge{
  1075. StartRowIndex: indexRow,
  1076. StartColumnIndex: indexColumn,
  1077. MergeRowNum: v.Rs - 1,
  1078. MergeColumnNum: v.Cs - 1,
  1079. }
  1080. tableDataMergeList = append(tableDataMergeList, tableDataMerge)
  1081. }
  1082. // 表格数据
  1083. selfTableData.TableDataList = tableDataList
  1084. selfTableData.RowWidthList = rowWidthList
  1085. selfTableData.RowHeightList = rowHeightList
  1086. selfTableData.MergeList = tableDataMergeList
  1087. return
  1088. }
  1089. func (item *LuckySheetData) ToExcel2() (downloadFilePath string, err error) {
  1090. tableData, err := item.GetTableDataByLuckySheetDataStr()
  1091. downloadFilePath, err = getDownloadPath()
  1092. if err != nil {
  1093. return
  1094. }
  1095. f := excelize.NewFile()
  1096. // Create a new sheet.
  1097. sheetName := `Sheet1`
  1098. sheetIndex, err := f.NewSheet(sheetName)
  1099. if err != nil {
  1100. return
  1101. }
  1102. //设置列宽度
  1103. for k, v := range tableData.RowWidthList {
  1104. colName, tmpErr := excelize.ColumnNumberToName(k + 1)
  1105. if tmpErr != nil {
  1106. err = errors.New("获取单元格列名失败,ERR:" + tmpErr.Error())
  1107. err = tmpErr
  1108. return
  1109. }
  1110. err = f.SetColWidth(sheetName, colName, colName, v/10)
  1111. if err != nil {
  1112. err = errors.New("设置列宽度,ERR:" + tmpErr.Error())
  1113. return
  1114. }
  1115. }
  1116. // 写入数据
  1117. for index, v := range tableData.TableDataList {
  1118. //设置单元格高度
  1119. if tableData.RowHeightList[index] > 0 {
  1120. tmpErr := f.SetRowHeight(sheetName, index+1, tableData.RowHeightList[index]/2)
  1121. if tmpErr != nil {
  1122. err = errors.New("设置单元格高度失败,ERR:" + tmpErr.Error())
  1123. return
  1124. }
  1125. }
  1126. for colunmIndex, cellInfo := range v {
  1127. //f.NewStyle
  1128. defaultFill := excelize.Fill{
  1129. //Type: "solid",
  1130. Pattern: 1,
  1131. //Color: []string{cellInfo.Background},
  1132. Shading: 0,
  1133. }
  1134. if cellInfo.Background != `` {
  1135. defaultFill.Type = "solid"
  1136. defaultFill.Color = []string{cellInfo.Background}
  1137. }
  1138. cellStyle := &excelize.Style{
  1139. Border: []excelize.Border{
  1140. {Type: "left", Color: "000000", Style: 1},
  1141. {Type: "top", Color: "000000", Style: 1},
  1142. {Type: "bottom", Color: "000000", Style: 1},
  1143. {Type: "right", Color: "000000", Style: 1},
  1144. //{Type: "diagonalDown", Color: "A020F0", Style: 7},
  1145. //{Type: "diagonalUp", Color: "A020F0", Style: 8},
  1146. },
  1147. Fill: defaultFill,
  1148. Font: getExcelizeFontConf(cellInfo),
  1149. Alignment: getExcelizeAlignmentConf(cellInfo),
  1150. //Protection: nil,
  1151. //NumFmt: 0,
  1152. //DecimalPlaces: 0,
  1153. //CustomNumFmt: nil,
  1154. //Lang: "",
  1155. //NegRed: false,
  1156. }
  1157. cellStyleId, tmpErr := f.NewStyle(cellStyle)
  1158. if tmpErr != nil {
  1159. err = errors.New("new Style 失败,ERR:" + tmpErr.Error())
  1160. return
  1161. }
  1162. columnName, tmpErr := excelize.ColumnNumberToName(colunmIndex + 1)
  1163. if tmpErr != nil {
  1164. err = errors.New("获取单元格列名失败,ERR:" + tmpErr.Error())
  1165. return
  1166. }
  1167. cellName := columnName + strconv.Itoa(index+1)
  1168. tmpErr = f.SetCellStyle(sheetName, cellName, cellName, cellStyleId)
  1169. if tmpErr != nil {
  1170. err = errors.New("设置style失败,ERR:" + tmpErr.Error())
  1171. return
  1172. }
  1173. valueStr := cellInfo.Monitor
  1174. if valueStr == `` {
  1175. //valueStr = fmt.Sprint(cellInfo.Value)
  1176. if valueStr == `` && cellInfo.CellType.S != nil {
  1177. //不是设置在单元格上面,而是设置在文本上
  1178. for _, cellS := range cellInfo.CellType.S {
  1179. valueStr += fmt.Sprint(cellS.Value)
  1180. }
  1181. }
  1182. }
  1183. tmpErr = f.SetCellStr(sheetName, cellName, valueStr)
  1184. if tmpErr != nil {
  1185. err = errors.New("设置单元格数据失败,ERR:" + tmpErr.Error())
  1186. return
  1187. }
  1188. }
  1189. }
  1190. for _, v := range tableData.MergeList {
  1191. //开始列
  1192. startColumnName, tmpErr := excelize.ColumnNumberToName(v.StartColumnIndex + 1)
  1193. if tmpErr != nil {
  1194. err = tmpErr
  1195. return
  1196. }
  1197. startCellName := startColumnName + strconv.Itoa(v.StartRowIndex+1)
  1198. //结束列
  1199. endColumnName, tmpErr := excelize.ColumnNumberToName(v.StartColumnIndex + v.MergeColumnNum + 1)
  1200. if tmpErr != nil {
  1201. err = tmpErr
  1202. return
  1203. }
  1204. endCellName := endColumnName + strconv.Itoa(v.StartRowIndex+v.MergeRowNum+1)
  1205. err = f.MergeCell(sheetName, startCellName, endCellName)
  1206. if err != nil {
  1207. return
  1208. }
  1209. }
  1210. // Set active sheet of the workbook.
  1211. f.SetActiveSheet(sheetIndex)
  1212. // Save spreadsheet by the given path.
  1213. err = f.SaveAs(downloadFilePath)
  1214. return
  1215. }
  1216. // getExcelizeFontConf 获取表格字体配置
  1217. func getExcelizeFontConf(cellInfo LuckySheetDataValue) *excelize.Font {
  1218. fontSize := 10
  1219. familyName := ``
  1220. //single 单线 、double 双线
  1221. underlineStyle := ``
  1222. var isBold, isItalic, isUnderline bool
  1223. // 字体
  1224. {
  1225. if cellInfo.Bold == 1 {
  1226. isBold = true
  1227. }
  1228. if cellInfo.Italic == 1 {
  1229. isItalic = true
  1230. }
  1231. if cellInfo.CancelLine == 1 {
  1232. isUnderline = true
  1233. }
  1234. //if cellInfo.Fontsize != `` {
  1235. // convSize, _ := strconv.Atoi(cellInfo.Fontsize)
  1236. // if convSize > 0 {
  1237. // fontSize = convSize
  1238. // }
  1239. //}
  1240. if cellInfo.Fontsize > 0 {
  1241. fontSize = cellInfo.Fontsize
  1242. }
  1243. tmpFamilyName, familyNameOk := LuckyFontFamilyMap[cellInfo.FontFamily]
  1244. if !familyNameOk {
  1245. tmpFamilyName = "宋体"
  1246. }
  1247. familyName = tmpFamilyName
  1248. }
  1249. if isUnderline {
  1250. underlineStyle = "single"
  1251. }
  1252. //VertAlign取值:
  1253. //BASELINE、superscript、subscript
  1254. return &excelize.Font{
  1255. Bold: isBold,
  1256. Italic: isItalic,
  1257. Underline: underlineStyle,
  1258. Family: familyName,
  1259. Size: float64(fontSize),
  1260. Strike: isUnderline,
  1261. Color: cellInfo.FontColor,
  1262. VertAlign: "",
  1263. }
  1264. }
  1265. // getExcelizeAlignmentConf 获取表格单元格排列配置
  1266. func getExcelizeAlignmentConf(cellInfo LuckySheetDataValue) *excelize.Alignment {
  1267. //自动换行
  1268. isWrapText := false
  1269. if cellInfo.TextBeak == 2 {
  1270. isWrapText = true
  1271. }
  1272. rotateText := 0
  1273. //if cellInfo.RotateText != `` {
  1274. // convSize, _ := strconv.Atoi(cellInfo.RotateText)
  1275. // if convSize > 0 {
  1276. // rotateText = convSize
  1277. // }
  1278. //}
  1279. return &excelize.Alignment{
  1280. Horizontal: LuckyHorizontalMap[cellInfo.HorizontalType],
  1281. //Indent: 0,
  1282. //JustifyLastLine: false,
  1283. //ReadingOrder: 0,
  1284. //RelativeIndent: 0,
  1285. //ShrinkToFit: false,
  1286. TextRotation: rotateText,
  1287. Vertical: LuckyVerticalMap[cellInfo.VerticalType],
  1288. WrapText: isWrapText,
  1289. }
  1290. }
  1291. // getColor 获取hex颜色
  1292. func getColor(bgStr string) string {
  1293. if strings.Contains(bgStr, "(") {
  1294. arr := strings.Split(bgStr, ",")
  1295. if len(arr) != 3 {
  1296. return bgStr
  1297. }
  1298. // 第一位
  1299. tmpFirstArr := strings.Split(arr[0], "(")
  1300. arr[0] = tmpFirstArr[len(tmpFirstArr)-1]
  1301. // 最后一位
  1302. tmpLastArr := strings.Split(arr[2], ")")
  1303. arr[2] = tmpLastArr[0]
  1304. rgbArr := make([]int64, 0)
  1305. for _, v := range arr {
  1306. tmpInt, err := strconv.Atoi(utils.TrimStr(v))
  1307. if err != nil {
  1308. return bgStr
  1309. }
  1310. rgbArr = append(rgbArr, int64(tmpInt))
  1311. }
  1312. rgb := RGB{
  1313. rgbArr[0],
  1314. rgbArr[1],
  1315. rgbArr[2],
  1316. }
  1317. bgStr = "" + rgb.Rgb2Hex().Str
  1318. }
  1319. return bgStr
  1320. }
  1321. // GetTableDataByCustomData 通过自定义表格数据获取表格数据
  1322. func GetTableDataByCustomData(excelType int, data request.TableDataReq) (selfTableData TableData, err error) {
  1323. tableDataList := make([][]LuckySheetDataValue, 0)
  1324. mergeList := make([]TableDataMerge, 0)
  1325. // 指标数
  1326. lenEdb := len(data.Data)
  1327. if lenEdb <= 0 {
  1328. return
  1329. }
  1330. // 日期数
  1331. lenCol := len(data.Data[0].Data)
  1332. if lenCol <= 0 {
  1333. return
  1334. }
  1335. // 指标列:1;指标行:2
  1336. if excelType == 1 {
  1337. mergeList = append(mergeList, TableDataMerge{
  1338. StartRowIndex: 0,
  1339. StartColumnIndex: 0,
  1340. MergeRowNum: 1,
  1341. MergeColumnNum: 0,
  1342. })
  1343. // 第一行
  1344. {
  1345. firstCol := make([]LuckySheetDataValue, 0)
  1346. firstCol = append(firstCol, LuckySheetDataValue{
  1347. Value: "日期",
  1348. Monitor: "日期",
  1349. MergeCell: LuckySheetDataConfigMerge{
  1350. Row: 0, //行数
  1351. Column: 0, //列数
  1352. Rs: 2, //合并的行数
  1353. Cs: 1, //合并的列数
  1354. },
  1355. })
  1356. for _, v := range data.Data {
  1357. edbName := v.EdbName
  1358. if v.EdbAliasName != `` {
  1359. edbName = v.EdbAliasName
  1360. }
  1361. firstCol = append(firstCol, LuckySheetDataValue{
  1362. Value: edbName,
  1363. Monitor: edbName,
  1364. MergeCell: LuckySheetDataConfigMerge{},
  1365. })
  1366. }
  1367. tableDataList = append(tableDataList, firstCol)
  1368. }
  1369. // 第二行
  1370. {
  1371. secondCol := make([]LuckySheetDataValue, 0)
  1372. secondCol = append(secondCol, LuckySheetDataValue{})
  1373. for _, v := range data.Data {
  1374. name := v.Unit + " / " + v.Frequency
  1375. secondCol = append(secondCol, LuckySheetDataValue{
  1376. Value: name,
  1377. Monitor: name,
  1378. MergeCell: LuckySheetDataConfigMerge{},
  1379. })
  1380. }
  1381. tableDataList = append(tableDataList, secondCol)
  1382. }
  1383. // 开始数据了
  1384. {
  1385. for i := 0; i < lenCol; i++ {
  1386. dataCol := make([]LuckySheetDataValue, 0)
  1387. // 日期
  1388. dataCol = append(dataCol, LuckySheetDataValue{
  1389. Value: data.Data[0].Data[i].DataTime,
  1390. Monitor: data.Data[0].Data[i].DataTime,
  1391. MergeCell: LuckySheetDataConfigMerge{},
  1392. })
  1393. // 数据值
  1394. for _, v := range data.Data {
  1395. dataCol = append(dataCol, LuckySheetDataValue{
  1396. Value: v.Data[i].Value,
  1397. Monitor: v.Data[i].ShowValue,
  1398. MergeCell: LuckySheetDataConfigMerge{},
  1399. })
  1400. }
  1401. tableDataList = append(tableDataList, dataCol)
  1402. }
  1403. }
  1404. // 开始文本行了
  1405. {
  1406. for _, textColList := range data.TextRowData {
  1407. dataCol := make([]LuckySheetDataValue, 0)
  1408. for _, v := range textColList {
  1409. dataCol = append(dataCol, LuckySheetDataValue{
  1410. Value: v.Value,
  1411. Monitor: v.ShowValue,
  1412. MergeCell: LuckySheetDataConfigMerge{},
  1413. })
  1414. }
  1415. tableDataList = append(tableDataList, dataCol)
  1416. }
  1417. }
  1418. } else {
  1419. // 指标行
  1420. mergeList = append(mergeList, TableDataMerge{
  1421. StartRowIndex: 0,
  1422. StartColumnIndex: 0,
  1423. MergeRowNum: 0,
  1424. MergeColumnNum: 1,
  1425. })
  1426. // 第一行
  1427. {
  1428. firstCol := make([]LuckySheetDataValue, 0)
  1429. firstCol = append(firstCol, LuckySheetDataValue{
  1430. Value: "日期",
  1431. Monitor: "日期",
  1432. MergeCell: LuckySheetDataConfigMerge{
  1433. Row: 0, //行数
  1434. Column: 0, //列数
  1435. Rs: 1, //合并的行数
  1436. Cs: 2, //合并的列数
  1437. },
  1438. })
  1439. firstCol = append(firstCol, LuckySheetDataValue{})
  1440. // 日期列
  1441. for _, v := range data.Data[0].Data {
  1442. firstCol = append(firstCol, LuckySheetDataValue{
  1443. Value: v.DataTime,
  1444. Monitor: v.DataTime,
  1445. MergeCell: LuckySheetDataConfigMerge{},
  1446. })
  1447. }
  1448. // 文本列
  1449. for _, textColList := range data.TextRowData {
  1450. firstCol = append(firstCol, LuckySheetDataValue{
  1451. Value: textColList[0].Value,
  1452. Monitor: textColList[0].ShowValue,
  1453. MergeCell: LuckySheetDataConfigMerge{},
  1454. })
  1455. }
  1456. tableDataList = append(tableDataList, firstCol)
  1457. }
  1458. // 日期列+文本列+两列表头(日期这个文案表头)
  1459. //colLen := lenCol+2+len(data.TextRowData)
  1460. for i := 0; i < lenEdb; i++ {
  1461. dataCol := make([]LuckySheetDataValue, 0)
  1462. // 指标信息
  1463. tmpEdbInfo := data.Data[i]
  1464. // 指标名称
  1465. {
  1466. edbName := tmpEdbInfo.EdbName
  1467. if tmpEdbInfo.EdbAliasName != `` {
  1468. edbName = tmpEdbInfo.EdbAliasName
  1469. }
  1470. dataCol = append(dataCol, LuckySheetDataValue{
  1471. Value: edbName,
  1472. Monitor: edbName,
  1473. MergeCell: LuckySheetDataConfigMerge{},
  1474. })
  1475. }
  1476. // 指标单位、频度
  1477. {
  1478. name := tmpEdbInfo.Unit + " / " + tmpEdbInfo.Frequency
  1479. dataCol = append(dataCol, LuckySheetDataValue{
  1480. Value: name,
  1481. Monitor: name,
  1482. MergeCell: LuckySheetDataConfigMerge{},
  1483. })
  1484. }
  1485. // 指标数据列
  1486. for _, tmpData := range tmpEdbInfo.Data {
  1487. dataCol = append(dataCol, LuckySheetDataValue{
  1488. Value: tmpData.Value,
  1489. Monitor: tmpData.ShowValue,
  1490. MergeCell: LuckySheetDataConfigMerge{},
  1491. })
  1492. }
  1493. // 文本列
  1494. for _, textColList := range data.TextRowData {
  1495. dataCol = append(dataCol, LuckySheetDataValue{
  1496. Value: textColList[i+1].Value,
  1497. Monitor: textColList[i+1].ShowValue,
  1498. MergeCell: LuckySheetDataConfigMerge{},
  1499. })
  1500. }
  1501. tableDataList = append(tableDataList, dataCol)
  1502. }
  1503. }
  1504. selfTableData.MergeList = mergeList
  1505. selfTableData.TableDataList = tableDataList
  1506. return
  1507. }
  1508. // GetTableDataByMixedTableData 通过混合表格数据获取表格数据
  1509. func GetTableDataByMixedTableData(config [][]request.MixedTableCellDataReq) (selfTableData TableData, err error) {
  1510. tableDataList := make([][]LuckySheetDataValue, 0)
  1511. mergeList := make([]TableDataMerge, 0)
  1512. // 开始文本行了
  1513. {
  1514. for _, row := range config {
  1515. dataCol := make([]LuckySheetDataValue, 0)
  1516. for _, cell := range row {
  1517. dataCol = append(dataCol, LuckySheetDataValue{
  1518. Value: cell.Value,
  1519. Monitor: cell.ShowValue,
  1520. MergeCell: LuckySheetDataConfigMerge{},
  1521. })
  1522. }
  1523. tableDataList = append(tableDataList, dataCol)
  1524. }
  1525. }
  1526. selfTableData.MergeList = mergeList
  1527. selfTableData.TableDataList = tableDataList
  1528. return
  1529. }