|
@@ -3,6 +3,7 @@ package produce
|
|
|
import (
|
|
|
"fmt"
|
|
|
"log"
|
|
|
+ "strings"
|
|
|
"time"
|
|
|
|
|
|
"xgAutoTest/internal/global"
|
|
@@ -96,10 +97,10 @@ func Newword() *WordInfo {
|
|
|
doc: document.New(),
|
|
|
}
|
|
|
}
|
|
|
-func (wd *WordInfo) WriterTable(fileLocal string, tableName string, tableUpperPart TableUpperPart, SingleImage []byte) {
|
|
|
+func (wd *WordInfo) WriterTable(fileLocal string, tableUpperPart TableUpperPart, SingleImage []byte) {
|
|
|
//wd.doc = document.New()
|
|
|
// 写入表名
|
|
|
- wd.doc.AddParagraph().AddRun().AddText(tableName)
|
|
|
+ //wd.doc.AddParagraph().AddRun().AddText("tableName")
|
|
|
|
|
|
// 添加一个表格
|
|
|
table := wd.doc.AddTable()
|
|
@@ -126,16 +127,45 @@ func (wd *WordInfo) SaveWord(fileLocal string) {
|
|
|
|
|
|
func addRow(table *document.Table, col1, col2 string) {
|
|
|
row := table.AddRow()
|
|
|
- rowCell := row.AddCell()
|
|
|
- rowCell.Properties().SetWidthPercent(60)
|
|
|
- rowCell.AddParagraph().AddRun().AddText(col1)
|
|
|
- row.AddCell().AddParagraph().AddRun().AddText(col2)
|
|
|
+ rowCellLeft := row.AddCell()
|
|
|
+ rowCellLeft.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
|
|
|
+ rowCellLeft.Properties().SetWidthPercent(25)
|
|
|
+ rowCellLeft.AddParagraph().AddRun().AddText(col1)
|
|
|
+ rowCellRight := row.AddCell()
|
|
|
+ if col1 == "用例名称" {
|
|
|
+ rowCellLeft.Properties().SetShading(wml.ST_ShdSolid, color.RGB(128, 128, 128), color.RGB(128, 128, 128))
|
|
|
+ rowCellRight.Properties().SetShading(wml.ST_ShdSolid, color.RGB(128, 128, 128), color.RGB(128, 128, 128))
|
|
|
+ }
|
|
|
+ //rowCellRight.AddParagraph().AddRun().AddText(col2)
|
|
|
+ //将;分号识别为换行
|
|
|
+ startIndex := 0
|
|
|
+ for {
|
|
|
+ index := strings.Index(col2[startIndex:], ";")
|
|
|
+ if index == -1 {
|
|
|
+ break
|
|
|
+ }
|
|
|
+
|
|
|
+ // 找到了分号,执行相应操作
|
|
|
+ rowCellRight.AddParagraph().AddRun().AddText(col2[startIndex : startIndex+index+1])
|
|
|
+
|
|
|
+ // 更新起始索引,继续检索下一个分号
|
|
|
+ startIndex += index + 1
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理最后一个分号后的部分(如果有)
|
|
|
+ if startIndex < len(col2) {
|
|
|
+ rowCellRight.AddParagraph().AddRun().AddText(col2[startIndex:])
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
// 插入合并后的图片到表格内
|
|
|
func (wd *WordInfo) InsertSingleImage(table *document.Table, data []byte) {
|
|
|
row := table.AddRow()
|
|
|
- row.AddCell().AddParagraph().AddRun().AddText("测试结果截图")
|
|
|
+ rowCellLeft := row.AddCell()
|
|
|
+ //row.AddCell().Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
|
|
|
+ rowCellLeft.AddParagraph().AddRun().AddText("测试结果截图")
|
|
|
+ rowCellLeft.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
|
|
|
///row = table.AddRow()
|
|
|
ParagraphTemp := row.AddCell().AddParagraph()
|
|
|
|
|
@@ -152,7 +182,7 @@ func (wd *WordInfo) InsertSingleImage(table *document.Table, data []byte) {
|
|
|
if err != nil {
|
|
|
global.Logs.Fatalf("unable to doc.AddImage: %s", err)
|
|
|
}
|
|
|
- inlineDrawing.SetSize(100, 100) // 设置图像大小为 100x100 像素
|
|
|
+ inlineDrawing.SetSize(300, 400) // 设置图像大小为 100x100 像素
|
|
|
|
|
|
}
|
|
|
|