2025-02-26 23:15:11 +08:00
|
|
|
package wps
|
|
|
|
|
|
|
|
import (
|
|
|
|
"dt_automate/tool"
|
|
|
|
"log"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/Esword618/unioffice/document"
|
|
|
|
)
|
|
|
|
|
|
|
|
func HW_SYS_Word() {
|
|
|
|
doc, err := document.Open("temp/hlw_temp_cloude.docx")
|
|
|
|
if err != nil {
|
|
|
|
log.Panic("打开文件失败", err)
|
|
|
|
}
|
|
|
|
// defer doc.Close()
|
|
|
|
// 填充模板中的变量
|
|
|
|
paragraphs := []document.Paragraph{}
|
|
|
|
for _, p := range doc.Paragraphs() {
|
|
|
|
paragraphs = append(paragraphs, p)
|
|
|
|
}
|
2025-03-14 18:20:23 +08:00
|
|
|
//此示例文档使用了不常见的结构化文档标记
|
|
|
|
//文档模板中的除外。通常情况下,您只需迭代
|
|
|
|
//文档的段落。
|
2025-02-26 23:15:11 +08:00
|
|
|
for _, sdt := range doc.StructuredDocumentTags() {
|
|
|
|
for _, p := range sdt.Paragraphs() {
|
|
|
|
paragraphs = append(paragraphs, p)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.Println("开始生成运维平台互联网区模板")
|
|
|
|
for _, p := range paragraphs {
|
|
|
|
for _, r := range p.Runs() {
|
|
|
|
if strings.Contains(r.Text(), "{{HW_DTCLOUD_MAN}}") {
|
|
|
|
Replaceimg_1(r, doc, "img/hw_dtcloud_man.png")
|
|
|
|
} else if strings.Contains(r.Text(), "{{HW_DTCLOUD_01}}") {
|
|
|
|
Replaceimg_1(r, doc, "img/hw_dtcloud_01.png")
|
|
|
|
} else if strings.Contains(r.Text(), "{{HW_DTCLOUD_02}}") {
|
|
|
|
Replaceimg_1(r, doc, "img/hw_dtcloud_02.png")
|
|
|
|
} else if strings.Contains(r.Text(), "{{HW_DTCLOUD_03}}") {
|
|
|
|
Replaceimg_1(r, doc, "img/hw_dtcloud_03.png")
|
|
|
|
} else if strings.Contains(r.Text(), "{{HW_DTCLOUD_04}}") {
|
|
|
|
Replaceimg_1(r, doc, "img/hw_dtcloud_04.png")
|
|
|
|
} else if strings.Contains(r.Text(), "{{HW_DTCLOUD_05}}") {
|
|
|
|
Replaceimg_1(r, doc, "img/hw_dtcloud_05.png")
|
|
|
|
} else if strings.Contains(r.Text(), "{{HW_DTCLOUD_06}}") {
|
|
|
|
Replaceimg_1(r, doc, "img/hw_dtcloud_06.png")
|
|
|
|
} else if strings.Contains(r.Text(), "{{HW_DTCLOUD_07}}") {
|
|
|
|
Replaceimg_1(r, doc, "img/hw_dtcloud_07.png")
|
|
|
|
} else if strings.Contains(r.Text(), "{{HW_DTCLOUD_08}}") {
|
|
|
|
Replaceimg_1(r, doc, "img/hw_dtcloud_08.png")
|
|
|
|
} else {
|
|
|
|
// log.Println(r.Text())
|
|
|
|
// log.Println("")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 遍历文档中的表格,替换{{bianliang}} 中的内容
|
|
|
|
// for _, table := range doc.Tables() {
|
|
|
|
// for _, row := range table.Rows() {
|
|
|
|
// for _, cell := range row.Cells() {
|
|
|
|
// var (
|
|
|
|
// b string
|
|
|
|
// p document.Paragraph
|
|
|
|
// k int
|
|
|
|
// )
|
|
|
|
// for k, p = range cell.Paragraphs() {
|
|
|
|
// for _, a := range p.Runs() {
|
|
|
|
// b += a.Text()
|
|
|
|
// }
|
|
|
|
// // log.Println(k)
|
|
|
|
// }
|
|
|
|
// // log.Println(i)
|
|
|
|
// if strings.Contains(b, "{{DATE_B}}") {
|
|
|
|
// log.Println("匹配到模板内容:", b)
|
|
|
|
// for _, h := range cell.Paragraphs()[k].Runs() {
|
|
|
|
// h.ClearContent()
|
|
|
|
// }
|
|
|
|
// cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
|
|
|
|
// // log.Println(time.Date(2025, time.February, 25, 0, 0, 0, 0, time.Local).Format("2006年01月02日"))
|
|
|
|
// cell.Paragraphs()[k].AddRun().AddText(time.Unix(tool.Timestamp("second"), 0).Format("2006年01月02日"))
|
|
|
|
// }
|
|
|
|
// // log.Println(b)
|
|
|
|
// b = ""
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
doc.SaveToFile("大同信创云5.2.0 互联网区-" + time.Unix(tool.Timestamp("second"), 0).Format("2006年01月02日") + "巡检报告.docx")
|
|
|
|
}
|
|
|
|
func ZWW_SYS_Word() {
|
|
|
|
doc, err := document.Open("temp/zww_temp_cloude.docx")
|
|
|
|
if err != nil {
|
|
|
|
log.Panic("打开文件失败", err)
|
|
|
|
}
|
|
|
|
// defer doc.Close()
|
|
|
|
// 填充模板中的变量
|
|
|
|
paragraphs := []document.Paragraph{}
|
|
|
|
for _, p := range doc.Paragraphs() {
|
|
|
|
paragraphs = append(paragraphs, p)
|
|
|
|
}
|
|
|
|
// This sample document uses structured document tags, which are not common
|
|
|
|
// except for in document templates. Normally you can just iterate over the
|
|
|
|
// document's paragraphs.
|
|
|
|
for _, sdt := range doc.StructuredDocumentTags() {
|
|
|
|
for _, p := range sdt.Paragraphs() {
|
|
|
|
paragraphs = append(paragraphs, p)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.Println("开始生成运维平台政务网区模板")
|
|
|
|
for _, p := range paragraphs {
|
|
|
|
for _, r := range p.Runs() {
|
|
|
|
if strings.Contains(r.Text(), "{{ZWW_DTCLOUD_MAN}}") {
|
|
|
|
Replaceimg_1(r, doc, "img/zww_dtcloud_man.png")
|
|
|
|
} else if strings.Contains(r.Text(), "{{ZWW_DTCLOUD_01}}") {
|
|
|
|
Replaceimg_1(r, doc, "img/zww_dtcloud_01.png")
|
|
|
|
} else if strings.Contains(r.Text(), "{{ZWW_DTCLOUD_02}}") {
|
|
|
|
Replaceimg_1(r, doc, "img/zww_dtcloud_02.png")
|
|
|
|
} else if strings.Contains(r.Text(), "{{ZWW_DTCLOUD_03}}") {
|
|
|
|
Replaceimg_1(r, doc, "img/zww_dtcloud_03.png")
|
|
|
|
} else if strings.Contains(r.Text(), "{{ZWW_DTCLOUD_04}}") {
|
|
|
|
Replaceimg_1(r, doc, "img/zww_dtcloud_04.png")
|
|
|
|
} else if strings.Contains(r.Text(), "{{ZWW_DTCLOUD_05}}") {
|
|
|
|
Replaceimg_1(r, doc, "img/zww_dtcloud_05.png")
|
|
|
|
} else if strings.Contains(r.Text(), "{{ZWW_DTCLOUD_06}}") {
|
|
|
|
Replaceimg_1(r, doc, "img/zww_dtcloud_06.png")
|
|
|
|
} else if strings.Contains(r.Text(), "{{ZWW_DTCLOUD_07}}") {
|
|
|
|
Replaceimg_1(r, doc, "img/zww_dtcloud_07.png")
|
|
|
|
} else if strings.Contains(r.Text(), "{{ZWW_DTCLOUD_08}}") {
|
|
|
|
Replaceimg_1(r, doc, "img/zww_dtcloud_08.png")
|
|
|
|
} else {
|
|
|
|
// log.Println(r.Text())
|
|
|
|
// log.Println("")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 遍历文档中的表格,替换{{bianliang}} 中的内容
|
|
|
|
// for _, table := range doc.Tables() {
|
|
|
|
// for _, row := range table.Rows() {
|
|
|
|
// for _, cell := range row.Cells() {
|
|
|
|
// var (
|
|
|
|
// b string
|
|
|
|
// p document.Paragraph
|
|
|
|
// k int
|
|
|
|
// )
|
|
|
|
// for k, p = range cell.Paragraphs() {
|
|
|
|
// for _, a := range p.Runs() {
|
|
|
|
// b += a.Text()
|
|
|
|
// }
|
|
|
|
// // log.Println(k)
|
|
|
|
// }
|
|
|
|
// // log.Println(i)
|
|
|
|
// if strings.Contains(b, "{{DATE_B}}") {
|
|
|
|
// log.Println("匹配到模板内容:", b)
|
|
|
|
// for _, h := range cell.Paragraphs()[k].Runs() {
|
|
|
|
// h.ClearContent()
|
|
|
|
// }
|
|
|
|
// cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
|
|
|
|
// // log.Println(time.Date(2025, time.February, 25, 0, 0, 0, 0, time.Local).Format("2006年01月02日"))
|
|
|
|
// cell.Paragraphs()[k].AddRun().AddText(time.Unix(tool.Timestamp("second"), 0).Format("2006年01月02日"))
|
|
|
|
// }
|
|
|
|
// // log.Println(b)
|
|
|
|
// b = ""
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
doc.SaveToFile("大同信创云5.2.0 政务网区-" + time.Unix(tool.Timestamp("second"), 0).Format("2006年01月02日") + "巡检报告.docx")
|
|
|
|
}
|