|
@@ -4,6 +4,7 @@ import (
|
|
|
"box-cost/db/model"
|
|
|
"fmt"
|
|
|
"regexp"
|
|
|
+ "strings"
|
|
|
|
|
|
_ "image/gif"
|
|
|
_ "image/jpeg"
|
|
@@ -28,7 +29,40 @@ type ProductBillExcel struct {
|
|
|
|
|
|
Signatures []*model.Signature
|
|
|
|
|
|
- IsPdf string
|
|
|
+ IsPdf string
|
|
|
+ RowMap map[string]int
|
|
|
+ RowWidthArray []float64
|
|
|
+ RowsHeightArray []map[int]float64
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (b *ProductBillExcel) setRowsHeight() {
|
|
|
+ for _, rowHeight := range b.RowsHeightArray {
|
|
|
+ for row, height := range rowHeight {
|
|
|
+ b.Excel.SetRowHeight(b.SheetName, row, height)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (b *ProductBillExcel) getRangeWidth(r string) float64 {
|
|
|
+ rg := strings.Split(r, ":")
|
|
|
+
|
|
|
+ if len(rg) == 1 {
|
|
|
+ start := b.RowMap[rg[0]]
|
|
|
+ return b.RowWidthArray[start]
|
|
|
+ } else if len(rg) == 2 {
|
|
|
+ start := b.RowMap[rg[0]]
|
|
|
+ end := b.RowMap[rg[1]]
|
|
|
+ rowr := b.RowWidthArray[start : end+1]
|
|
|
+ width := 0.0
|
|
|
+ for _, v := range rowr {
|
|
|
+ width += v
|
|
|
+ }
|
|
|
+ return width
|
|
|
+ }
|
|
|
+ return 0.0
|
|
|
}
|
|
|
|
|
|
func (b *ProductBillExcel) drawTitle() error {
|
|
@@ -120,6 +154,7 @@ func (b *ProductBillExcel) drawSubTitles() error {
|
|
|
return err
|
|
|
}
|
|
|
b.Excel.SetCellValue(b.SheetName, left1Cell, value)
|
|
|
+
|
|
|
return nil
|
|
|
}
|
|
|
|
|
@@ -129,10 +164,13 @@ func (b *ProductBillExcel) drawSubTitles() error {
|
|
|
b.Excel.SetRowHeight(b.SheetName, b.Row, 21)
|
|
|
|
|
|
|
|
|
- drawLeft(b.Row+1, "供应商名称:"+b.Content.Supplier)
|
|
|
+ supplierContent := fmt.Sprintf("供应商名称:%s", b.Content.Supplier)
|
|
|
+ drawLeft(b.Row+1, supplierContent)
|
|
|
+
|
|
|
+ b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{b.Row + 1: getRowHeight(supplierContent, b.getRangeWidth("A:F"), 21)})
|
|
|
+
|
|
|
timeformat := b.Content.CreateTime.Local().Format("2006年01月02号 15:04:05")
|
|
|
drawRight(b.Row+1, "下单时间:"+timeformat)
|
|
|
- b.Excel.SetRowHeight(b.SheetName, b.Row+1, 21)
|
|
|
|
|
|
|
|
|
drawLeft(b.Row+2, "产品名称:"+b.Content.ProductName)
|
|
@@ -147,6 +185,8 @@ func (b *ProductBillExcel) drawSubTitles() error {
|
|
|
b.Excel.SetRowHeight(b.SheetName, b.Row+2, 21)
|
|
|
|
|
|
drawLall(b.Row+3, "包含工序:"+b.Content.CompProduceName)
|
|
|
+
|
|
|
+ b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{b.Row + 3: getRowHeight("包含工序:"+b.Content.CompProduceName, b.getRangeWidth("A:F"), 21)})
|
|
|
|
|
|
return nil
|
|
|
}
|
|
@@ -386,6 +426,8 @@ func (b *ProductBillExcel) Draws() {
|
|
|
}
|
|
|
b.drawRemark()
|
|
|
b.drawTableSignature()
|
|
|
+
|
|
|
+ b.setRowsHeight()
|
|
|
}
|
|
|
|
|
|
func NewProductBill(f *excelize.File) *ProductBillExcel {
|
|
@@ -410,12 +452,11 @@ func NewProductBill(f *excelize.File) *ProductBillExcel {
|
|
|
Offset: 0,
|
|
|
AlignCenterStyle: styleLeft,
|
|
|
Signatures: make([]*model.Signature, 0),
|
|
|
+ RowMap: map[string]int{"A": 0, "B": 1, "C": 2, "D": 3, "E": 4, "F": 5, "G": 6, "H": 7, "I": 8},
|
|
|
+ RowWidthArray: []float64{16, 12, 12, 12, 12, 12, 12, 12, 18},
|
|
|
+ RowsHeightArray: make([]map[int]float64, 0),
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
f.SetPageMargins(b.SheetName, excelize.PageMarginTop(1), excelize.PageMarginLeft(0.25), excelize.PageMarginRight(0))
|
|
|
return b
|
|
|
}
|