20250225_new
This commit is contained in:
parent
746bbbe4a2
commit
529fe27dce
6
main.go
6
main.go
@ -1,8 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"dt_automate/method"
|
|
||||||
"dt_automate/tool"
|
"dt_automate/tool"
|
||||||
|
"dt_automate/wps"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
@ -95,8 +95,8 @@ func main() {
|
|||||||
// method.HW_TSGZ() //截取态势感知的图片
|
// method.HW_TSGZ() //截取态势感知的图片
|
||||||
// //政务网区
|
// //政务网区
|
||||||
// method.ZWW_FW1() //截取防火墙的图片
|
// method.ZWW_FW1() //截取防火墙的图片
|
||||||
method.ZWW_TSGZ() //截取态势感知的图片
|
// method.ZWW_TSGZ() //截取态势感知的图片
|
||||||
// wps.Word()
|
wps.Word()
|
||||||
// wps.Damo()
|
// wps.Damo()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
BIN
simple.docx
BIN
simple.docx
Binary file not shown.
BIN
temp_save.docx
BIN
temp_save.docx
Binary file not shown.
109
wps/word.go
109
wps/word.go
@ -1,9 +1,9 @@
|
|||||||
package wps
|
package wps
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/unidoc/unioffice/common"
|
"github.com/unidoc/unioffice/common"
|
||||||
"github.com/unidoc/unioffice/common/license"
|
"github.com/unidoc/unioffice/common/license"
|
||||||
@ -45,19 +45,33 @@ func Word() {
|
|||||||
for _, p := range paragraphs {
|
for _, p := range paragraphs {
|
||||||
for _, r := range p.Runs() {
|
for _, r := range p.Runs() {
|
||||||
if strings.Contains(r.Text(), "{{DATE_A}}") {
|
if strings.Contains(r.Text(), "{{DATE_A}}") {
|
||||||
Replacetext(r, "{{DATE_A}}", "2025年02月25日")
|
Replacetext(r, "{{DATE_A}}", time.Date(2025, time.February, 25, 0, 0, 0, 0, time.Local).Format("2006年01月02日"))
|
||||||
} else if strings.Contains(r.Text(), "{{DATE_A}}") {
|
} else if strings.Contains(r.Text(), "{{HLW_FW_1}}") { //插入互联网防火墙图片
|
||||||
// r.ClearContent()
|
Replaceimg(r, doc, "img/hw_fw1.png")
|
||||||
|
} else if strings.Contains(r.Text(), "{{HLW_AFC2000_1}}") { //插入互联网流量清洗图片
|
||||||
|
Replaceimg(r, doc, "img/afc2000_1.png")
|
||||||
|
} else if strings.Contains(r.Text(), "{{HLW_AFC2000_2}}") { //插入互联网流量清洗图片
|
||||||
|
Replaceimg(r, doc, "img/afc2000_2.png")
|
||||||
|
} else if strings.Contains(r.Text(), "{{HLW_TSGZ}}") { //插入互联网态势感知图片
|
||||||
|
Replaceimg(r, doc, "img/hw_tsgz.png")
|
||||||
|
} else if strings.Contains(r.Text(), "{{HLW_BLJ}}") { //插入互联网堡垒机图片
|
||||||
|
// Replaceimg(r, doc, "img/hw_fw1.png")
|
||||||
|
} else if strings.Contains(r.Text(), "{{ZWW_FW_1}}") { //插入政务网防火墙图片
|
||||||
|
Replaceimg(r, doc, "img/zww_fw1.png")
|
||||||
|
} else if strings.Contains(r.Text(), "{{ZWW_TSGZ}}") { //插入政务网态势感知图片
|
||||||
|
Replaceimg(r, doc, "img/zww_tsgz.png")
|
||||||
|
} else if strings.Contains(r.Text(), "{{ZWW_BLJ}}") { //插入政务网堡垒机图片
|
||||||
|
// Replaceimg(r, doc, "img/hw_fw1.png")
|
||||||
} else {
|
} else {
|
||||||
// fmt.Println("not modifying", r.Text())
|
// log.Println("")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 遍历文档中的表格
|
// 遍历文档中的表格,替换{{bianliang}} 中的内容
|
||||||
for _, table := range doc.Tables() {
|
for _, table := range doc.Tables() {
|
||||||
for _, row := range table.Rows() {
|
for _, row := range table.Rows() {
|
||||||
for i, cell := range row.Cells() {
|
for _, cell := range row.Cells() {
|
||||||
var (
|
var (
|
||||||
b string
|
b string
|
||||||
p document.Paragraph
|
p document.Paragraph
|
||||||
@ -69,96 +83,45 @@ func Word() {
|
|||||||
}
|
}
|
||||||
// log.Println(k)
|
// log.Println(k)
|
||||||
}
|
}
|
||||||
log.Println(i)
|
// log.Println(i)
|
||||||
if strings.Contains(b, "{{DATE_B}}") {
|
if strings.Contains(b, "{{DATE_B}}") {
|
||||||
// log.Println(k)
|
log.Println("匹配到模板内容:", b)
|
||||||
for _, h := range cell.Paragraphs()[k].Runs() {
|
for _, h := range cell.Paragraphs()[k].Runs() {
|
||||||
h.ClearContent()
|
h.ClearContent()
|
||||||
}
|
}
|
||||||
cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
|
cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
|
||||||
cell.Paragraphs()[k].AddRun().AddText("2025年02月25日")
|
// log.Println(time.Date(2025, time.February, 25, 0, 0, 0, 0, time.Local).Format("2006年01月02日"))
|
||||||
|
cell.Paragraphs()[k].AddRun().AddText(time.Date(2025, time.February, 25, 0, 0, 0, 0, time.Local).Format("2006年01月02日"))
|
||||||
}
|
}
|
||||||
log.Println(b)
|
// log.Println(b)
|
||||||
b = ""
|
b = ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
doc.SaveToFile("simple.docx")
|
doc.SaveToFile("大同信创云平台安全运维日报" + time.Date(2025, time.February, 25, 0, 0, 0, 0, time.Local).Format("20060102") + ".docx")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 文字替换
|
// 文字替换
|
||||||
func Replacetext(r document.Run, src, ends string) {
|
func Replacetext(r document.Run, src, ends string) {
|
||||||
datas := r.Text()
|
datas := r.Text()
|
||||||
|
log.Println("匹配到的内容:", datas)
|
||||||
r.ClearContent()
|
r.ClearContent()
|
||||||
r.AddText(strings.Replace(datas, src, ends, -1))
|
r.AddText(strings.Replace(datas, src, ends, -1))
|
||||||
log.Println(strings.Replace(datas, src, ends, -1))
|
log.Println("替换后的内容:", strings.Replace(datas, src, ends, -1))
|
||||||
}
|
}
|
||||||
|
|
||||||
// func createParaRun(doc *document.Document, s string) document.Run {
|
// 插入图片
|
||||||
// para := doc.AddParagraph()
|
func Replaceimg(r document.Run, doc *document.Document, path_img string) {
|
||||||
// run := para.AddRun()
|
r.ClearContent()
|
||||||
// run.AddText(s)
|
img1, err := common.ImageFromFile("img/hw_fw1.png")
|
||||||
// return run
|
|
||||||
// }
|
|
||||||
|
|
||||||
var lorem = `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin lobortis, lectus dictum feugiat tempus, sem neque finibus enim, sed eleifend sem nunc ac diam. Vestibulum tempus sagittis elementum`
|
|
||||||
|
|
||||||
func Word_img() {
|
|
||||||
doc := document.New()
|
|
||||||
|
|
||||||
img1, err := common.ImageFromFile("gophercolor.png")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("unable to create image: %s", err)
|
log.Fatalf("unable to create image: %s", err)
|
||||||
}
|
}
|
||||||
img2data, err := ioutil.ReadFile("gophercolor.png")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("unable to read file: %s", err)
|
|
||||||
}
|
|
||||||
img2, err := common.ImageFromBytes(img2data)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("unable to create image: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
img1ref, err := doc.AddImage(img1)
|
img1ref, err := doc.AddImage(img1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("unable to add image to document: %s", err)
|
log.Fatalf("unable to add image to document: %s", err)
|
||||||
}
|
}
|
||||||
img2ref, err := doc.AddImage(img2)
|
anchored, _ := r.AddDrawingInline(img1ref) //在文档中插入图片
|
||||||
if err != nil {
|
anchored.SetSize(img1ref.RelativeWidth(5.2*measurement.Inch), 5.2*measurement.Inch)
|
||||||
log.Fatalf("unable to add image to document: %s", err)
|
log.Println("插入图片:", path_img)
|
||||||
}
|
|
||||||
|
|
||||||
para := doc.AddParagraph()
|
|
||||||
anchored, err := para.AddRun().AddDrawingAnchored(img1ref) //添加绘图锚定
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("unable to add anchored image: %s", err)
|
|
||||||
}
|
|
||||||
anchored.SetName("Gopher")
|
|
||||||
anchored.SetSize(2*measurement.Inch, 2*measurement.Inch)
|
|
||||||
anchored.SetOrigin(wml.WdST_RelFromHPage, wml.WdST_RelFromVTopMargin) //设置原点
|
|
||||||
anchored.SetHAlignment(wml.WdST_AlignHCenter) //设置校准
|
|
||||||
anchored.SetYOffset(3 * measurement.Inch) //设置偏移量
|
|
||||||
anchored.SetTextWrapSquare(wml.WdST_WrapTextBothSides) //设置文本环绕正方形
|
|
||||||
|
|
||||||
run := para.AddRun()
|
|
||||||
for i := 0; i < 16; i++ {
|
|
||||||
run.AddText(lorem)
|
|
||||||
|
|
||||||
// drop an inline image in
|
|
||||||
if i == 13 {
|
|
||||||
inl, err := run.AddDrawingInline(img1ref)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("unable to add inline image: %s", err)
|
|
||||||
}
|
|
||||||
inl.SetSize(1*measurement.Inch, 1*measurement.Inch)
|
|
||||||
}
|
|
||||||
if i == 15 {
|
|
||||||
inl, err := run.AddDrawingInline(img2ref)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("unable to add inline image: %s", err)
|
|
||||||
}
|
|
||||||
inl.SetSize(1*measurement.Inch, 1*measurement.Inch)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
doc.SaveToFile("image.docx")
|
|
||||||
}
|
}
|
||||||
|
BIN
大同信创云平台安全运维日报20250225.docx
Normal file
BIN
大同信创云平台安全运维日报20250225.docx
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user