lucky_sheet.go 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690
  1. package excel
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "eta/eta_api/models/data_manage/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. for rowIndex := lenRow - 1; rowIndex >= 0; rowIndex-- {
  571. isDelete := true
  572. for _, v := range tableDataList[rowIndex] {
  573. if v.Monitor != `` {
  574. isDelete = false
  575. flag = true
  576. break
  577. }
  578. }
  579. if flag {
  580. break
  581. }
  582. if isDelete {
  583. deleteBottomRowIndexList = append(deleteBottomRowIndexList, rowIndex)
  584. removeBottomRow++
  585. }
  586. }
  587. if len(deleteBottomRowIndexList) > 0 {
  588. deleteRowIndexList = append(deleteRowIndexList, utils.RevSlice(deleteBottomRowIndexList)...)
  589. }
  590. lenDeleteRow := len(deleteRowIndexList)
  591. if lenDeleteRow > 0 {
  592. for rowIndex := lenDeleteRow - 1; rowIndex >= 0; rowIndex-- {
  593. //表格数据
  594. tableDataList = append(tableDataList[:deleteRowIndexList[rowIndex]], tableDataList[deleteRowIndexList[rowIndex]+1:]...) // 删除开头N个元素
  595. //表格高度
  596. rowHeightList = append(rowHeightList[:deleteRowIndexList[rowIndex]], rowHeightList[deleteRowIndexList[rowIndex]+1:]...) // 删除开头N个元素
  597. }
  598. }
  599. }
  600. //移除左右空列
  601. deleteColumnIndexList := make([]int, 0)
  602. if len(tableDataList) > 0 {
  603. var flag = false
  604. lenColumn := len(tableDataList[0])
  605. // 移除左边空列
  606. for columnIndex := 0; columnIndex < lenColumn; columnIndex++ {
  607. isDelete := true
  608. for _, v := range tableDataList {
  609. //如果一列都没有,说明是上面几行是空行,没有数据
  610. if len(v) <= 0 {
  611. continue
  612. }
  613. if v[columnIndex].Monitor != `` || (v[columnIndex].MergeCell.Column != columnIndex && v[columnIndex].MergeCell.Column != 0) {
  614. isDelete = false
  615. flag = true
  616. break
  617. }
  618. }
  619. if flag {
  620. break
  621. }
  622. if isDelete {
  623. removeLeftColumn++
  624. deleteColumnIndexList = append(deleteColumnIndexList, columnIndex)
  625. }
  626. }
  627. // 移除右方空列
  628. flag = false
  629. //右边
  630. deleteTailColumnIndexList := make([]int, 0)
  631. for columnIndex := lenColumn - 1; columnIndex >= 0; columnIndex-- {
  632. isDelete := true
  633. for _, v := range tableDataList {
  634. //如果一列都没有,说明是上面几行是空行,没有数据
  635. if len(v) <= 0 {
  636. continue
  637. }
  638. if v[columnIndex].Monitor != `` || (v[columnIndex].MergeCell.Column != columnIndex && v[columnIndex].MergeCell.Column != 0) {
  639. isDelete = false
  640. flag = true
  641. break
  642. }
  643. }
  644. if flag {
  645. break
  646. }
  647. if isDelete {
  648. deleteTailColumnIndexList = append(deleteTailColumnIndexList, columnIndex)
  649. removeRightColumn++
  650. }
  651. }
  652. if len(deleteTailColumnIndexList) > 0 {
  653. deleteColumnIndexList = append(deleteColumnIndexList, utils.RevSlice(deleteTailColumnIndexList)...)
  654. }
  655. lenDeleteColumn := len(deleteColumnIndexList)
  656. if lenDeleteColumn > 0 {
  657. for columnIndex := lenDeleteColumn - 1; columnIndex >= 0; columnIndex-- {
  658. //表格数据
  659. for k, v := range tableDataList {
  660. tableDataList[k] = append(v[:deleteColumnIndexList[columnIndex]], v[deleteColumnIndexList[columnIndex]+1:]...) // 删除开头N个元素
  661. }
  662. //表格宽度
  663. rowWidthList = append(rowWidthList[:deleteColumnIndexList[columnIndex]], rowWidthList[deleteColumnIndexList[columnIndex]+1:]...) // 删除开头N个元素
  664. }
  665. }
  666. }
  667. //处理合并单元格
  668. for _, v := range luckySheetDataConfigMergeList {
  669. indexRow := v.Row - removeTopRow
  670. indexColumn := v.Column - removeLeftColumn
  671. tableDataMerge := TableDataMerge{
  672. StartRowIndex: indexRow,
  673. StartColumnIndex: indexColumn,
  674. MergeRowNum: v.Rs - 1,
  675. MergeColumnNum: v.Cs - 1,
  676. }
  677. tableDataMergeList = append(tableDataMergeList, tableDataMerge)
  678. }
  679. return tableDataList, TableRemoveNum{
  680. RemoveTopRow: removeTopRow,
  681. RemoveBottomRow: removeBottomRow,
  682. RemoveLeftColumn: removeLeftColumn,
  683. RemoveRightColumn: removeRightColumn,
  684. }, rowHeightList, rowWidthList, tableDataMergeList
  685. }
  686. // ToExcel 通过 luckySheetData生成excel表格
  687. func (item *LuckySheetData) ToExcel() (downloadFilePath string, err error) {
  688. tableData, err := item.GetTableDataByLuckySheetDataStr()
  689. if err != nil {
  690. return
  691. }
  692. downloadFilePath, err = tableData.ToExcel()
  693. return
  694. }
  695. // getDownloadPath 获取下载地址
  696. func getDownloadPath() (fpath string, err error) {
  697. dateDir := time.Now().Format("20060102")
  698. uploadDir := "static/xls/" + dateDir
  699. err = os.MkdirAll(uploadDir, 0766)
  700. if err != nil {
  701. return
  702. }
  703. randStr := utils.GetRandStringNoSpecialChar(28)
  704. fileName := randStr + ".xlsx"
  705. fpath = uploadDir + "/" + fileName
  706. return
  707. }
  708. // getExcelFontConf 获取表格字体配置
  709. func getExcelFontConf(cellInfo LuckySheetDataValue) xlsx.Font {
  710. fontSize := 10
  711. familyName := ``
  712. var isBold, isItalic, isUnderline bool
  713. // 字体
  714. {
  715. if cellInfo.Bold == 1 {
  716. isBold = true
  717. }
  718. if cellInfo.Italic == 1 {
  719. isItalic = true
  720. }
  721. if cellInfo.CancelLine == 1 {
  722. isUnderline = true
  723. }
  724. //if cellInfo.Fontsize != `` {
  725. // convSize, _ := strconv.Atoi(cellInfo.Fontsize)
  726. // if convSize > 0 {
  727. // fontSize = convSize
  728. // }
  729. //}
  730. if cellInfo.Fontsize > 0 {
  731. fontSize = cellInfo.Fontsize
  732. }
  733. tmpFamilyName, familyNameOk := LuckyFontFamilyMap[cellInfo.FontFamily]
  734. if !familyNameOk {
  735. tmpFamilyName = "宋体"
  736. }
  737. familyName = tmpFamilyName
  738. }
  739. return xlsx.Font{
  740. Size: fontSize,
  741. Name: familyName,
  742. //Family: v2.FontFamily,
  743. //Charset: 0,
  744. Color: strings.TrimPrefix(cellInfo.FontColor, "#"),
  745. Bold: isBold,
  746. Italic: isItalic,
  747. Underline: isUnderline,
  748. }
  749. }
  750. // getExcelAlignmentConf 获取表格单元格排列配置
  751. func getExcelAlignmentConf(cellInfo LuckySheetDataValue) xlsx.Alignment {
  752. //自动换行
  753. isWrapText := false
  754. if cellInfo.TextBeak == 2 {
  755. isWrapText = true
  756. }
  757. rotateText := 0
  758. //if cellInfo.RotateText != `` {
  759. // convSize, _ := strconv.Atoi(cellInfo.RotateText)
  760. // if convSize > 0 {
  761. // rotateText = convSize
  762. // }
  763. //}
  764. return xlsx.Alignment{
  765. Horizontal: LuckyHorizontalMap[cellInfo.HorizontalType],
  766. //Indent: 0,
  767. //ShrinkToFit: false,
  768. TextRotation: rotateText,
  769. Vertical: LuckyVerticalMap[cellInfo.VerticalType],
  770. WrapText: isWrapText,
  771. }
  772. }
  773. // getExcelBorderConf 获取表格边框配置
  774. //func getExcelBorderConf(list []LuckySheetDataConfigBorderInfo) (v xlsx.Border) {
  775. // // 字体
  776. // for _, v := range list {
  777. // //v.BorderType
  778. // //v.Style
  779. //
  780. // if v.RangeType == "cell" {
  781. //
  782. // xlsx.Border{
  783. // Left: LuckyBorderMap[v.Value.L.Style],
  784. // LeftColor: strings.TrimPrefix(v.Value.L.Color, "#"),
  785. // Right: LuckyBorderMap[v.Value.R.Style],
  786. // RightColor: strings.TrimPrefix(v.Value.R.Color, "#"),
  787. // Top: LuckyBorderMap[v.Value.T.Style],
  788. // TopColor: strings.TrimPrefix(v.Value.T.Color, "#"),
  789. // Bottom: LuckyBorderMap[v.Value.B.Style],
  790. // BottomColor: strings.TrimPrefix(v.Value.B.Color, "#"),
  791. // }
  792. // } else {
  793. // xlsx.Border{
  794. // Left: LuckyBorderMap[v.Style],
  795. // LeftColor: strings.TrimPrefix(v.Color, "#"),
  796. // Right: LuckyBorderMap[v.Style],
  797. // RightColor: strings.TrimPrefix(v.Color, "#"),
  798. // Top: LuckyBorderMap[v.Style],
  799. // TopColor: strings.TrimPrefix(v.Color, "#"),
  800. // Bottom: LuckyBorderMap[v.Style],
  801. // BottomColor: strings.TrimPrefix(v.Color, "#"),
  802. // }
  803. // }
  804. // //v.Value.T.Style
  805. //
  806. // }
  807. //
  808. // return
  809. //}
  810. // LuckyFontFamilyMap 字体map
  811. var LuckyFontFamilyMap = map[int]string{
  812. 0: "Times New Roman",
  813. 1: "Arial",
  814. 2: "Tahoma",
  815. 3: "Verdana",
  816. 4: "微软雅黑",
  817. 5: "宋体", //宋体(Song)、
  818. 6: "黑体", // 黑体(ST Heiti)
  819. 7: "楷体", //楷体(ST Kaiti),
  820. 8: "仿宋", //仿宋(ST FangSong),
  821. 9: "新宋体", //新宋体(ST Song),
  822. 10: "华文新魏",
  823. 11: "华文行楷",
  824. 12: "华文隶书",
  825. }
  826. // LuckyBorderMap 边框map
  827. var LuckyBorderMap = map[string]string{
  828. "": "Thin",
  829. "1": "Thin",
  830. "2": "Hair",
  831. "3": "Dotted",
  832. "4": "Dashed",
  833. "5": "DashDot", //宋体(Song)、
  834. "6": "DashDotDot", // 黑体(ST Heiti)
  835. "7": "Double", //楷体(ST Kaiti),
  836. "8": "Medium", //仿宋(ST FangSong),
  837. "9": "MediumDashed", //新宋体(ST Song),
  838. "10": "MediumDashDot",
  839. "11": "MediumDashDotDot",
  840. "12": "SlantedDashDot",
  841. "13": "Thick",
  842. }
  843. // LuckyHorizontalMap 水平对齐map
  844. var LuckyHorizontalMap = map[int]string{
  845. //"": "general",
  846. 0: "center",
  847. 1: "left",
  848. 2: "right",
  849. }
  850. // LuckyVerticalMap 垂直对齐map
  851. var LuckyVerticalMap = map[int]string{
  852. //"": "center",
  853. 0: "center",
  854. 1: "top",
  855. //2: "bottom",
  856. }
  857. // GetColumnName Return the ColumnName
  858. func GetColumnName(rowNumber int, colNumber int) (colName string, err error) {
  859. if rowNumber < 1 || colNumber < 1 {
  860. err = errors.New("Row and Column Number can not be less than 1")
  861. return
  862. }
  863. dividend := colNumber
  864. var modulo int
  865. for dividend > 0 {
  866. modulo = (dividend - 1) % 26
  867. // Convert int to char
  868. colName = string(65+modulo) + colName
  869. dividend = (int)((dividend - modulo) / 26)
  870. }
  871. colName = colName + strconv.Itoa(rowNumber)
  872. return
  873. }
  874. // GetTableDataByLuckySheetDataStrBak 通过LuckySheet的string数据获取表格数据(备份:2022-08-23 10:30:32)
  875. func (item *LuckySheetData) GetTableDataByLuckySheetDataStrBak() (selfTableData TableData, err error) {
  876. luckySheetCellDataList := item.CellData
  877. // 表格数据
  878. tableDataMap := make(map[int64]map[int64]LuckySheetDataValue)
  879. // 最大行,最大列
  880. var maxRow, maxCol int64
  881. for _, v := range luckySheetCellDataList {
  882. //fmt.Println("row:", v.Row, "=====col:", v.Col)
  883. if v.Row > maxRow { //最大行
  884. maxRow = v.Row
  885. }
  886. if v.Col > maxCol { //最大列
  887. maxCol = v.Col
  888. }
  889. var tmpRow map[int64]LuckySheetDataValue
  890. tmpRow, ok := tableDataMap[v.Row]
  891. if ok {
  892. tmpRow[v.Col] = v.Value
  893. } else {
  894. tmpRow = make(map[int64]LuckySheetDataValue)
  895. tmpRow[v.Col] = v.Value
  896. }
  897. tableDataMap[v.Row] = tmpRow
  898. }
  899. tableDataList := make([][]LuckySheetDataValue, 0)
  900. var i int64
  901. // 单元格宽度
  902. configColumnConf := item.Config.Columnlen
  903. rowWidthMap := make(map[int]float64)
  904. rowWidthList := make([]float64, 0) //
  905. // 单元格高度
  906. configRowConf := item.Config.Rowlen
  907. rowHeightList := make([]float64, 0) //
  908. for i = 0; i <= maxRow; i++ {
  909. //列
  910. tmpTableColDataList := make([]LuckySheetDataValue, 0)
  911. // 每个单元格的高度
  912. tmpHeight, ok := configRowConf[fmt.Sprint(i)]
  913. if !ok {
  914. tmpHeight = 0
  915. }
  916. rowHeightList = append(rowHeightList, tmpHeight)
  917. tmpRowData, ok := tableDataMap[i]
  918. // 如果没有该行数据,那么就默认添加空行数据处理
  919. if !ok {
  920. tmpRowData = make(map[int64]LuckySheetDataValue)
  921. }
  922. var j int64
  923. for j = 0; j <= maxCol; j++ {
  924. tmpTableColData, ok := tmpRowData[j]
  925. if !ok {
  926. tmpTableColData = LuckySheetDataValue{}
  927. }
  928. tmpTableColDataList = append(tmpTableColDataList, tmpTableColData)
  929. // 每个单元格的宽度
  930. tmpWidth, ok := configColumnConf[fmt.Sprint(j)]
  931. if !ok {
  932. tmpWidth = 0
  933. }
  934. rowIndex := len(tmpTableColDataList) - 1
  935. if _, ok2 := rowWidthMap[rowIndex]; !ok2 {
  936. rowWidthList = append(rowWidthList, tmpWidth)
  937. }
  938. rowWidthMap[rowIndex] = tmpWidth
  939. }
  940. tableDataList = append(tableDataList, tmpTableColDataList)
  941. }
  942. //总共多少行
  943. lenRow := len(tableDataList)
  944. //移除上下空行
  945. deleteRowIndexList := make([]int, 0)
  946. if lenRow > 0 {
  947. var flag = false
  948. // 移除上方空列
  949. for rowIndex := 0; rowIndex < lenRow; rowIndex++ {
  950. isDelete := true
  951. for _, v := range tableDataList[rowIndex] {
  952. if v.Monitor != `` || (v.MergeCell.Row != rowIndex && v.MergeCell.Row != 0) {
  953. isDelete = false
  954. flag = true
  955. break
  956. }
  957. }
  958. if flag {
  959. break
  960. }
  961. if isDelete {
  962. selfTableData.RemoveTopRow++
  963. deleteRowIndexList = append(deleteRowIndexList, rowIndex)
  964. }
  965. }
  966. // 移除下方空行
  967. flag = false
  968. //尾部
  969. deleteBottomRowIndexList := make([]int, 0)
  970. for rowIndex := lenRow - 1; rowIndex >= 0; rowIndex-- {
  971. isDelete := true
  972. for _, v := range tableDataList[rowIndex] {
  973. if v.Monitor != `` {
  974. isDelete = false
  975. flag = true
  976. break
  977. }
  978. }
  979. if flag {
  980. break
  981. }
  982. if isDelete {
  983. deleteBottomRowIndexList = append(deleteBottomRowIndexList, rowIndex)
  984. selfTableData.RemoveBottomRow++
  985. }
  986. }
  987. if len(deleteBottomRowIndexList) > 0 {
  988. deleteRowIndexList = append(deleteRowIndexList, utils.RevSlice(deleteBottomRowIndexList)...)
  989. }
  990. lenDeleteRow := len(deleteRowIndexList)
  991. if lenDeleteRow > 0 {
  992. for rowIndex := lenDeleteRow - 1; rowIndex >= 0; rowIndex-- {
  993. //表格数据
  994. tableDataList = append(tableDataList[:deleteRowIndexList[rowIndex]], tableDataList[deleteRowIndexList[rowIndex]+1:]...) // 删除开头N个元素
  995. //表格高度
  996. rowHeightList = append(rowHeightList[:deleteRowIndexList[rowIndex]], rowHeightList[deleteRowIndexList[rowIndex]+1:]...) // 删除开头N个元素
  997. }
  998. }
  999. }
  1000. //移除左右空列
  1001. deleteColumnIndexList := make([]int, 0)
  1002. if len(tableDataList) > 0 {
  1003. var flag = false
  1004. lenColumn := len(tableDataList[0])
  1005. // 移除左边空列
  1006. for columnIndex := 0; columnIndex < lenColumn; columnIndex++ {
  1007. isDelete := true
  1008. for _, v := range tableDataList {
  1009. //如果一列都没有,说明是上面几行是空行,没有数据
  1010. if len(v) <= 0 {
  1011. continue
  1012. }
  1013. if v[columnIndex].Monitor != `` || (v[columnIndex].MergeCell.Column != columnIndex && v[columnIndex].MergeCell.Column != 0) {
  1014. isDelete = false
  1015. flag = true
  1016. break
  1017. }
  1018. }
  1019. if flag {
  1020. break
  1021. }
  1022. if isDelete {
  1023. selfTableData.RemoveLeftColumn++
  1024. deleteColumnIndexList = append(deleteColumnIndexList, columnIndex)
  1025. }
  1026. }
  1027. // 移除右方空列
  1028. flag = false
  1029. //右边
  1030. deleteTailColumnIndexList := make([]int, 0)
  1031. for columnIndex := lenColumn - 1; columnIndex >= 0; columnIndex-- {
  1032. isDelete := true
  1033. for _, v := range tableDataList {
  1034. //如果一列都没有,说明是上面几行是空行,没有数据
  1035. if len(v) <= 0 {
  1036. continue
  1037. }
  1038. if v[columnIndex].Monitor != `` || (v[columnIndex].MergeCell.Column != columnIndex && v[columnIndex].MergeCell.Column != 0) {
  1039. isDelete = false
  1040. flag = true
  1041. break
  1042. }
  1043. }
  1044. if flag {
  1045. break
  1046. }
  1047. if isDelete {
  1048. deleteTailColumnIndexList = append(deleteTailColumnIndexList, columnIndex)
  1049. selfTableData.RemoveRightColumn++
  1050. }
  1051. }
  1052. if len(deleteTailColumnIndexList) > 0 {
  1053. deleteColumnIndexList = append(deleteColumnIndexList, utils.RevSlice(deleteTailColumnIndexList)...)
  1054. }
  1055. lenDeleteColumn := len(deleteColumnIndexList)
  1056. if lenDeleteColumn > 0 {
  1057. for columnIndex := lenDeleteColumn - 1; columnIndex >= 0; columnIndex-- {
  1058. //表格数据
  1059. for k, v := range tableDataList {
  1060. tableDataList[k] = append(v[:deleteColumnIndexList[columnIndex]], v[deleteColumnIndexList[columnIndex]+1:]...) // 删除开头N个元素
  1061. }
  1062. //表格宽度
  1063. rowWidthList = append(rowWidthList[:deleteColumnIndexList[columnIndex]], rowWidthList[deleteColumnIndexList[columnIndex]+1:]...) // 删除开头N个元素
  1064. }
  1065. }
  1066. }
  1067. //处理合并单元格
  1068. tableDataMergeList := make([]TableDataMerge, 0)
  1069. for _, v := range item.Config.Merge {
  1070. indexRow := v.Row - selfTableData.RemoveTopRow
  1071. indexColumn := v.Column - selfTableData.RemoveLeftColumn
  1072. tableDataMerge := TableDataMerge{
  1073. StartRowIndex: indexRow,
  1074. StartColumnIndex: indexColumn,
  1075. MergeRowNum: v.Rs - 1,
  1076. MergeColumnNum: v.Cs - 1,
  1077. }
  1078. tableDataMergeList = append(tableDataMergeList, tableDataMerge)
  1079. }
  1080. // 表格数据
  1081. selfTableData.TableDataList = tableDataList
  1082. selfTableData.RowWidthList = rowWidthList
  1083. selfTableData.RowHeightList = rowHeightList
  1084. selfTableData.MergeList = tableDataMergeList
  1085. return
  1086. }
  1087. func (item *LuckySheetData) ToExcel2() (downloadFilePath string, err error) {
  1088. tableData, err := item.GetTableDataByLuckySheetDataStr()
  1089. downloadFilePath, err = getDownloadPath()
  1090. if err != nil {
  1091. return
  1092. }
  1093. f := excelize.NewFile()
  1094. // Create a new sheet.
  1095. sheetName := `Sheet1`
  1096. sheetIndex, err := f.NewSheet(sheetName)
  1097. if err != nil {
  1098. return
  1099. }
  1100. //设置列宽度
  1101. for k, v := range tableData.RowWidthList {
  1102. colName, tmpErr := excelize.ColumnNumberToName(k + 1)
  1103. if tmpErr != nil {
  1104. err = errors.New("获取单元格列名失败,ERR:" + tmpErr.Error())
  1105. err = tmpErr
  1106. return
  1107. }
  1108. err = f.SetColWidth(sheetName, colName, colName, v/10)
  1109. if err != nil {
  1110. err = errors.New("设置列宽度,ERR:" + tmpErr.Error())
  1111. return
  1112. }
  1113. }
  1114. // 写入数据
  1115. for index, v := range tableData.TableDataList {
  1116. //设置单元格高度
  1117. if tableData.RowHeightList[index] > 0 {
  1118. tmpErr := f.SetRowHeight(sheetName, index+1, tableData.RowHeightList[index]/2)
  1119. if tmpErr != nil {
  1120. err = errors.New("设置单元格高度失败,ERR:" + tmpErr.Error())
  1121. return
  1122. }
  1123. }
  1124. for colunmIndex, cellInfo := range v {
  1125. //f.NewStyle
  1126. defaultFill := excelize.Fill{
  1127. //Type: "solid",
  1128. Pattern: 1,
  1129. //Color: []string{cellInfo.Background},
  1130. Shading: 0,
  1131. }
  1132. if cellInfo.Background != `` {
  1133. defaultFill.Type = "solid"
  1134. defaultFill.Color = []string{cellInfo.Background}
  1135. }
  1136. cellStyle := &excelize.Style{
  1137. Border: []excelize.Border{
  1138. {Type: "left", Color: "000000", Style: 1},
  1139. {Type: "top", Color: "000000", Style: 1},
  1140. {Type: "bottom", Color: "000000", Style: 1},
  1141. {Type: "right", Color: "000000", Style: 1},
  1142. //{Type: "diagonalDown", Color: "A020F0", Style: 7},
  1143. //{Type: "diagonalUp", Color: "A020F0", Style: 8},
  1144. },
  1145. Fill: defaultFill,
  1146. Font: getExcelizeFontConf(cellInfo),
  1147. Alignment: getExcelizeAlignmentConf(cellInfo),
  1148. //Protection: nil,
  1149. //NumFmt: 0,
  1150. //DecimalPlaces: 0,
  1151. //CustomNumFmt: nil,
  1152. //Lang: "",
  1153. //NegRed: false,
  1154. }
  1155. cellStyleId, tmpErr := f.NewStyle(cellStyle)
  1156. if tmpErr != nil {
  1157. err = errors.New("new Style 失败,ERR:" + tmpErr.Error())
  1158. return
  1159. }
  1160. columnName, tmpErr := excelize.ColumnNumberToName(colunmIndex + 1)
  1161. if tmpErr != nil {
  1162. err = errors.New("获取单元格列名失败,ERR:" + tmpErr.Error())
  1163. return
  1164. }
  1165. cellName := columnName + strconv.Itoa(index+1)
  1166. tmpErr = f.SetCellStyle(sheetName, cellName, cellName, cellStyleId)
  1167. if tmpErr != nil {
  1168. err = errors.New("设置style失败,ERR:" + tmpErr.Error())
  1169. return
  1170. }
  1171. valueStr := cellInfo.Monitor
  1172. if valueStr == `` {
  1173. //valueStr = fmt.Sprint(cellInfo.Value)
  1174. if valueStr == `` && cellInfo.CellType.S != nil {
  1175. //不是设置在单元格上面,而是设置在文本上
  1176. for _, cellS := range cellInfo.CellType.S {
  1177. valueStr += fmt.Sprint(cellS.Value)
  1178. }
  1179. }
  1180. }
  1181. tmpErr = f.SetCellStr(sheetName, cellName, valueStr)
  1182. if tmpErr != nil {
  1183. err = errors.New("设置单元格数据失败,ERR:" + tmpErr.Error())
  1184. return
  1185. }
  1186. }
  1187. }
  1188. for _, v := range tableData.MergeList {
  1189. //开始列
  1190. startColumnName, tmpErr := excelize.ColumnNumberToName(v.StartColumnIndex + 1)
  1191. if tmpErr != nil {
  1192. err = tmpErr
  1193. return
  1194. }
  1195. startCellName := startColumnName + strconv.Itoa(v.StartRowIndex+1)
  1196. //结束列
  1197. endColumnName, tmpErr := excelize.ColumnNumberToName(v.StartColumnIndex + v.MergeColumnNum + 1)
  1198. if tmpErr != nil {
  1199. err = tmpErr
  1200. return
  1201. }
  1202. endCellName := endColumnName + strconv.Itoa(v.StartRowIndex+v.MergeRowNum+1)
  1203. err = f.MergeCell(sheetName, startCellName, endCellName)
  1204. if err != nil {
  1205. return
  1206. }
  1207. }
  1208. // Set active sheet of the workbook.
  1209. f.SetActiveSheet(sheetIndex)
  1210. // Save spreadsheet by the given path.
  1211. err = f.SaveAs(downloadFilePath)
  1212. return
  1213. }
  1214. // getExcelizeFontConf 获取表格字体配置
  1215. func getExcelizeFontConf(cellInfo LuckySheetDataValue) *excelize.Font {
  1216. fontSize := 10
  1217. familyName := ``
  1218. //single 单线 、double 双线
  1219. underlineStyle := ``
  1220. var isBold, isItalic, isUnderline bool
  1221. // 字体
  1222. {
  1223. if cellInfo.Bold == 1 {
  1224. isBold = true
  1225. }
  1226. if cellInfo.Italic == 1 {
  1227. isItalic = true
  1228. }
  1229. if cellInfo.CancelLine == 1 {
  1230. isUnderline = true
  1231. }
  1232. //if cellInfo.Fontsize != `` {
  1233. // convSize, _ := strconv.Atoi(cellInfo.Fontsize)
  1234. // if convSize > 0 {
  1235. // fontSize = convSize
  1236. // }
  1237. //}
  1238. if cellInfo.Fontsize > 0 {
  1239. fontSize = cellInfo.Fontsize
  1240. }
  1241. tmpFamilyName, familyNameOk := LuckyFontFamilyMap[cellInfo.FontFamily]
  1242. if !familyNameOk {
  1243. tmpFamilyName = "宋体"
  1244. }
  1245. familyName = tmpFamilyName
  1246. }
  1247. if isUnderline {
  1248. underlineStyle = "single"
  1249. }
  1250. //VertAlign取值:
  1251. //BASELINE、superscript、subscript
  1252. return &excelize.Font{
  1253. Bold: isBold,
  1254. Italic: isItalic,
  1255. Underline: underlineStyle,
  1256. Family: familyName,
  1257. Size: float64(fontSize),
  1258. Strike: isUnderline,
  1259. Color: cellInfo.FontColor,
  1260. VertAlign: "",
  1261. }
  1262. }
  1263. // getExcelizeAlignmentConf 获取表格单元格排列配置
  1264. func getExcelizeAlignmentConf(cellInfo LuckySheetDataValue) *excelize.Alignment {
  1265. //自动换行
  1266. isWrapText := false
  1267. if cellInfo.TextBeak == 2 {
  1268. isWrapText = true
  1269. }
  1270. rotateText := 0
  1271. //if cellInfo.RotateText != `` {
  1272. // convSize, _ := strconv.Atoi(cellInfo.RotateText)
  1273. // if convSize > 0 {
  1274. // rotateText = convSize
  1275. // }
  1276. //}
  1277. return &excelize.Alignment{
  1278. Horizontal: LuckyHorizontalMap[cellInfo.HorizontalType],
  1279. //Indent: 0,
  1280. //JustifyLastLine: false,
  1281. //ReadingOrder: 0,
  1282. //RelativeIndent: 0,
  1283. //ShrinkToFit: false,
  1284. TextRotation: rotateText,
  1285. Vertical: LuckyVerticalMap[cellInfo.VerticalType],
  1286. WrapText: isWrapText,
  1287. }
  1288. }
  1289. // getColor 获取hex颜色
  1290. func getColor(bgStr string) string {
  1291. if strings.Contains(bgStr, "(") {
  1292. arr := strings.Split(bgStr, ",")
  1293. if len(arr) != 3 {
  1294. return bgStr
  1295. }
  1296. // 第一位
  1297. tmpFirstArr := strings.Split(arr[0], "(")
  1298. arr[0] = tmpFirstArr[len(tmpFirstArr)-1]
  1299. // 最后一位
  1300. tmpLastArr := strings.Split(arr[2], ")")
  1301. arr[2] = tmpLastArr[0]
  1302. rgbArr := make([]int64, 0)
  1303. for _, v := range arr {
  1304. tmpInt, err := strconv.Atoi(utils.TrimStr(v))
  1305. if err != nil {
  1306. return bgStr
  1307. }
  1308. rgbArr = append(rgbArr, int64(tmpInt))
  1309. }
  1310. rgb := RGB{
  1311. rgbArr[0],
  1312. rgbArr[1],
  1313. rgbArr[2],
  1314. }
  1315. bgStr = "" + rgb.Rgb2Hex().Str
  1316. }
  1317. return bgStr
  1318. }
  1319. // GetTableDataByCustomData 通过自定义表格数据获取表格数据
  1320. func GetTableDataByCustomData(excelType int, data request.TableDataReq) (selfTableData TableData, err error) {
  1321. tableDataList := make([][]LuckySheetDataValue, 0)
  1322. mergeList := make([]TableDataMerge, 0)
  1323. // 指标数
  1324. lenEdb := len(data.Data)
  1325. if lenEdb <= 0 {
  1326. return
  1327. }
  1328. // 日期数
  1329. lenCol := len(data.Data[0].Data)
  1330. if lenCol <= 0 {
  1331. return
  1332. }
  1333. // 指标列:1;指标行:2
  1334. if excelType == 1 {
  1335. mergeList = append(mergeList, TableDataMerge{
  1336. StartRowIndex: 0,
  1337. StartColumnIndex: 0,
  1338. MergeRowNum: 1,
  1339. MergeColumnNum: 0,
  1340. })
  1341. // 第一行
  1342. {
  1343. firstCol := make([]LuckySheetDataValue, 0)
  1344. firstCol = append(firstCol, LuckySheetDataValue{
  1345. Value: "日期",
  1346. Monitor: "日期",
  1347. MergeCell: LuckySheetDataConfigMerge{
  1348. Row: 0, //行数
  1349. Column: 0, //列数
  1350. Rs: 2, //合并的行数
  1351. Cs: 1, //合并的列数
  1352. },
  1353. })
  1354. for _, v := range data.Data {
  1355. edbName := v.EdbName
  1356. if v.EdbAliasName != `` {
  1357. edbName = v.EdbAliasName
  1358. }
  1359. firstCol = append(firstCol, LuckySheetDataValue{
  1360. Value: edbName,
  1361. Monitor: edbName,
  1362. MergeCell: LuckySheetDataConfigMerge{},
  1363. })
  1364. }
  1365. tableDataList = append(tableDataList, firstCol)
  1366. }
  1367. // 第二行
  1368. {
  1369. secondCol := make([]LuckySheetDataValue, 0)
  1370. secondCol = append(secondCol, LuckySheetDataValue{})
  1371. for _, v := range data.Data {
  1372. name := v.Unit + " / " + v.Frequency
  1373. secondCol = append(secondCol, LuckySheetDataValue{
  1374. Value: name,
  1375. Monitor: name,
  1376. MergeCell: LuckySheetDataConfigMerge{},
  1377. })
  1378. }
  1379. tableDataList = append(tableDataList, secondCol)
  1380. }
  1381. // 开始数据了
  1382. {
  1383. for i := 0; i < lenCol; i++ {
  1384. dataCol := make([]LuckySheetDataValue, 0)
  1385. // 日期
  1386. dataCol = append(dataCol, LuckySheetDataValue{
  1387. Value: data.Data[0].Data[i].DataTime,
  1388. Monitor: data.Data[0].Data[i].DataTime,
  1389. MergeCell: LuckySheetDataConfigMerge{},
  1390. })
  1391. // 数据值
  1392. for _, v := range data.Data {
  1393. dataCol = append(dataCol, LuckySheetDataValue{
  1394. Value: v.Data[i].Value,
  1395. Monitor: v.Data[i].ShowValue,
  1396. MergeCell: LuckySheetDataConfigMerge{},
  1397. })
  1398. }
  1399. tableDataList = append(tableDataList, dataCol)
  1400. }
  1401. }
  1402. // 开始文本行了
  1403. {
  1404. for _, textColList := range data.TextRowData {
  1405. dataCol := make([]LuckySheetDataValue, 0)
  1406. for _, v := range textColList {
  1407. dataCol = append(dataCol, LuckySheetDataValue{
  1408. Value: v.Value,
  1409. Monitor: v.ShowValue,
  1410. MergeCell: LuckySheetDataConfigMerge{},
  1411. })
  1412. }
  1413. tableDataList = append(tableDataList, dataCol)
  1414. }
  1415. }
  1416. } else {
  1417. // 指标行
  1418. mergeList = append(mergeList, TableDataMerge{
  1419. StartRowIndex: 0,
  1420. StartColumnIndex: 0,
  1421. MergeRowNum: 0,
  1422. MergeColumnNum: 1,
  1423. })
  1424. // 第一行
  1425. {
  1426. firstCol := make([]LuckySheetDataValue, 0)
  1427. firstCol = append(firstCol, LuckySheetDataValue{
  1428. Value: "日期",
  1429. Monitor: "日期",
  1430. MergeCell: LuckySheetDataConfigMerge{
  1431. Row: 0, //行数
  1432. Column: 0, //列数
  1433. Rs: 1, //合并的行数
  1434. Cs: 2, //合并的列数
  1435. },
  1436. })
  1437. firstCol = append(firstCol, LuckySheetDataValue{})
  1438. // 日期列
  1439. for _, v := range data.Data[0].Data {
  1440. firstCol = append(firstCol, LuckySheetDataValue{
  1441. Value: v.DataTime,
  1442. Monitor: v.DataTime,
  1443. MergeCell: LuckySheetDataConfigMerge{},
  1444. })
  1445. }
  1446. // 文本列
  1447. for _, textColList := range data.TextRowData {
  1448. firstCol = append(firstCol, LuckySheetDataValue{
  1449. Value: textColList[0].Value,
  1450. Monitor: textColList[0].ShowValue,
  1451. MergeCell: LuckySheetDataConfigMerge{},
  1452. })
  1453. }
  1454. tableDataList = append(tableDataList, firstCol)
  1455. }
  1456. // 日期列+文本列+两列表头(日期这个文案表头)
  1457. //colLen := lenCol+2+len(data.TextRowData)
  1458. for i := 0; i < lenEdb; i++ {
  1459. dataCol := make([]LuckySheetDataValue, 0)
  1460. // 指标信息
  1461. tmpEdbInfo := data.Data[i]
  1462. // 指标名称
  1463. {
  1464. edbName := tmpEdbInfo.EdbName
  1465. if tmpEdbInfo.EdbAliasName != `` {
  1466. edbName = tmpEdbInfo.EdbAliasName
  1467. }
  1468. dataCol = append(dataCol, LuckySheetDataValue{
  1469. Value: edbName,
  1470. Monitor: edbName,
  1471. MergeCell: LuckySheetDataConfigMerge{},
  1472. })
  1473. }
  1474. // 指标单位、频度
  1475. {
  1476. name := tmpEdbInfo.Unit + " / " + tmpEdbInfo.Frequency
  1477. dataCol = append(dataCol, LuckySheetDataValue{
  1478. Value: name,
  1479. Monitor: name,
  1480. MergeCell: LuckySheetDataConfigMerge{},
  1481. })
  1482. }
  1483. // 指标数据列
  1484. for _, tmpData := range tmpEdbInfo.Data {
  1485. dataCol = append(dataCol, LuckySheetDataValue{
  1486. Value: tmpData.Value,
  1487. Monitor: tmpData.ShowValue,
  1488. MergeCell: LuckySheetDataConfigMerge{},
  1489. })
  1490. }
  1491. // 文本列
  1492. for _, textColList := range data.TextRowData {
  1493. dataCol = append(dataCol, LuckySheetDataValue{
  1494. Value: textColList[i+1].Value,
  1495. Monitor: textColList[i+1].ShowValue,
  1496. MergeCell: LuckySheetDataConfigMerge{},
  1497. })
  1498. }
  1499. tableDataList = append(tableDataList, dataCol)
  1500. }
  1501. }
  1502. selfTableData.MergeList = mergeList
  1503. selfTableData.TableDataList = tableDataList
  1504. return
  1505. }
  1506. // GetTableDataByMixedTableData 通过混合表格数据获取表格数据
  1507. func GetTableDataByMixedTableData(config [][]request.MixedTableCellDataReq) (selfTableData TableData, err error) {
  1508. tableDataList := make([][]LuckySheetDataValue, 0)
  1509. mergeList := make([]TableDataMerge, 0)
  1510. // 开始文本行了
  1511. {
  1512. for _, row := range config {
  1513. dataCol := make([]LuckySheetDataValue, 0)
  1514. for _, cell := range row {
  1515. dataCol = append(dataCol, LuckySheetDataValue{
  1516. Value: cell.Value,
  1517. Monitor: cell.ShowValue,
  1518. MergeCell: LuckySheetDataConfigMerge{},
  1519. })
  1520. }
  1521. tableDataList = append(tableDataList, dataCol)
  1522. }
  1523. }
  1524. selfTableData.MergeList = mergeList
  1525. selfTableData.TableDataList = tableDataList
  1526. return
  1527. }