animeic 1 год назад
Родитель
Сommit
420ea094cc
3 измененных файлов с 158 добавлено и 75 удалено
  1. 79 30
      boxcost/api/bill-produce-excel.go
  2. 12 22
      boxcost/api/bill-product-excel.go
  3. 67 23
      boxcost/api/bill-purchase-excel.go

+ 79 - 30
boxcost/api/bill-produce-excel.go

@@ -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))

+ 12 - 22
boxcost/api/bill-product-excel.go

@@ -101,7 +101,7 @@ func (b *ProductBillExcel) drawTitle() error {
 func (b *ProductBillExcel) 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
@@ -167,13 +167,15 @@ func (b *ProductBillExcel) drawSubTitles() error {
 	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)})
+	b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{b.Row + 1: getRowHeight(supplierContent, b.getRangeWidth("A:F"), 18)})
 
 	timeformat := b.Content.CreateTime.Local().Format("2006年01月02号 15:04:05")
 	drawRight(b.Row+1, "下单时间:"+timeformat)
 
 	//第三行
 	drawLeft(b.Row+2, "产品名称:"+b.Content.ProductName)
+	// 设置行高
+	b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{b.Row + 2: getRowHeight("产品名称:"+b.Content.ProductName, b.getRangeWidth("A:F"), 18)})
 	status := ""
 	if b.Content.Status == "complete" {
 		status = "已完成"
@@ -186,7 +188,7 @@ func (b *ProductBillExcel) drawSubTitles() error {
 	// 第四行
 	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)})
+	b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{b.Row + 3: getRowHeight("包含工序:"+b.Content.CompProduceName, b.getRangeWidth("A:F"), 18)})
 
 	return nil
 }
@@ -237,23 +239,10 @@ func (b *ProductBillExcel) drawTableContent() error {
 			b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("%s%d", c, rowIndex), v)
 			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)
+
 			if getRowHeight(v, b.getRangeWidth(c)) > max {
 				max = getRowHeight(v, b.getRangeWidth(c))
 			}
-			b.Excel.SetRowHeight(b.SheetName, rowIndex, 50)
 		}
 		return max
 	}
@@ -280,10 +269,10 @@ func (b *ProductBillExcel) drawTableContent() error {
 			price := fmt.Sprintf("%.3f", product.OrderPrice)
 			b.FormatToEmpty(&price)
 
-			DrawRow(b.Row, product.Name, product.Norm, product.Size, orderCount, product.Unit, price, budgetAmount, deliveryTime, product.Remark)
-			// rowMaxHeight := DrawRow(b.Row, product.Name, product.Norm, product.Size, orderCount, product.Unit, price, budgetAmount, deliveryTime, product.Remark)
+			// DrawRow(b.Row, product.Name, product.Norm, product.Size, orderCount, product.Unit, price, budgetAmount, deliveryTime, product.Remark)
+			rowMaxHeight := DrawRow(b.Row, product.Name, product.Norm, product.Size, orderCount, product.Unit, price, budgetAmount, deliveryTime, product.Remark)
 			// 设置行高
-			// b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{b.Row: rowMaxHeight})
+			b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{b.Row: rowMaxHeight})
 
 			b.Row++
 		}
@@ -315,7 +304,7 @@ func (b *ProductBillExcel) drawTableFooter() error {
 	b.Excel.SetCellValue(b.SheetName, sendToStartCell, "送货地址:"+b.Content.SendTo)
 	b.Excel.MergeCell(b.SheetName, supplierStartCell, supplierEndCell)
 	// 设置行高
-	// b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{b.Row: getRowHeight("送货地址:"+b.Content.SendTo, b.getRangeWidth("A:F"))})
+	b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{b.Row: getRowHeight("送货地址:"+b.Content.SendTo, b.getRangeWidth("A:F"), 18)})
 	b.Excel.SetCellStyle(b.SheetName, supplierStartCell, supplierEndCell, styleLeft)
 	b.Excel.SetCellValue(b.SheetName, supplierStartCell, " 供应商签字:")
 	b.Excel.SetRowHeight(b.SheetName, b.Row, 32)
@@ -344,7 +333,8 @@ func (b *ProductBillExcel) 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)
+	// 设置行高
+	b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{b.Row: getRowHeight("供应商备注:"+b.Content.SupplierRemark, b.getRangeWidth("A:I"), 18)})
 	return nil
 
 }

+ 67 - 23
boxcost/api/bill-purchase-excel.go

