|
@@ -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("J%d", b.Row)
|
|
|
- // marginLeft := excelize.PageMarginLeft(0.2)
|
|
|
- // !!isPdf
|
|
|
- // if b.IsPdf == "true" {
|
|
|
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
|
|
|
}
|
|
|
|
|
|
- // var drawLeft = func(rowIndex int, value string) error {
|
|
|
- // //左边1
|
|
|
- // left1Cell := fmt.Sprintf("A%d", rowIndex)
|
|
|
- // err = b.Excel.MergeCell(b.SheetName, left1Cell, fmt.Sprintf("F%d", rowIndex))
|
|
|
- // if err != nil {
|
|
|
- // return err
|
|
|
- // }
|
|
|
- // err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left1Cell, styleLeft)
|
|
|
- // if err != nil {
|
|
|
- // return err
|
|
|
- // }
|
|
|
- // b.Excel.SetCellValue(b.SheetName, left1Cell, value)
|
|
|
- // return nil
|
|
|
- // }
|
|
|
-
|
|
|
- // var drawRight = func(rowIndex int, value string) error {
|
|
|
- // right1Cell := fmt.Sprintf("G%d", rowIndex)
|
|
|
- // err = b.Excel.MergeCell(b.SheetName, right1Cell, fmt.Sprintf("J%d", rowIndex))
|
|
|
- // if err != nil {
|
|
|
- // return err
|
|
|
- // }
|
|
|
- // err = b.Excel.SetCellStyle(b.SheetName, right1Cell, right1Cell, styleRight)
|
|
|
- // if err != nil {
|
|
|
- // return err
|
|
|
- // }
|
|
|
- // b.Excel.SetCellValue(b.SheetName, right1Cell, value)
|
|
|
- // return nil
|
|
|
- // }
|
|
|
-
|
|
|
- // !!isPdf
|
|
|
- // if b.IsPdf == "true" {
|
|
|
-
|
|
|
drawLeft := func(rowIndex int, value string) error {
|
|
|
//左边1
|
|
|
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)
|
|
|
}
|
|
|
|
|
|
- // !!isPdf
|
|
|
- // if b.IsPdf == "true" {
|
|
|
drawCol("A", "采购项目")
|
|
|
drawCol("B", "规格")
|
|
|
drawCol("C", "下单数量")
|
|
@@ -197,19 +158,6 @@ func (b *ProductBillExcel) drawTableTitle() error {
|
|
|
drawCol("F", "预算金额")
|
|
|
drawCol("G", "交货时间")
|
|
|
drawCol("H", "备注")
|
|
|
- // } else {
|
|
|
- // drawCol("A", "采购项目")
|
|
|
- // drawCol("B", "规格")
|
|
|
- // drawCol("C", "下单数量")
|
|
|
- // drawCol("D", "单位")
|
|
|
- // drawCol("E", "完成数量")
|
|
|
- // drawCol("F", "单价")
|
|
|
- // drawCol("G", "预算金额")
|
|
|
- // drawCol("H", "实际金额")
|
|
|
- // drawCol("I", "交货时间")
|
|
|
- // drawCol("J", "备注")
|
|
|
- // }
|
|
|
-
|
|
|
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", "I", "J"}
|
|
|
- // !!isPdf
|
|
|
- // if b.IsPdf == "true" {
|
|
|
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)
|
|
|
|
|
|
- // !!isPdf
|
|
|
- // if b.IsPdf == "true" {
|
|
|
DrawRow(b.Row, product.Name, product.Norm, orderCount, product.Unit, price, budgetAmount, deliveryTime, product.Remark)
|
|
|
- // } else {
|
|
|
- // DrawRow(b.Row, product.Name, product.Norm, orderCount, product.Unit, realCount, price, budgetAmount, realPrice, deliveryTime, product.Remark)
|
|
|
- // }
|
|
|
|
|
|
b.Row++
|
|
|
}
|
|
@@ -308,116 +257,6 @@ func (b *ProductBillExcel) drawTableFooter() error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-// func (b *ProductBillExcel) drawRemark() error {
|
|
|
-// // 填备注
|
|
|
-// b.Row++
|
|
|
-// remarkTitleCell := fmt.Sprintf("A%d", b.Row)
|
|
|
-// b.Excel.SetCellValue(b.SheetName, remarkTitleCell, "备注:")
|
|
|
-// b.Row++
|
|
|
-
|
|
|
-// remarkContentScell := fmt.Sprintf("A%d", b.Row)
|
|
|
-// // 预留五行备注内容
|
|
|
-// reg := regexp.MustCompile(`\n`)
|
|
|
-// remarkRowNum := len(reg.FindAllString(b.Content.Remark, -1)) + 1
|
|
|
-// b.Row += remarkRowNum
|
|
|
-// // remarkContentEcell := fmt.Sprintf("J%d", b.Row)
|
|
|
-// // // !!isPdf
|
|
|
-// // if b.IsPdf == "true" {
|
|
|
-// remarkContentEcell := fmt.Sprintf("H%d", b.Row)
|
|
|
-// // }
|
|
|
-// b.Excel.MergeCell(b.SheetName, remarkContentScell, remarkContentEcell)
|
|
|
-// b.Excel.SetCellValue(b.SheetName, remarkContentScell, b.Content.Remark)
|
|
|
-
|
|
|
-// // 签字位置
|
|
|
-// b.Row += 2
|
|
|
-// styleLeft, err := b.Excel.NewStyle(&excelize.Style{
|
|
|
-// Alignment: &excelize.Alignment{Horizontal: "left", Vertical: "center"},
|
|
|
-// Font: &excelize.Font{Size: 11}})
|
|
|
-// if err != nil {
|
|
|
-// return err
|
|
|
-// }
|
|
|
-// // var drawLeft = func(rowIndex int, value string) error {
|
|
|
-// // //左边1
|
|
|
-// // left1Cell := fmt.Sprintf("A%d", rowIndex)
|
|
|
-// // err := b.Excel.MergeCell(b.SheetName, left1Cell, fmt.Sprintf("E%d", rowIndex))
|
|
|
-// // if err != nil {
|
|
|
-// // return err
|
|
|
-// // }
|
|
|
-// // err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left1Cell, styleLeft)
|
|
|
-// // if err != nil {
|
|
|
-// // return err
|
|
|
-// // }
|
|
|
-// // b.Excel.SetCellValue(b.SheetName, left1Cell, value)
|
|
|
-// // return nil
|
|
|
-// // }
|
|
|
-
|
|
|
-// // var drawRight = func(rowIndex int, value string) error {
|
|
|
-// // right1Cell := fmt.Sprintf("F%d", rowIndex)
|
|
|
-// // err = b.Excel.MergeCell(b.SheetName, right1Cell, fmt.Sprintf("J%d", rowIndex))
|
|
|
-// // if err != nil {
|
|
|
-// // return err
|
|
|
-// // }
|
|
|
-// // err = b.Excel.SetCellStyle(b.SheetName, right1Cell, right1Cell, styleLeft)
|
|
|
-// // if err != nil {
|
|
|
-// // return err
|
|
|
-// // }
|
|
|
-// // b.Excel.SetCellValue(b.SheetName, right1Cell, value)
|
|
|
-// // return nil
|
|
|
-// // }
|
|
|
-
|
|
|
-// // !!isPdf
|
|
|
-// // if b.IsPdf == "true" {
|
|
|
-// drawLeft := func(rowIndex int, value string) error {
|
|
|
-// //左边1
|
|
|
-// left1Cell := fmt.Sprintf("A%d", rowIndex)
|
|
|
-// err := b.Excel.MergeCell(b.SheetName, left1Cell, fmt.Sprintf("E%d", rowIndex))
|
|
|
-// if err != nil {
|
|
|
-// return err
|
|
|
-// }
|
|
|
-// err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left1Cell, styleLeft)
|
|
|
-// if err != nil {
|
|
|
-// return err
|
|
|
-// }
|
|
|
-// b.Excel.SetCellValue(b.SheetName, left1Cell, value)
|
|
|
-// return nil
|
|
|
-// }
|
|
|
-
|
|
|
-// drawRight := func(rowIndex int, value string) error {
|
|
|
-// right1Cell := fmt.Sprintf("F%d", rowIndex)
|
|
|
-// err = b.Excel.MergeCell(b.SheetName, right1Cell, fmt.Sprintf("H%d", rowIndex))
|
|
|
-// if err != nil {
|
|
|
-// return err
|
|
|
-// }
|
|
|
-// err = b.Excel.SetCellStyle(b.SheetName, right1Cell, right1Cell, styleLeft)
|
|
|
-// if err != nil {
|
|
|
-// return err
|
|
|
-// }
|
|
|
-// b.Excel.SetCellValue(b.SheetName, right1Cell, value)
|
|
|
-// return nil
|
|
|
-// }
|
|
|
-// // }
|
|
|
-
|
|
|
-// //第一行
|
|
|
-// drawLeft(b.Row, "甲方:"+b.Title)
|
|
|
-// drawRight(b.Row, "乙方:"+b.Content.Supplier)
|
|
|
-// b.Excel.SetRowHeight(b.SheetName, b.Row, 21)
|
|
|
-
|
|
|
-// //第二行
|
|
|
-// drawLeft(b.Row+1, "联系人:")
|
|
|
-// timeformat := b.Content.CreateTime.Local().Format("2006年01月02号")
|
|
|
-// drawRight(b.Row+1, "联系人:")
|
|
|
-// b.Excel.SetRowHeight(b.SheetName, b.Row+1, 21)
|
|
|
-
|
|
|
-// //第三行
|
|
|
-// drawLeft(b.Row+2, "时间:"+timeformat)
|
|
|
-// drawRight(b.Row+2, "时间:"+timeformat)
|
|
|
-// b.Excel.SetRowHeight(b.SheetName, b.Row+2, 21)
|
|
|
-// b.Row += 2
|
|
|
-
|
|
|
-// return nil
|
|
|
-
|
|
|
-// }
|
|
|
-
|
|
|
func (b *ProductBillExcel) drawTableSignature() error {
|
|
|
b.Row += 2
|
|
|
// row := b.Row
|
|
@@ -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 := "H"
|
|
|
- // image1s := "I"
|
|
|
- // image2s := "K"
|
|
|
- // image1e := "J"
|
|
|
- // image2e := "L"
|
|
|
-
|
|
|
- // !!isPdf
|
|
|
- // if b.IsPdf == "true" {
|
|
|
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.drawRemark()
|
|
|
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},
|
|
|
})
|