package wps import ( "log" "strings" "github.com/Esword618/unioffice/common" "github.com/Esword618/unioffice/document" "github.com/Esword618/unioffice/measurement" ) // 设置unidoc key // func init() { // // Make sure to load your metered License API key prior to using the library. // // If you need a key, you can sign up and create a free one at https://cloud.unidoc.io // err := license.SetMeteredKey(`4d568da2fb25ed2477068464ffde96b7e7fa091595e6af3610eb4aee1b539a24`) // if err != nil { // panic(err) // } // } // 文字替换 func Replacetext(r document.Run, src, ends string) { datas := r.Text() log.Println("匹配到的内容:", datas) r.ClearContent() r.AddText(strings.Replace(datas, src, ends, -1)) log.Println("替换后的内容:", strings.Replace(datas, src, ends, -1)) } // 插入图片 func Replaceimg(r document.Run, doc *document.Document, path_img string) { r.ClearContent() img1, err := common.ImageFromFile(path_img) if err != nil { log.Fatalf("unable to create image: %s", err) } img1ref, err := doc.AddImage(img1) if err != nil { log.Fatalf("unable to add image to document: %s", err) } anchored, _ := r.AddDrawingInline(img1ref) //在文档中插入图片 anchored.SetSize(img1ref.RelativeWidth(5.2*measurement.Inch), 5.2*measurement.Inch) log.Println("插入图片:", path_img) } // 插入图片应用系统 func Replaceimg_1(r document.Run, doc *document.Document, path_img string) { r.ClearContent() img1, err := common.ImageFromFile(path_img) if err != nil { log.Fatalf("unable to create image: %s", err) } img1ref, err := doc.AddImage(img1) if err != nil { log.Fatalf("unable to add image to document: %s", err) } anchored, _ := r.AddDrawingInline(img1ref) //在文档中插入图片 anchored.SetSize(5.75*measurement.Inch, 3.2*measurement.Inch) log.Println("插入图片:", path_img) }