@@ -3,6 +3,7 @@ package api
 import (
 	"box-cost/db/model"
 	"fmt"
+	"strings"
 
 	_ "image/gif"
 	_ "image/jpeg"
@@ -26,8 +27,41 @@ type PurchaseBillExcel struct {
 
 	Content *model.PurchaseBill
 
-	Signatures []*model.Signature
-	IsPdf      string
+	Signatures      []*model.Signature
+	IsPdf           string
+	RowMap          map[string]int
+	RowWidthArray   []float64
+	RowsHeightArray []map[int]float64
+}
+
+// 批量设置行高
+func (b *PurchaseBillExcel) setRowsHeight() {
+	for _, rowHeight := range b.RowsHeightArray {
+		for row, height := range rowHeight {
+			b.Excel.SetRowHeight(b.SheetName, row, height)
+		}
+	}
+
+}
+
+// 获取范围内单元格的宽度 A:F
+func (b *PurchaseBillExcel) 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 *PurchaseBillExcel) drawTitle() error {
@@ -65,7 +99,7 @@ func (b *PurchaseBillExcel) drawTitle() error {
 func (b *PurchaseBillExcel) 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
@@ -127,13 +161,18 @@ func (b *PurchaseBillExcel) 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)
 	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)
+	// 设置行高
+	b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{b.Row + 1: getRowHeight(supplierContent, b.getRangeWidth("A:G"), 18)})
 
 	//第三行
 	drawLeft(b.Row+2, "产品名称:"+b.Content.ProductName)
+	// 设置行高
+	b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{b.Row + 2: getRowHeight("产品名称:"+b.Content.ProductName, b.getRangeWidth("A:G"), 18)})
+
 	status := ""
 	if b.Content.Status == "complete" {
 		status = "已完成"
@@ -146,6 +185,8 @@ func (b *PurchaseBillExcel) drawSubTitles() error {
 
 	// 第四行
 	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:G"), 18)})
 
 	return nil
 }
@@ -221,8 +262,10 @@ func (b *PurchaseBillExcel) drawTableTitle() error {
 func (b *PurchaseBillExcel) 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"}
+		// 获取改行最大行高
+		max := getRowHeight(values[0], b.getRangeWidth(charas[0]))
 		for i, c := range charas {
 			v := ""
 			if i < len(values) {
@@ -231,22 +274,13 @@ func (b *PurchaseBillExcel) drawTableContent() error {
 			b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("%s%d", c, rowIndex), v)
 			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
 	}
 	papers := b.Content.Paper
 	if len(papers) > 0 {
@@ -271,7 +305,9 @@ func (b *PurchaseBillExcel) drawTableContent() error {
 			// 实际金额
 			realPrice = fmt.Sprintf("%.3f", paper.OrderPrice*float64(paper.ConfirmCount))
 			b.FormatToEmpty(&realPrice)
-			DrawRow(b.Row, paper.Name, paper.Norm, paper.Height, paper.Width, fmt.Sprintf("%d", paper.OrderCount), price, price2, budgetAmount, deliveryTime, paper.Remark)
+			rowMaxHeight := DrawRow(b.Row, paper.Name, paper.Norm, paper.Height, paper.Width, fmt.Sprintf("%d", paper.OrderCount), price, price2, budgetAmount, deliveryTime, paper.Remark)
+			// 设置行高
+			b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{b.Row: rowMaxHeight})
 			b.Row++
 		}
 	}
@@ -301,6 +337,8 @@ func (b *PurchaseBillExcel) drawTableFooter() error {
 	b.Excel.SetCellStyle(b.SheetName, sendToStartCell, sendToEndCell, styleLeft)
 	b.Excel.SetCellValue(b.SheetName, sendToStartCell, "送货地址:"+b.Content.SendTo)
 	b.Excel.MergeCell(b.SheetName, supplierStartCell, supplierEndCell)
+	// 设置行高
+	b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{b.Row: getRowHeight("送货地址:"+b.Content.SendTo, b.getRangeWidth("A:G"), 18)})
 	b.Excel.SetCellStyle(b.SheetName, supplierStartCell, supplierEndCell, styleLeft)
 	b.Excel.SetCellValue(b.SheetName, supplierStartCell, "供应商签字:")
 	b.Excel.SetRowHeight(b.SheetName, b.Row, 32)
@@ -323,13 +361,13 @@ func (b *PurchaseBillExcel) drawSupplierRemark() error {
 	})
 
 	sendToStartCell := fmt.Sprintf("A%d", b.Row)
-
 	sendToEndCell := fmt.Sprintf("J%d", b.Row)
 
 	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)
+	// 设置行高
+	b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{b.Row: getRowHeight("供应商备注:"+b.Content.SupplierRemark, b.getRangeWidth("A:J"), 18)})
 	return nil
 
 }
@@ -402,6 +440,9 @@ func (b *PurchaseBillExcel) Draws() {
 
 	}
 	b.drawTableSignature()
+
+	// 设置行高
+	b.setRowsHeight()
 }
 
 func NewPurchaseBill(f *excelize.File) *PurchaseBillExcel {
@@ -426,6 +467,9 @@ func NewPurchaseBill(f *excelize.File) *PurchaseBillExcel {
 		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, "J": 9},
+		RowWidthArray:    []float64{16, 16, 9, 9, 9, 9, 9, 12, 12, 16},
+		RowsHeightArray:  make([]map[int]float64, 0),
 	}
 
 	f.SetPageMargins(b.SheetName, excelize.PageMarginTop(1), excelize.PageMarginLeft(0), excelize.PageMarginRight(0))