Quellcode durchsuchen

修改word设置

GTong vor 1 Jahr
Ursprung
Commit
fcbaab3251
3 geänderte Dateien mit 60 neuen und 29 gelöschten Zeilen
  1. 12 12
      file/test.txt
  2. 10 9
      internal/auto/auto.go
  3. 38 8
      internal/produce/word.go

+ 12 - 12
file/test.txt

@@ -11,28 +11,28 @@ password = SYSDBA
 预置条件 = "数据库集群运行正常"
 测试程序 = "虚谷数据库管理系统(XGDBMS V11.0);虚谷数据库控制台工具(xgconsole V1)"
 测试步骤 = """
---支持数值类型
+--支持数值类型;
 create table  IF NOT EXISTS  t1(a int,b bigint,c float,d double,e tinyint,f smallint,g numeric(5,2));
 insert into t1 values(1,100,123456,123456,12,123,123.12);
 select * from t1;
---删除表
+--删除表;
 drop table if EXISTS   t1;
---支持字符类型
+--支持字符类型;
 create table  IF NOT EXISTS  t2(a char(20),b varchar,c clob);
 insert into t2 values('a','ab','abc');
 select * from t2;
 drop table if  EXISTS  t2;
---支持日期类型
+--支持日期类型;
 create table IF NOT EXISTS  t4(a date,b datetime,c datetime with time zone,d time,e time with time zone);
 insert into t4 values('2020-01-01','2021-01-01 10:10:10.111','2021-01-01 10:10:10.111 +8:00','10:10:10.111', '10:10:10.111 +8:00');
 select * from t4;
---删除表
+--删除表;
 drop table if  EXISTS  t4;
---创建表,表列类型为布尔类型
+--创建表,表列类型为布尔类型;
 create table t5(a boolean);
 insert into t5 values('true')('false');
 select * from t5;
---删除表
+--删除表;
 drop table if  EXISTS  t5;
 """
 
@@ -41,9 +41,9 @@ drop table if  EXISTS  t5;
 预置条件 = "数据库安装部署完毕,使用xgconsole连接数据库成功,管理器工具连接数据库成功"
 测试程序 = "虚谷数据库控制台工具(xgconsole V1)"
 测试步骤 = """
-    --删除测试表
+    --删除测试表;
     DROP TABLE IF EXISTS INTERVAL_TABLE; 
-    --创建表,表列类型时间间隔
+    --创建表,表列类型时间间隔;
    CREATE TABLE INTERVAL_TABLE(
     A INTERVAL YEAR,
     B INTERVAL MONTH,
@@ -58,7 +58,7 @@ drop table if  EXISTS  t5;
     K INTERVAL HOUR TO MINUTE,
     L INTERVAL HOUR TO SECOND,
     M INTERVAL MINUTE TO SECOND);
-    --插入数据
+    --插入数据;
     INSERT INTO INTERVAL_TABLE VALUES(
     '1',
     '2',
@@ -73,9 +73,9 @@ drop table if  EXISTS  t5;
     '10:10',
     '10:10:10',
     '10:10'); 
-    --查询表数据
+    --查询表数据;
     SELECT * FROM INTERVAL_TABLE;
-    --删除表
+    --删除表;
     drop table INTERVAL_TABLE;
 """
 

+ 10 - 9
internal/auto/auto.go

@@ -76,21 +76,21 @@ func AutoRun(config config.ConfigInfo) {
 		var sql string
 		for partTestStepScanner.Scan() {
 			partLine := strings.ToLower(strings.TrimSpace(partTestStepScanner.Text()))
-			fmt.Printf("partLine: %s\n", partLine)
+			//fmt.Printf("partLine: %s\n", partLine)
 
 			switch {
 			//sql注释--
 			case strings.HasPrefix(partLine, "--"):
-				fmt.Println("带有--key")
+				//fmt.Println("带有--key")
 				sql = strings.TrimSpace(strings.TrimPrefix(partLine, "--"))
 				texts += sql
 				texts += "\n"
 				texts += "\n"
 				sql = ""
-				//fmt.Printf("带有--key: %s\n", key)
+
 			//sql语句
 			case strings.Contains(partLine, ";"):
-				fmt.Println("带有;key")
+				//fmt.Println("带有;key")
 				//fmt.Printf("不带有--sql: %s\n", partLine)
 				sql += strings.TrimSpace(partLine[:strings.Index(partLine, ";")+1])
 				//fmt.Printf("sql TrimSpace: %s\n", sql)
@@ -99,7 +99,7 @@ func AutoRun(config config.ConfigInfo) {
 				isQueryOrInsert(db, sql, &tableUpperPartTemp)
 				sql = ""
 			default:
-				fmt.Println("继续读取key")
+				//	fmt.Println("继续读取key")
 				sql += strings.TrimSpace(partLine)
 				texts += sql
 				texts += "\n"
@@ -118,10 +118,10 @@ func AutoRun(config config.ConfigInfo) {
 
 	}
 
-	for i := range tableUpperParts1 {
-		fmt.Printf("tableUpperParts1内有 %v 条数据\n", i+1)
+	// for i := range tableUpperParts1 {
+	// 	fmt.Printf("tableUpperParts1内有 %v 条数据\n", i+1)
 
-	}
+	// }
 	//生成word
 	generateWord(tableUpperParts1)
 }
@@ -218,7 +218,8 @@ func generateWord(tableUpperParts1 []produce.TableUpperPart) {
 		if err != nil {
 			panic(err)
 		}
-		wd.WriterTable(global.FileLocal, "sad", tableUpperPart, mergedImage)
+
+		wd.WriterTable(global.FileLocal, tableUpperPart, mergedImage)
 
 		//保存图片
 		timeNow := time.Now().Format("2006-01-02 15:04:05.00000")

+ 38 - 8
internal/produce/word.go

@@ -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 像素
 
 }