plan-summary-excel.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. package api
  2. import (
  3. "fmt"
  4. "github.com/xuri/excelize/v2"
  5. )
  6. // 生产成本表
  7. type PlanSummaryExcel struct {
  8. Row int
  9. Title string
  10. Excel *excelize.File
  11. SheetName string
  12. AlignCenterStyle int
  13. Content *SupplierPlanSummary
  14. }
  15. func (b *PlanSummaryExcel) drawTitle() error {
  16. b.Row++
  17. startCell := fmt.Sprintf("A%d", b.Row)
  18. err := b.Excel.MergeCell(b.SheetName, startCell, fmt.Sprintf("P%d", b.Row))
  19. if err != nil {
  20. return err
  21. }
  22. style, err := b.Excel.NewStyle(&excelize.Style{
  23. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  24. Font: &excelize.Font{Bold: true, Size: 18}})
  25. if err != nil {
  26. return err
  27. }
  28. err = b.Excel.SetCellStyle(b.SheetName, startCell, startCell, style)
  29. if err != nil {
  30. return err
  31. }
  32. b.Excel.SetRowHeight(b.SheetName, b.Row, 23)
  33. b.Excel.SetCellValue(b.SheetName, startCell, "汇总表")
  34. return nil
  35. }
  36. func (b *PlanSummaryExcel) drawTableTitle() error {
  37. b.Row++
  38. var drawCol = func(prefix string, value string) error {
  39. left1Cell := fmt.Sprintf("%s%d", prefix, b.Row)
  40. left2Cell := fmt.Sprintf("%s%d", prefix, b.Row+1)
  41. err := b.Excel.MergeCell(b.SheetName, left1Cell, left2Cell)
  42. if err != nil {
  43. return err
  44. }
  45. err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left2Cell, b.AlignCenterStyle)
  46. if err != nil {
  47. return err
  48. }
  49. return b.Excel.SetCellValue(b.SheetName, left1Cell, value)
  50. }
  51. var drawCol2 = func(prefix1 string, prefix2 string, value1 string, value2 string, value3 string) error {
  52. left1Cell := fmt.Sprintf("%s%d", prefix1, b.Row)
  53. left2Cell := fmt.Sprintf("%s%d", prefix2, b.Row)
  54. err := b.Excel.MergeCell(b.SheetName, left1Cell, left2Cell)
  55. if err != nil {
  56. return err
  57. }
  58. if err != nil {
  59. fmt.Println(err)
  60. return err
  61. }
  62. err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left2Cell, b.AlignCenterStyle)
  63. if err != nil {
  64. return err
  65. }
  66. b.Excel.SetCellValue(b.SheetName, left1Cell, value1)
  67. val2Cel := fmt.Sprintf("%s%d", prefix1, b.Row+1)
  68. b.Excel.SetCellStyle(b.SheetName, val2Cel, val2Cel, b.AlignCenterStyle)
  69. b.Excel.SetCellValue(b.SheetName, val2Cel, value2)
  70. val3Cel := fmt.Sprintf("%s%d", prefix2, b.Row+1)
  71. b.Excel.SetCellStyle(b.SheetName, val3Cel, val3Cel, b.AlignCenterStyle)
  72. b.Excel.SetCellValue(b.SheetName, val3Cel, value3)
  73. return nil
  74. }
  75. var drawCol3 = func(prefix1 string, prefix2 string, prefix3 string, value1 string, value2 string, value3 string, value4 string) error {
  76. left1Cell := fmt.Sprintf("%s%d", prefix1, b.Row)
  77. left3Cell := fmt.Sprintf("%s%d", prefix3, b.Row)
  78. err := b.Excel.MergeCell(b.SheetName, left1Cell, left3Cell)
  79. if err != nil {
  80. return err
  81. }
  82. if err != nil {
  83. fmt.Println(err)
  84. return err
  85. }
  86. err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left3Cell, b.AlignCenterStyle)
  87. if err != nil {
  88. return err
  89. }
  90. b.Excel.SetCellValue(b.SheetName, left1Cell, value1)
  91. val2Cel := fmt.Sprintf("%s%d", prefix1, b.Row+1)
  92. b.Excel.SetCellStyle(b.SheetName, val2Cel, val2Cel, b.AlignCenterStyle)
  93. b.Excel.SetCellValue(b.SheetName, val2Cel, value2)
  94. val3Cel := fmt.Sprintf("%s%d", prefix2, b.Row+1)
  95. b.Excel.SetCellStyle(b.SheetName, val3Cel, val3Cel, b.AlignCenterStyle)
  96. b.Excel.SetCellValue(b.SheetName, val3Cel, value3)
  97. val4Cel := fmt.Sprintf("%s%d", prefix3, b.Row+1)
  98. b.Excel.SetCellStyle(b.SheetName, val4Cel, val4Cel, b.AlignCenterStyle)
  99. b.Excel.SetCellValue(b.SheetName, val4Cel, value4)
  100. return nil
  101. }
  102. drawCol("A", "产品名称")
  103. drawCol("B", "产品部件名称")
  104. drawCol2("C", "D", "类型/项目", "类型", "项目")
  105. drawCol("E", "下单数量")
  106. drawCol("F", "实际数量")
  107. drawCol("G", "状态") // 生成订单状态 审核状态 发送状态 完成状态
  108. drawCol("H", "供应商名称")
  109. drawCol("I", "单价")
  110. drawCol3("J", "K", "L", "规格", "厚度(纸克)", "长", "宽")
  111. drawCol("M", "单位")
  112. drawCol("N", "下单单价")
  113. drawCol("O", "预算金额")
  114. drawCol("P", "实际金额")
  115. return nil
  116. }
  117. func (b *PlanSummaryExcel) drawRow(rowIndex int, values ...string) {
  118. charas := []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P"}
  119. for i, c := range charas {
  120. v := ""
  121. if i < len(values) {
  122. v = values[i]
  123. }
  124. b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("%s%d", c, rowIndex), v)
  125. val2Cel := fmt.Sprintf("%s%d", c, rowIndex)
  126. b.Excel.SetCellStyle(b.SheetName, val2Cel, val2Cel, b.AlignCenterStyle)
  127. b.Excel.SetRowHeight(b.SheetName, rowIndex, 32)
  128. }
  129. }
  130. func (b *PlanSummaryExcel) drawAllContent() error {
  131. b.Row += 2
  132. // summaryPlans
  133. // 预算金额汇总
  134. var totalBudgetPrice float64 = 0.00
  135. // 实际金额汇总
  136. var totalRealPrice float64 = 0.00
  137. for _, splan := range b.Content.Plans {
  138. planStartRow := b.Row
  139. plan := splan.Plan
  140. comps := plan.Pack.Components
  141. // 预算金额汇总
  142. var planBudgetPrice float64 = 0.00
  143. // 实际金额汇总
  144. var planRealPrice float64 = 0.00
  145. if len(comps) > 0 {
  146. for _, comp := range comps {
  147. var perBudgetPrice float64 = 0.00
  148. var perRealPrice float64 = 0.00
  149. if len(comp.Stages) > 0 {
  150. startRow := b.Row
  151. cates := map[string][]int{}
  152. for _, stage := range comp.Stages {
  153. matHeigth := fmt.Sprintf("%d", stage.BatchSizeHeight)
  154. b.FormatToEmpty(&matHeigth)
  155. matWidth := fmt.Sprintf("%d", stage.BatchSizeWidth)
  156. b.FormatToEmpty(&matWidth)
  157. orderCount := fmt.Sprintf("%d", int(stage.OrderCount))
  158. b.FormatToEmpty(&orderCount)
  159. // 实际数量
  160. realCount := fmt.Sprintf("%d", stage.ConfirmCount)
  161. b.FormatToEmpty(&realCount)
  162. // 单价
  163. price := fmt.Sprintf("%.3f", stage.OrderPrice)
  164. b.FormatToEmpty(&price)
  165. // 预算金额
  166. budgetPrice := fmt.Sprintf("%.3f", stage.OrderPrice*float64(stage.OrderCount))
  167. perBudgetPrice += stage.OrderPrice * float64(stage.OrderCount)
  168. b.FormatToEmpty(&budgetPrice)
  169. // 实际金额
  170. perRealPrice += stage.OrderPrice * float64(stage.ConfirmCount)
  171. realPrice := fmt.Sprintf("%.3f", stage.OrderPrice*float64(stage.ConfirmCount))
  172. b.FormatToEmpty(&realPrice)
  173. unit := stage.Unit
  174. if stage.Unit == "吨" || stage.Unit == "平方米" {
  175. unit = "张"
  176. }
  177. supplierName := ""
  178. if stage.SupplierInfo != nil {
  179. supplierName = stage.SupplierInfo.Name
  180. }
  181. stageType := ""
  182. if stage.BillType > 0 {
  183. stage.Type = stage.BillType
  184. }
  185. if stage.Type == 1 {
  186. stageType = "材料采购"
  187. }
  188. if stage.Type == 2 {
  189. stageType = "工艺"
  190. }
  191. if stage.Type == 3 {
  192. stageType = "成品采购"
  193. }
  194. // 状态
  195. stop := false
  196. stageStatus := ""
  197. if len(stage.BillId) < 1 {
  198. stageStatus = "未生成订单"
  199. stop = true
  200. }
  201. // 审核状态
  202. if !stop {
  203. if splan.Reviewed[stage.BillId] == 1 {
  204. stageStatus = "已审核"
  205. } else {
  206. stageStatus = "未审核"
  207. stop = true
  208. }
  209. }
  210. // 接单状态
  211. if !stop {
  212. if splan.IsAck[stage.BillId] {
  213. stageStatus = "已接单"
  214. } else {
  215. stageStatus = "未接单"
  216. stop = true
  217. }
  218. }
  219. // 完成状态
  220. if !stop {
  221. if splan.State[stage.BillId] == "complete" {
  222. stageStatus = "已完成"
  223. } else if splan.State[stage.BillId] == "created" {
  224. stageStatus = "进行中"
  225. }
  226. }
  227. b.drawRow(b.Row, "", "", stageType, stage.Name, orderCount, realCount, stageStatus, supplierName, fmt.Sprintf("%.3f元/%s", stage.Price, stage.Unit), stage.Norm, matHeigth, matWidth, unit, price, budgetPrice, realPrice)
  228. if stage.SupplierInfo != nil {
  229. cates[stage.SupplierInfo.Name] = append(cates[stage.SupplierInfo.Name], b.Row)
  230. }
  231. b.Row++
  232. }
  233. for supplierName, cate := range cates {
  234. mergeStartRow := cate[0]
  235. mergeEndRow := cate[len(cate)-1]
  236. b.Excel.MergeCell(b.SheetName, fmt.Sprintf("H%d", mergeStartRow), fmt.Sprintf("H%d", mergeEndRow))
  237. b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("H%d", mergeEndRow), supplierName)
  238. }
  239. endRow := b.Row - 1
  240. // 组件名字
  241. startACell := fmt.Sprintf("%s%d", "B", startRow)
  242. endACell := fmt.Sprintf("%s%d", "B", endRow)
  243. b.Excel.MergeCell(b.SheetName, startACell, endACell)
  244. err := b.Excel.SetCellStyle(b.SheetName, startACell, endACell, b.AlignCenterStyle)
  245. if err != nil {
  246. return err
  247. }
  248. b.Excel.SetCellValue(b.SheetName, startACell, comp.Name)
  249. }
  250. // 预算
  251. planBudgetPrice += perBudgetPrice
  252. // 实际金额
  253. planRealPrice += perRealPrice
  254. }
  255. }
  256. totalBudgetPrice += planBudgetPrice
  257. totalRealPrice += planRealPrice
  258. // plan
  259. planEndRow := b.Row
  260. planStartACell := fmt.Sprintf("%s%d", "A", planStartRow)
  261. planEndACell := fmt.Sprintf("%s%d", "A", planEndRow-1)
  262. b.Excel.MergeCell(b.SheetName, planStartACell, planEndACell)
  263. err := b.Excel.SetCellStyle(b.SheetName, planStartACell, planEndACell, b.AlignCenterStyle)
  264. if err != nil {
  265. return err
  266. }
  267. b.Excel.SetCellValue(b.SheetName, planStartACell, plan.Name)
  268. }
  269. // summaryEndRow := b.Row
  270. // startACell := fmt.Sprintf("%s%d", "A", summaryEndRow)
  271. // endNell := fmt.Sprintf("%s%d", "N", summaryEndRow)
  272. // OCell := fmt.Sprintf("%s%d", "O", summaryEndRow)
  273. // PCell := fmt.Sprintf("%s%d", "P", summaryEndRow)
  274. // b.Excel.MergeCell(b.SheetName, startACell, endNell)
  275. // b.Excel.SetCellStyle(b.SheetName, startACell, endNell, b.AlignCenterStyle)
  276. // b.Excel.SetCellValue(b.SheetName, startACell, "生产计划汇总金额")
  277. // // 生产预算汇总
  278. // b.Excel.SetCellStyle(b.SheetName, OCell, OCell, b.AlignCenterStyle)
  279. // totalOrderRealPrice := fmt.Sprintf("%.3f", totalBudgetPrice)
  280. // b.FormatToEmpty(&totalOrderRealPrice)
  281. // b.Excel.SetCellValue(b.SheetName, OCell, totalOrderRealPrice)
  282. // // 生产实际汇总
  283. // b.Excel.SetCellStyle(b.SheetName, PCell, PCell, b.AlignCenterStyle)
  284. // totalRealPricef := fmt.Sprintf("%.3f", totalRealPrice)
  285. // b.FormatToEmpty(&totalRealPricef)
  286. // b.Excel.SetCellValue(b.SheetName, PCell, totalRealPricef)
  287. return nil
  288. }
  289. func (b *PlanSummaryExcel) drawSupplierContent() error {
  290. b.Row += 2
  291. supplier := ""
  292. // summaryPlans
  293. // 预算金额汇总
  294. var totalBudgetPrice float64 = 0.00
  295. // 实际金额汇总
  296. var totalRealPrice float64 = 0.00
  297. for _, splan := range b.Content.Plans {
  298. planStartRow := b.Row
  299. plan := splan.Plan
  300. comps := plan.Pack.Components
  301. // 预算金额汇总
  302. var planBudgetPrice float64 = 0.00
  303. // 实际金额汇总
  304. var planRealPrice float64 = 0.00
  305. if len(comps) > 0 {
  306. for _, comp := range comps {
  307. var perBudgetPrice float64 = 0.00
  308. var perRealPrice float64 = 0.00
  309. if len(comp.Stages) > 0 {
  310. startRow := 0
  311. cates := map[string][]int{}
  312. for _, stage := range comp.Stages {
  313. if stage.SupplierInfo != nil {
  314. if b.Content.SupplierId == stage.SupplierInfo.Id {
  315. supplier = stage.SupplierInfo.Name
  316. // 材料
  317. if startRow == 0 {
  318. startRow = b.Row
  319. }
  320. matHeigth := fmt.Sprintf("%d", stage.BatchSizeHeight)
  321. b.FormatToEmpty(&matHeigth)
  322. matWidth := fmt.Sprintf("%d", stage.BatchSizeWidth)
  323. b.FormatToEmpty(&matWidth)
  324. orderCount := fmt.Sprintf("%d", int(stage.OrderCount))
  325. b.FormatToEmpty(&orderCount)
  326. // 实际数量
  327. realCount := fmt.Sprintf("%d", stage.ConfirmCount)
  328. b.FormatToEmpty(&realCount)
  329. // 单价
  330. price := fmt.Sprintf("%.3f", stage.OrderPrice)
  331. b.FormatToEmpty(&price)
  332. // 预算金额
  333. budgetPrice := fmt.Sprintf("%.3f", stage.OrderPrice*float64(stage.OrderCount))
  334. perBudgetPrice += stage.OrderPrice * float64(stage.OrderCount)
  335. b.FormatToEmpty(&budgetPrice)
  336. // 实际金额
  337. perRealPrice += stage.OrderPrice * float64(stage.ConfirmCount)
  338. realPrice := fmt.Sprintf("%.3f", stage.OrderPrice*float64(stage.ConfirmCount))
  339. b.FormatToEmpty(&realPrice)
  340. unit := stage.Unit
  341. if stage.Unit == "吨" || stage.Unit == "平方米" {
  342. unit = "张"
  343. }
  344. supplierName := ""
  345. if stage.SupplierInfo != nil {
  346. supplierName = stage.SupplierInfo.Name
  347. }
  348. stageType := ""
  349. if stage.BillType > 0 {
  350. stage.Type = stage.BillType
  351. }
  352. if stage.Type == 1 {
  353. stageType = "材料采购"
  354. }
  355. if stage.Type == 2 {
  356. stageType = "工艺"
  357. }
  358. if stage.Type == 3 {
  359. stageType = "成品采购"
  360. }
  361. // 状态
  362. stop := false
  363. stageStatus := ""
  364. if len(stage.BillId) < 1 {
  365. stageStatus = "未生成订单"
  366. stop = true
  367. }
  368. // 审核状态
  369. if !stop {
  370. if splan.Reviewed[stage.BillId] == 1 {
  371. stageStatus = "已审核"
  372. } else {
  373. stageStatus = "未审核"
  374. stop = true
  375. }
  376. }
  377. // 接单状态
  378. if !stop {
  379. if splan.IsAck[stage.BillId] {
  380. stageStatus = "已接单"
  381. } else {
  382. stageStatus = "未接单"
  383. stop = true
  384. }
  385. }
  386. // 完成状态
  387. if !stop {
  388. if splan.State[stage.BillId] == "complete" {
  389. stageStatus = "已完成"
  390. } else if splan.State[stage.BillId] == "created" {
  391. stageStatus = "进行中"
  392. }
  393. }
  394. b.drawRow(b.Row, "", "", stageType, stage.Name, orderCount, realCount, stageStatus, supplierName, fmt.Sprintf("%.3f元/%s", stage.Price, stage.Unit), stage.Norm, matHeigth, matWidth, unit, price, budgetPrice, realPrice)
  395. if stage.SupplierInfo != nil {
  396. cates[stage.SupplierInfo.Name] = append(cates[stage.SupplierInfo.Name], b.Row)
  397. }
  398. b.Row++
  399. }
  400. }
  401. }
  402. // 合并同一供应商名
  403. for supplierName, cate := range cates {
  404. mergeStartRow := cate[0]
  405. mergeEndRow := cate[len(cate)-1]
  406. b.Excel.MergeCell(b.SheetName, fmt.Sprintf("H%d", mergeStartRow), fmt.Sprintf("H%d", mergeEndRow))
  407. b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("H%d", mergeEndRow), supplierName)
  408. }
  409. if startRow != 0 {
  410. endRow := b.Row - 1
  411. // 组件名字
  412. startACell := fmt.Sprintf("%s%d", "B", startRow)
  413. endACell := fmt.Sprintf("%s%d", "B", endRow)
  414. b.Excel.MergeCell(b.SheetName, startACell, endACell)
  415. err := b.Excel.SetCellStyle(b.SheetName, startACell, endACell, b.AlignCenterStyle)
  416. if err != nil {
  417. return err
  418. }
  419. b.Excel.SetCellValue(b.SheetName, startACell, comp.Name)
  420. }
  421. }
  422. // 预算
  423. totalBudgetPrice += perBudgetPrice
  424. // 预算
  425. totalRealPrice += perRealPrice
  426. }
  427. }
  428. totalBudgetPrice += planBudgetPrice
  429. totalRealPrice += planRealPrice
  430. // plan
  431. // b.row +2 分割每个计划
  432. planEndRow := b.Row
  433. planStartACell := fmt.Sprintf("%s%d", "A", planStartRow)
  434. planEndACell := fmt.Sprintf("%s%d", "A", planEndRow-1)
  435. b.Excel.MergeCell(b.SheetName, planStartACell, planEndACell)
  436. err := b.Excel.SetCellStyle(b.SheetName, planStartACell, planEndACell, b.AlignCenterStyle)
  437. if err != nil {
  438. return err
  439. }
  440. b.Excel.SetCellValue(b.SheetName, planStartACell, plan.Name)
  441. }
  442. // summaryEndRow := b.Row
  443. // startACell := fmt.Sprintf("%s%d", "A", summaryEndRow)
  444. // endNell := fmt.Sprintf("%s%d", "N", summaryEndRow)
  445. // OCell := fmt.Sprintf("%s%d", "O", summaryEndRow)
  446. // PCell := fmt.Sprintf("%s%d", "P", summaryEndRow)
  447. // b.Excel.MergeCell(b.SheetName, startACell, endNell)
  448. // b.Excel.SetCellStyle(b.SheetName, startACell, endNell, b.AlignCenterStyle)
  449. // b.Excel.SetCellValue(b.SheetName, startACell, fmt.Sprintf("【%s】生产计划汇总金额", supplier))
  450. // // 生产预算汇总
  451. // b.Excel.SetCellStyle(b.SheetName, OCell, OCell, b.AlignCenterStyle)
  452. // totalOrderRealPrice := fmt.Sprintf("%.3f", totalBudgetPrice)
  453. // b.FormatToEmpty(&totalOrderRealPrice)
  454. // b.Excel.SetCellValue(b.SheetName, OCell, totalOrderRealPrice)
  455. // // 生产实际汇总
  456. // b.Excel.SetCellStyle(b.SheetName, PCell, PCell, b.AlignCenterStyle)
  457. // totalRealPricef := fmt.Sprintf("%.3f", totalRealPrice)
  458. // b.FormatToEmpty(&totalRealPricef)
  459. // b.Excel.SetCellValue(b.SheetName, PCell, totalRealPricef)
  460. // 供应商名字标题
  461. style, err := b.Excel.NewStyle(&excelize.Style{
  462. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  463. })
  464. if err != nil {
  465. return err
  466. }
  467. err = b.Excel.SetCellStyle(b.SheetName, "A1", "G1", style)
  468. if err != nil {
  469. return err
  470. }
  471. b.Excel.SetRowHeight(b.SheetName, 1, 32)
  472. b.Excel.SetCellValue(b.SheetName, "A1", fmt.Sprintf("【%s】-汇总表", supplier))
  473. return nil
  474. }
  475. func (b *PlanSummaryExcel) Draws() {
  476. b.drawTitle()
  477. b.drawTableTitle()
  478. if !b.Content.SupplierId.IsZero() {
  479. b.drawSupplierContent()
  480. } else {
  481. b.drawAllContent()
  482. }
  483. }
  484. func NewPlanSummaryExcel(f *excelize.File) *PlanSummaryExcel {
  485. border := []excelize.Border{
  486. {Type: "top", Style: 1, Color: "000000"},
  487. {Type: "left", Style: 1, Color: "000000"},
  488. {Type: "right", Style: 1, Color: "000000"},
  489. {Type: "bottom", Style: 1, Color: "000000"},
  490. }
  491. styleLeft, _ := f.NewStyle(&excelize.Style{
  492. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  493. Border: border,
  494. Font: &excelize.Font{Size: 10},
  495. })
  496. b := &PlanSummaryExcel{
  497. Title: "生产成本表",
  498. SheetName: "Sheet1",
  499. Excel: f,
  500. AlignCenterStyle: styleLeft,
  501. }
  502. f.SetColWidth(b.SheetName, "A", "D", 16)
  503. f.SetColWidth(b.SheetName, "E", "G", 12)
  504. f.SetColWidth(b.SheetName, "H", "H", 25)
  505. f.SetColWidth(b.SheetName, "I", "L", 16)
  506. f.SetColWidth(b.SheetName, "M", "M", 10)
  507. f.SetColWidth(b.SheetName, "N", "P", 16)
  508. f.SetPageMargins(b.SheetName, excelize.PageMarginTop(0), excelize.PageMarginLeft(0), excelize.PageMarginRight(0))
  509. return b
  510. }
  511. func (b *PlanSummaryExcel) FormatToEmpty(str *string) {
  512. if *str == "0" || *str == "0.000" {
  513. *str = ""
  514. }
  515. }