plan-summary-excel.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  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. stageStatus := ""
  196. if len(stage.BillId) < 1 {
  197. stageStatus = "未生成订单"
  198. } else {
  199. if splan.State[stage.BillId] == "created" {
  200. stageStatus = "进行中"
  201. // 审核状态
  202. if splan.Reviewed[stage.BillId] == 1 {
  203. stageStatus = "已审核"
  204. if splan.IsSend[stage.BillId] {
  205. stageStatus = "已发送"
  206. if splan.IsAck[stage.BillId] {
  207. stageStatus = "已接单"
  208. } else {
  209. stageStatus = "未接单"
  210. }
  211. } else {
  212. stageStatus = "未发送"
  213. }
  214. } else {
  215. stageStatus = "未审核"
  216. }
  217. } else if splan.State[stage.BillId] == "complete" {
  218. stageStatus = "已完成"
  219. } else {
  220. stageStatus = "未生成订单"
  221. }
  222. }
  223. 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)
  224. if stage.SupplierInfo != nil {
  225. cates[stage.SupplierInfo.Name] = append(cates[stage.SupplierInfo.Name], b.Row)
  226. }
  227. b.Row++
  228. }
  229. for supplierName, cate := range cates {
  230. mergeStartRow := cate[0]
  231. mergeEndRow := cate[len(cate)-1]
  232. b.Excel.MergeCell(b.SheetName, fmt.Sprintf("H%d", mergeStartRow), fmt.Sprintf("H%d", mergeEndRow))
  233. b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("H%d", mergeEndRow), supplierName)
  234. }
  235. endRow := b.Row - 1
  236. // 组件名字
  237. startACell := fmt.Sprintf("%s%d", "B", startRow)
  238. endACell := fmt.Sprintf("%s%d", "B", endRow)
  239. b.Excel.MergeCell(b.SheetName, startACell, endACell)
  240. err := b.Excel.SetCellStyle(b.SheetName, startACell, endACell, b.AlignCenterStyle)
  241. if err != nil {
  242. return err
  243. }
  244. b.Excel.SetCellValue(b.SheetName, startACell, comp.Name)
  245. }
  246. // 预算
  247. planBudgetPrice += perBudgetPrice
  248. // 实际金额
  249. planRealPrice += perRealPrice
  250. }
  251. }
  252. totalBudgetPrice += planBudgetPrice
  253. totalRealPrice += planRealPrice
  254. // plan
  255. planEndRow := b.Row
  256. planStartACell := fmt.Sprintf("%s%d", "A", planStartRow)
  257. planEndACell := fmt.Sprintf("%s%d", "A", planEndRow-1)
  258. b.Excel.MergeCell(b.SheetName, planStartACell, planEndACell)
  259. err := b.Excel.SetCellStyle(b.SheetName, planStartACell, planEndACell, b.AlignCenterStyle)
  260. if err != nil {
  261. return err
  262. }
  263. b.Excel.SetCellValue(b.SheetName, planStartACell, fmt.Sprintf("%s(%d)", plan.Name, plan.Total))
  264. }
  265. // summaryEndRow := b.Row
  266. // startACell := fmt.Sprintf("%s%d", "A", summaryEndRow)
  267. // endNell := fmt.Sprintf("%s%d", "N", summaryEndRow)
  268. // OCell := fmt.Sprintf("%s%d", "O", summaryEndRow)
  269. // PCell := fmt.Sprintf("%s%d", "P", summaryEndRow)
  270. // b.Excel.MergeCell(b.SheetName, startACell, endNell)
  271. // b.Excel.SetCellStyle(b.SheetName, startACell, endNell, b.AlignCenterStyle)
  272. // b.Excel.SetCellValue(b.SheetName, startACell, "生产计划汇总金额")
  273. // // 生产预算汇总
  274. // b.Excel.SetCellStyle(b.SheetName, OCell, OCell, b.AlignCenterStyle)
  275. // totalOrderRealPrice := fmt.Sprintf("%.3f", totalBudgetPrice)
  276. // b.FormatToEmpty(&totalOrderRealPrice)
  277. // b.Excel.SetCellValue(b.SheetName, OCell, totalOrderRealPrice)
  278. // // 生产实际汇总
  279. // b.Excel.SetCellStyle(b.SheetName, PCell, PCell, b.AlignCenterStyle)
  280. // totalRealPricef := fmt.Sprintf("%.3f", totalRealPrice)
  281. // b.FormatToEmpty(&totalRealPricef)
  282. // b.Excel.SetCellValue(b.SheetName, PCell, totalRealPricef)
  283. return nil
  284. }
  285. func (b *PlanSummaryExcel) drawSupplierContent() error {
  286. b.Row += 2
  287. supplier := ""
  288. // summaryPlans
  289. // 预算金额汇总
  290. var totalBudgetPrice float64 = 0.00
  291. // 实际金额汇总
  292. var totalRealPrice float64 = 0.00
  293. for _, splan := range b.Content.Plans {
  294. planStartRow := b.Row
  295. plan := splan.Plan
  296. comps := plan.Pack.Components
  297. // 预算金额汇总
  298. var planBudgetPrice float64 = 0.00
  299. // 实际金额汇总
  300. var planRealPrice float64 = 0.00
  301. if len(comps) > 0 {
  302. for _, comp := range comps {
  303. var perBudgetPrice float64 = 0.00
  304. var perRealPrice float64 = 0.00
  305. if len(comp.Stages) > 0 {
  306. startRow := 0
  307. cates := map[string][]int{}
  308. for _, stage := range comp.Stages {
  309. if stage.SupplierInfo != nil {
  310. if b.Content.SupplierId == stage.SupplierInfo.Id {
  311. supplier = stage.SupplierInfo.Name
  312. // 材料
  313. if startRow == 0 {
  314. startRow = b.Row
  315. }
  316. matHeigth := fmt.Sprintf("%d", stage.BatchSizeHeight)
  317. b.FormatToEmpty(&matHeigth)
  318. matWidth := fmt.Sprintf("%d", stage.BatchSizeWidth)
  319. b.FormatToEmpty(&matWidth)
  320. orderCount := fmt.Sprintf("%d", int(stage.OrderCount))
  321. b.FormatToEmpty(&orderCount)
  322. // 实际数量
  323. realCount := fmt.Sprintf("%d", stage.ConfirmCount)
  324. b.FormatToEmpty(&realCount)
  325. // 单价
  326. price := fmt.Sprintf("%.3f", stage.OrderPrice)
  327. b.FormatToEmpty(&price)
  328. // 预算金额
  329. budgetPrice := fmt.Sprintf("%.3f", stage.OrderPrice*float64(stage.OrderCount))
  330. perBudgetPrice += stage.OrderPrice * float64(stage.OrderCount)
  331. b.FormatToEmpty(&budgetPrice)
  332. // 实际金额
  333. perRealPrice += stage.OrderPrice * float64(stage.ConfirmCount)
  334. realPrice := fmt.Sprintf("%.3f", stage.OrderPrice*float64(stage.ConfirmCount))
  335. b.FormatToEmpty(&realPrice)
  336. unit := stage.Unit
  337. if stage.Unit == "吨" || stage.Unit == "平方米" {
  338. unit = "张"
  339. }
  340. supplierName := ""
  341. if stage.SupplierInfo != nil {
  342. supplierName = stage.SupplierInfo.Name
  343. }
  344. stageType := ""
  345. if stage.BillType > 0 {
  346. stage.Type = stage.BillType
  347. }
  348. if stage.Type == 1 {
  349. stageType = "材料采购"
  350. }
  351. if stage.Type == 2 {
  352. stageType = "工艺"
  353. }
  354. if stage.Type == 3 {
  355. stageType = "成品采购"
  356. }
  357. // 状态
  358. stageStatus := ""
  359. if len(stage.BillId) < 1 {
  360. stageStatus = "未生成订单"
  361. } else {
  362. if splan.State[stage.BillId] == "created" {
  363. stageStatus = "进行中"
  364. // 审核状态
  365. if splan.Reviewed[stage.BillId] == 1 {
  366. stageStatus = "已审核"
  367. if splan.IsSend[stage.BillId] {
  368. stageStatus = "已发送"
  369. if splan.IsAck[stage.BillId] {
  370. stageStatus = "已接单"
  371. } else {
  372. stageStatus = "未接单"
  373. }
  374. } else {
  375. stageStatus = "未发送"
  376. }
  377. } else {
  378. stageStatus = "未审核"
  379. }
  380. } else if splan.State[stage.BillId] == "complete" {
  381. stageStatus = "已完成"
  382. } else {
  383. stageStatus = "未生成订单"
  384. }
  385. }
  386. 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)
  387. if stage.SupplierInfo != nil {
  388. cates[stage.SupplierInfo.Name] = append(cates[stage.SupplierInfo.Name], b.Row)
  389. }
  390. b.Row++
  391. }
  392. }
  393. }
  394. // 合并同一供应商名
  395. for supplierName, cate := range cates {
  396. mergeStartRow := cate[0]
  397. mergeEndRow := cate[len(cate)-1]
  398. b.Excel.MergeCell(b.SheetName, fmt.Sprintf("H%d", mergeStartRow), fmt.Sprintf("H%d", mergeEndRow))
  399. b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("H%d", mergeEndRow), supplierName)
  400. }
  401. if startRow != 0 {
  402. endRow := b.Row - 1
  403. // 组件名字
  404. startACell := fmt.Sprintf("%s%d", "B", startRow)
  405. endACell := fmt.Sprintf("%s%d", "B", endRow)
  406. b.Excel.MergeCell(b.SheetName, startACell, endACell)
  407. err := b.Excel.SetCellStyle(b.SheetName, startACell, endACell, b.AlignCenterStyle)
  408. if err != nil {
  409. return err
  410. }
  411. b.Excel.SetCellValue(b.SheetName, startACell, comp.Name)
  412. }
  413. }
  414. // 预算
  415. totalBudgetPrice += perBudgetPrice
  416. // 预算
  417. totalRealPrice += perRealPrice
  418. }
  419. }
  420. totalBudgetPrice += planBudgetPrice
  421. totalRealPrice += planRealPrice
  422. // plan
  423. // b.row +2 分割每个计划
  424. planEndRow := b.Row
  425. planStartACell := fmt.Sprintf("%s%d", "A", planStartRow)
  426. planEndACell := fmt.Sprintf("%s%d", "A", planEndRow-1)
  427. b.Excel.MergeCell(b.SheetName, planStartACell, planEndACell)
  428. err := b.Excel.SetCellStyle(b.SheetName, planStartACell, planEndACell, b.AlignCenterStyle)
  429. if err != nil {
  430. return err
  431. }
  432. b.Excel.SetCellValue(b.SheetName, planStartACell, fmt.Sprintf("%s(%d)", plan.Name, plan.Total))
  433. }
  434. // summaryEndRow := b.Row
  435. // startACell := fmt.Sprintf("%s%d", "A", summaryEndRow)
  436. // endNell := fmt.Sprintf("%s%d", "N", summaryEndRow)
  437. // OCell := fmt.Sprintf("%s%d", "O", summaryEndRow)
  438. // PCell := fmt.Sprintf("%s%d", "P", summaryEndRow)
  439. // b.Excel.MergeCell(b.SheetName, startACell, endNell)
  440. // b.Excel.SetCellStyle(b.SheetName, startACell, endNell, b.AlignCenterStyle)
  441. // b.Excel.SetCellValue(b.SheetName, startACell, fmt.Sprintf("【%s】生产计划汇总金额", supplier))
  442. // // 生产预算汇总
  443. // b.Excel.SetCellStyle(b.SheetName, OCell, OCell, b.AlignCenterStyle)
  444. // totalOrderRealPrice := fmt.Sprintf("%.3f", totalBudgetPrice)
  445. // b.FormatToEmpty(&totalOrderRealPrice)
  446. // b.Excel.SetCellValue(b.SheetName, OCell, totalOrderRealPrice)
  447. // // 生产实际汇总
  448. // b.Excel.SetCellStyle(b.SheetName, PCell, PCell, b.AlignCenterStyle)
  449. // totalRealPricef := fmt.Sprintf("%.3f", totalRealPrice)
  450. // b.FormatToEmpty(&totalRealPricef)
  451. // b.Excel.SetCellValue(b.SheetName, PCell, totalRealPricef)
  452. // 供应商名字标题
  453. style, err := b.Excel.NewStyle(&excelize.Style{
  454. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  455. })
  456. if err != nil {
  457. return err
  458. }
  459. err = b.Excel.SetCellStyle(b.SheetName, "A1", "G1", style)
  460. if err != nil {
  461. return err
  462. }
  463. b.Excel.SetRowHeight(b.SheetName, 1, 32)
  464. b.Excel.SetCellValue(b.SheetName, "A1", fmt.Sprintf("【%s】-汇总表", supplier))
  465. return nil
  466. }
  467. func (b *PlanSummaryExcel) Draws() {
  468. b.drawTitle()
  469. b.drawTableTitle()
  470. if !b.Content.SupplierId.IsZero() {
  471. b.drawSupplierContent()
  472. } else {
  473. b.drawAllContent()
  474. }
  475. }
  476. func NewPlanSummaryExcel(f *excelize.File) *PlanSummaryExcel {
  477. border := []excelize.Border{
  478. {Type: "top", Style: 1, Color: "000000"},
  479. {Type: "left", Style: 1, Color: "000000"},
  480. {Type: "right", Style: 1, Color: "000000"},
  481. {Type: "bottom", Style: 1, Color: "000000"},
  482. }
  483. styleLeft, _ := f.NewStyle(&excelize.Style{
  484. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  485. Border: border,
  486. Font: &excelize.Font{Size: 10},
  487. })
  488. b := &PlanSummaryExcel{
  489. Title: "生产成本表",
  490. SheetName: "Sheet1",
  491. Excel: f,
  492. AlignCenterStyle: styleLeft,
  493. }
  494. f.SetColWidth(b.SheetName, "A", "D", 16)
  495. f.SetColWidth(b.SheetName, "E", "G", 12)
  496. f.SetColWidth(b.SheetName, "H", "H", 25)
  497. f.SetColWidth(b.SheetName, "I", "L", 16)
  498. f.SetColWidth(b.SheetName, "M", "M", 10)
  499. f.SetColWidth(b.SheetName, "N", "P", 16)
  500. f.SetPageMargins(b.SheetName, excelize.PageMarginTop(0), excelize.PageMarginLeft(0), excelize.PageMarginRight(0))
  501. return b
  502. }
  503. func (b *PlanSummaryExcel) FormatToEmpty(str *string) {
  504. if *str == "0" || *str == "0.000" {
  505. *str = ""
  506. }
  507. }