|
@@ -3,6 +3,7 @@ package api
|
|
|
import (
|
|
|
"box-cost/db/model"
|
|
|
"fmt"
|
|
|
+ "math"
|
|
|
|
|
|
_ "image/gif"
|
|
|
_ "image/jpeg"
|
|
@@ -33,17 +34,12 @@ type ProductBillExcel struct {
|
|
|
func (b *ProductBillExcel) drawTitle() error {
|
|
|
b.Row++
|
|
|
startCell := fmt.Sprintf("A%d", b.Row)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
endCell := fmt.Sprintf("H%d", b.Row)
|
|
|
marginLeft := excelize.PageMarginLeft(0.35)
|
|
|
b.Excel.SetColWidth(b.SheetName, "A", "A", 17)
|
|
|
b.Excel.SetColWidth(b.SheetName, "B", "B", 14)
|
|
|
b.Excel.SetColWidth(b.SheetName, "C", "G", 12)
|
|
|
b.Excel.SetColWidth(b.SheetName, "H", "H", 22)
|
|
|
-
|
|
|
b.Excel.SetPageMargins(b.SheetName, marginLeft)
|
|
|
err := b.Excel.MergeCell(b.SheetName, startCell, endCell)
|
|
|
if err != nil {
|
|
@@ -80,38 +76,6 @@ func (b *ProductBillExcel) drawSubTitles() error {
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
drawLeft := func(rowIndex int, value string) error {
|
|
|
|
|
|
left1Cell := fmt.Sprintf("A%d", rowIndex)
|
|
@@ -141,7 +105,6 @@ func (b *ProductBillExcel) drawSubTitles() error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-
|
|
|
|
|
|
drawLeft(b.Row, "类别:"+b.Content.Type)
|
|
|
drawRight(b.Row, "单号:"+b.Content.SerialNumber)
|
|
@@ -187,8 +150,6 @@ func (b *ProductBillExcel) drawTableTitle() error {
|
|
|
return b.Excel.SetCellValue(b.SheetName, left1Cell, value)
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
drawCol("A", "采购项目")
|
|
|
drawCol("B", "规格")
|
|
|
drawCol("C", "下单数量")
|
|
@@ -197,19 +158,6 @@ func (b *ProductBillExcel) drawTableTitle() error {
|
|
|
drawCol("F", "预算金额")
|
|
|
drawCol("G", "交货时间")
|
|
|
drawCol("H", "备注")
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
return nil
|
|
|
}
|
|
|
|
|
@@ -217,11 +165,7 @@ func (b *ProductBillExcel) drawTableContent() error {
|
|
|
b.Row += 2
|
|
|
|
|
|
var DrawRow = func(rowIndex int, values ...string) {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
charas := []string{"A", "B", "C", "D", "E", "F", "G", "H"}
|
|
|
-
|
|
|
for i, c := range charas {
|
|
|
v := ""
|
|
|
if i < len(values) {
|
|
@@ -230,8 +174,18 @@ 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)
|
|
|
-
|
|
|
- b.Excel.SetRowHeight(b.SheetName, rowIndex, 21)
|
|
|
+ var magN float64 = 1
|
|
|
+ lenv := len([]rune(v))
|
|
|
+ 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)
|
|
|
}
|
|
|
}
|
|
|
products := b.Content.Products
|
|
@@ -257,12 +211,7 @@ func (b *ProductBillExcel) drawTableContent() error {
|
|
|
price := fmt.Sprintf("%.3f", product.OrderPrice)
|
|
|
b.FormatToEmpty(&price)
|
|
|
|
|
|
-
|
|
|
-
|
|
|
DrawRow(b.Row, product.Name, product.Norm, orderCount, product.Unit, price, budgetAmount, deliveryTime, product.Remark)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
|
|
|
b.Row++
|
|
|
}
|
|
@@ -308,116 +257,6 @@ func (b *ProductBillExcel) drawTableFooter() error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
func (b *ProductBillExcel) drawTableSignature() error {
|
|
|
b.Row += 2
|
|
|
|
|
@@ -432,22 +271,12 @@ func (b *ProductBillExcel) drawTableSignature() error {
|
|
|
b.Excel.MergeCell(b.SheetName, billUserCellS, billUserCellE)
|
|
|
b.Excel.SetCellValue(b.SheetName, billUserCellS, "制单人:"+b.Content.UserName)
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
fontNum := "E"
|
|
|
image1s := "F"
|
|
|
image2s := "H"
|
|
|
image1e := "G"
|
|
|
image2e := "H"
|
|
|
|
|
|
-
|
|
|
-
|
|
|
fontCell := fmt.Sprintf("%s%d", fontNum, b.Row)
|
|
|
fontEndCell := fmt.Sprintf("%s%d", fontNum, b.Row+2)
|
|
|
|
|
@@ -492,7 +321,6 @@ func (b *ProductBillExcel) Draws() {
|
|
|
b.drawTableTitle()
|
|
|
b.drawTableContent()
|
|
|
b.drawTableFooter()
|
|
|
-
|
|
|
b.drawTableSignature()
|
|
|
}
|
|
|
|
|
@@ -506,7 +334,7 @@ func NewProductBill(f *excelize.File) *ProductBillExcel {
|
|
|
}
|
|
|
|
|
|
styleLeft, _ := f.NewStyle(&excelize.Style{
|
|
|
- Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
|
|
|
+ Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
|
|
|
Border: border,
|
|
|
Font: &excelize.Font{Size: 10},
|
|
|
})
|