|
@@ -3,6 +3,7 @@ package api
|
|
|
import (
|
|
|
"box-cost/db/model"
|
|
|
"fmt"
|
|
|
+ "strings"
|
|
|
|
|
|
"github.com/xuri/excelize/v2"
|
|
|
)
|
|
@@ -22,7 +23,40 @@ type ProduceBillExcel struct {
|
|
|
Content *model.ProduceBill
|
|
|
Signatures []*model.Signature
|
|
|
|
|
|
- IsPdf string
|
|
|
+ IsPdf string
|
|
|
+ RowMap map[string]int
|
|
|
+ RowWidthArray []float64
|
|
|
+ RowsHeightArray []map[int]float64
|
|
|
+}
|
|
|
+
|
|
|
+// 批量设置行高
|
|
|
+func (b *ProduceBillExcel) setRowsHeight() {
|
|
|
+ for _, rowHeight := range b.RowsHeightArray {
|
|
|
+ for row, height := range rowHeight {
|
|
|
+ b.Excel.SetRowHeight(b.SheetName, row, height)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+// 获取范围内单元格的宽度 A:F
|
|
|
+func (b *ProduceBillExcel) 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 *ProduceBillExcel) drawTitle() error {
|
|
@@ -32,6 +66,8 @@ func (b *ProduceBillExcel) drawTitle() error {
|
|
|
marginLeft := excelize.PageMarginLeft(0.1)
|
|
|
endCell := fmt.Sprintf("L%d", b.Row)
|
|
|
if b.Content.IsPrint {
|
|
|
+ b.RowMap = map[string]int{"A": 0, "B": 1, "C": 2, "D": 3, "E": 4, "F": 5, "G": 6, "H": 7, "I": 8, "J": 9, "K": 10, "L": 11}
|
|
|
+ b.RowWidthArray = []float64{11, 11, 11, 10, 7, 10, 7, 6.5, 9, 9, 12, 14}
|
|
|
b.Excel.SetColWidth(b.SheetName, "A", "C", 11)
|
|
|
b.Excel.SetColWidth(b.SheetName, "D", "D", 10)
|
|
|
b.Excel.SetColWidth(b.SheetName, "E", "E", 7)
|
|
@@ -53,12 +89,12 @@ func (b *ProduceBillExcel) drawTitle() error {
|
|
|
b.Excel.SetColWidth(b.SheetName, "H", "H", 20)
|
|
|
// 是覆膜
|
|
|
if b.Content.IsLam {
|
|
|
+ b.RowMap = map[string]int{"A": 0, "B": 1, "C": 2, "D": 3, "E": 4, "F": 5, "G": 6, "H": 7, "I": 8}
|
|
|
+ b.RowWidthArray = []float64{14, 14, 14, 10, 11, 11, 12, 12, 16}
|
|
|
endCell = fmt.Sprintf("I%d", b.Row)
|
|
|
marginLeft = excelize.PageMarginLeft(0.2)
|
|
|
- b.Excel.SetColWidth(b.SheetName, "A", "A", 14)
|
|
|
- b.Excel.SetColWidth(b.SheetName, "B", "C", 14)
|
|
|
+ b.Excel.SetColWidth(b.SheetName, "A", "C", 14)
|
|
|
// 覆膜规格
|
|
|
- // b.Excel.SetColWidth(b.SheetName, "C", "C", 16)
|
|
|
b.Excel.SetColWidth(b.SheetName, "D", "D", 10)
|
|
|
b.Excel.SetColWidth(b.SheetName, "E", "F", 11)
|
|
|
b.Excel.SetColWidth(b.SheetName, "G", "H", 12)
|
|
@@ -91,7 +127,7 @@ func (b *ProduceBillExcel) drawTitle() error {
|
|
|
func (b *ProduceBillExcel) drawSubTitles() error {
|
|
|
b.Row++
|
|
|
styleLeft, err := b.Excel.NewStyle(&excelize.Style{
|
|
|
- Alignment: &excelize.Alignment{Horizontal: "left", Vertical: "center"},
|
|
|
+ Alignment: &excelize.Alignment{Horizontal: "left", Vertical: "center", WrapText: true},
|
|
|
Font: &excelize.Font{Size: 11}})
|
|
|
if err != nil {
|
|
|
return err
|
|
@@ -115,6 +151,8 @@ func (b *ProduceBillExcel) drawSubTitles() error {
|
|
|
return err
|
|
|
}
|
|
|
b.Excel.SetCellValue(b.SheetName, left1Cell, value)
|
|
|
+ // 设置行高
|
|
|
+ b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{rowIndex: getRowHeight(value, b.getRangeWidth("A:I"), 18)})
|
|
|
return nil
|
|
|
}
|
|
|
|
|
@@ -144,6 +182,8 @@ func (b *ProduceBillExcel) drawSubTitles() error {
|
|
|
return err
|
|
|
}
|
|
|
b.Excel.SetCellValue(b.SheetName, left1Cell, value)
|
|
|
+ // 设置行高
|
|
|
+ b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{rowIndex: getRowHeight(value, b.getRangeWidth("A:L"), 18)})
|
|
|
return nil
|
|
|
}
|
|
|
|
|
@@ -160,6 +200,8 @@ func (b *ProduceBillExcel) drawSubTitles() error {
|
|
|
return err
|
|
|
}
|
|
|
b.Excel.SetCellValue(b.SheetName, left1Cell, value)
|
|
|
+ // 设置行高
|
|
|
+ b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{rowIndex: getRowHeight(value, b.getRangeWidth("A:F"), 18)})
|
|
|
return nil
|
|
|
}
|
|
|
|
|
@@ -189,6 +231,8 @@ func (b *ProduceBillExcel) drawSubTitles() error {
|
|
|
return err
|
|
|
}
|
|
|
b.Excel.SetCellValue(b.SheetName, left1Cell, value)
|
|
|
+ // 设置行高
|
|
|
+ b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{rowIndex: getRowHeight(value, b.getRangeWidth("A:H"), 18)})
|
|
|
return nil
|
|
|
}
|
|
|
if b.Content.IsLam {
|
|
@@ -204,6 +248,8 @@ func (b *ProduceBillExcel) drawSubTitles() error {
|
|
|
return err
|
|
|
}
|
|
|
b.Excel.SetCellValue(b.SheetName, left1Cell, value)
|
|
|
+ // 设置行高
|
|
|
+ b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{rowIndex: getRowHeight(value, b.getRangeWidth("A:F"), 18)})
|
|
|
return nil
|
|
|
}
|
|
|
|
|
@@ -233,6 +279,8 @@ func (b *ProduceBillExcel) drawSubTitles() error {
|
|
|
return err
|
|
|
}
|
|
|
b.Excel.SetCellValue(b.SheetName, left1Cell, value)
|
|
|
+ // 设置行高
|
|
|
+ b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{rowIndex: getRowHeight(value, b.getRangeWidth("A:I"), 18)})
|
|
|
return nil
|
|
|
}
|
|
|
|
|
@@ -242,13 +290,11 @@ func (b *ProduceBillExcel) drawSubTitles() error {
|
|
|
//第一行
|
|
|
drawLeft(b.Row, "类别:"+b.Content.Type)
|
|
|
drawRight(b.Row, "单号:"+b.Content.SerialNumber)
|
|
|
- b.Excel.SetRowHeight(b.SheetName, b.Row, 21)
|
|
|
|
|
|
//第二行
|
|
|
drawLeft(b.Row+1, "供应商名称:"+b.Content.Supplier)
|
|
|
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)
|
|
@@ -260,7 +306,6 @@ func (b *ProduceBillExcel) drawSubTitles() error {
|
|
|
status = "进行中"
|
|
|
}
|
|
|
drawRight(b.Row+2, "状态:"+status)
|
|
|
- b.Excel.SetRowHeight(b.SheetName, b.Row+2, 21)
|
|
|
|
|
|
// 第四行
|
|
|
drawLall(b.Row+3, "包含工序:"+b.Content.CompProduceName)
|
|
@@ -359,7 +404,7 @@ func (b *ProduceBillExcel) drawTableTitle() error {
|
|
|
|
|
|
func (b *ProduceBillExcel) drawTableContent() error {
|
|
|
b.Row += 2
|
|
|
- var DrawRow = func(rowIndex int, values ...string) {
|
|
|
+ var DrawRow = func(rowIndex int, values ...string) float64 {
|
|
|
charas := []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"}
|
|
|
if !b.Content.IsPrint {
|
|
|
charas = []string{"A", "B", "C", "D", "E", "F", "G", "H"}
|
|
@@ -367,8 +412,8 @@ func (b *ProduceBillExcel) drawTableContent() error {
|
|
|
charas = []string{"A", "B", "C", "D", "E", "F", "G", "H", "I"}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- // }
|
|
|
+ // 获取改行最大行高
|
|
|
+ max := getRowHeight(values[0], b.getRangeWidth(charas[0]))
|
|
|
for i, c := range charas {
|
|
|
v := ""
|
|
|
if i < len(values) {
|
|
@@ -378,21 +423,11 @@ func (b *ProduceBillExcel) drawTableContent() error {
|
|
|
val2Cel := fmt.Sprintf("%s%d", c, rowIndex)
|
|
|
b.Excel.SetCellStyle(b.SheetName, val2Cel, val2Cel, b.AlignCenterStyle)
|
|
|
|
|
|
- // var magN float64 = 1
|
|
|
- // lenv := len([]rune(v))
|
|
|
- // magN = math.Ceil(float64(lenv) / 10)
|
|
|
- // if lenv%10 > 5 {
|
|
|
- // magN = math.Ceil(float64(lenv) / 10)
|
|
|
-
|
|
|
- // } else {
|
|
|
- // n := math.Floor(float64(lenv) / 10)
|
|
|
- // if n > 0 {
|
|
|
- // magN = n
|
|
|
- // }
|
|
|
- // }
|
|
|
- // b.Excel.SetRowHeight(b.SheetName, rowIndex, 21*magN)
|
|
|
- b.Excel.SetRowHeight(b.SheetName, rowIndex, 50)
|
|
|
+ if getRowHeight(v, b.getRangeWidth(c)) > max {
|
|
|
+ max = getRowHeight(v, b.getRangeWidth(c))
|
|
|
+ }
|
|
|
}
|
|
|
+ return max
|
|
|
}
|
|
|
|
|
|
produces := b.Content.Produces
|
|
@@ -418,17 +453,19 @@ func (b *ProduceBillExcel) drawTableContent() error {
|
|
|
paperCount := fmt.Sprintf("%d", produce.PaperCount)
|
|
|
b.FormatToEmpty(&paperCount)
|
|
|
|
|
|
+ rowMaxHeight := 0.0
|
|
|
if b.Content.IsPrint {
|
|
|
- DrawRow(b.Row, produce.Name, produce.Norm, produce.Paper, produce.PaperSize, paperCount, produce.PrintSize, fmt.Sprintf("%d", produce.OrderCount), produce.Unit, priceStr, budgetAmount, deliveryTime, produce.Remark)
|
|
|
+ rowMaxHeight = DrawRow(b.Row, produce.Name, produce.Norm, produce.Paper, produce.PaperSize, paperCount, produce.PrintSize, fmt.Sprintf("%d", produce.OrderCount), produce.Unit, priceStr, budgetAmount, deliveryTime, produce.Remark)
|
|
|
} else {
|
|
|
// 覆膜
|
|
|
if b.Content.IsLam {
|
|
|
- DrawRow(b.Row, produce.Name, produce.Norm, produce.PrintSize, fmt.Sprintf("%d", produce.OrderCount), priceStr, fmt.Sprintf("%.3f", produce.Price2), budgetAmount, deliveryTime, produce.Remark)
|
|
|
+ rowMaxHeight = DrawRow(b.Row, produce.Name, produce.Norm, produce.PrintSize, fmt.Sprintf("%d", produce.OrderCount), priceStr, fmt.Sprintf("%.3f", produce.Price2), budgetAmount, deliveryTime, produce.Remark)
|
|
|
} else {
|
|
|
- DrawRow(b.Row, produce.Name, produce.Norm, fmt.Sprintf("%d", produce.OrderCount), produce.Unit, priceStr, budgetAmount, deliveryTime, produce.Remark)
|
|
|
+ rowMaxHeight = DrawRow(b.Row, produce.Name, produce.Norm, fmt.Sprintf("%d", produce.OrderCount), produce.Unit, priceStr, budgetAmount, deliveryTime, produce.Remark)
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+ b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{b.Row: rowMaxHeight})
|
|
|
b.Row++
|
|
|
}
|
|
|
}
|
|
@@ -454,15 +491,18 @@ func (b *ProduceBillExcel) drawTableFooter() error {
|
|
|
sendToEndCell := fmt.Sprintf("I%d", b.Row)
|
|
|
supplierStartCell := fmt.Sprintf("J%d", b.Row)
|
|
|
supplierEndCell := fmt.Sprintf("L%d", b.Row)
|
|
|
+ b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{b.Row: getRowHeight("送货地址:"+b.Content.SendTo, b.getRangeWidth("A:I"))})
|
|
|
if !b.Content.IsPrint {
|
|
|
sendToEndCell = fmt.Sprintf("E%d", b.Row)
|
|
|
supplierStartCell = fmt.Sprintf("F%d", b.Row)
|
|
|
supplierEndCell = fmt.Sprintf("H%d", b.Row)
|
|
|
+ b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{b.Row: getRowHeight("送货地址:"+b.Content.SendTo, b.getRangeWidth("A:E"))})
|
|
|
|
|
|
if b.Content.IsLam {
|
|
|
sendToEndCell = fmt.Sprintf("F%d", b.Row)
|
|
|
supplierStartCell = fmt.Sprintf("G%d", b.Row)
|
|
|
supplierEndCell = fmt.Sprintf("I%d", b.Row)
|
|
|
+ b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{b.Row: getRowHeight("送货地址:"+b.Content.SendTo, b.getRangeWidth("A:F"))})
|
|
|
|
|
|
}
|
|
|
}
|
|
@@ -473,7 +513,6 @@ func (b *ProduceBillExcel) drawTableFooter() error {
|
|
|
b.Excel.MergeCell(b.SheetName, supplierStartCell, supplierEndCell)
|
|
|
b.Excel.SetCellStyle(b.SheetName, supplierStartCell, supplierEndCell, styleLeft)
|
|
|
b.Excel.SetCellValue(b.SheetName, supplierStartCell, "供应商签字:")
|
|
|
- b.Excel.SetRowHeight(b.SheetName, b.Row, 32)
|
|
|
|
|
|
return nil
|
|
|
}
|
|
@@ -494,11 +533,17 @@ func (b *ProduceBillExcel) drawSupplierRemark() error {
|
|
|
sendToStartCell := fmt.Sprintf("A%d", b.Row)
|
|
|
|
|
|
sendToEndCell := fmt.Sprintf("L%d", b.Row)
|
|
|
+ // 设置行高
|
|
|
+ b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{b.Row: getRowHeight("供应商备注:"+b.Content.SupplierRemark, b.getRangeWidth("A:L"), 18)})
|
|
|
if !b.Content.IsPrint {
|
|
|
sendToEndCell = fmt.Sprintf("H%d", b.Row)
|
|
|
+ // 设置行高
|
|
|
+ b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{b.Row: getRowHeight("供应商备注:"+b.Content.SupplierRemark, b.getRangeWidth("A:H"), 18)})
|
|
|
|
|
|
if b.Content.IsLam {
|
|
|
sendToEndCell = fmt.Sprintf("I%d", b.Row)
|
|
|
+ // 设置行高
|
|
|
+ b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{b.Row: getRowHeight("供应商备注:"+b.Content.SupplierRemark, b.getRangeWidth("A:I"), 18)})
|
|
|
|
|
|
}
|
|
|
}
|
|
@@ -506,7 +551,6 @@ func (b *ProduceBillExcel) drawSupplierRemark() error {
|
|
|
b.Excel.MergeCell(b.SheetName, sendToStartCell, sendToEndCell)
|
|
|
b.Excel.SetCellStyle(b.SheetName, sendToStartCell, sendToEndCell, styleLeft)
|
|
|
b.Excel.SetCellValue(b.SheetName, sendToStartCell, "供应商备注:"+b.Content.SupplierRemark)
|
|
|
- b.Excel.SetRowHeight(b.SheetName, b.Row, 32)
|
|
|
return nil
|
|
|
|
|
|
}
|
|
@@ -599,6 +643,8 @@ func (b *ProduceBillExcel) Draws() {
|
|
|
|
|
|
}
|
|
|
b.drawTableSignature()
|
|
|
+ // 设置行高
|
|
|
+ b.setRowsHeight()
|
|
|
}
|
|
|
|
|
|
func NewProduceBill(f *excelize.File) *ProduceBillExcel {
|
|
@@ -622,6 +668,9 @@ func NewProduceBill(f *excelize.File) *ProduceBillExcel {
|
|
|
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},
|
|
|
+ RowWidthArray: []float64{17, 17, 12, 6, 12, 12, 12, 20},
|
|
|
+ RowsHeightArray: make([]map[int]float64, 0),
|
|
|
}
|
|
|
|
|
|
f.SetPageMargins(b.SheetName, excelize.PageMarginTop(1), excelize.PageMarginLeft(0), excelize.PageMarginRight(0))
|