代码拉取完成,页面将自动刷新
// Copyright 2017 Baliance. All rights reserved.
package main
import (
"fmt"
"log"
"gitee.com/jiewen/gooxml/document"
)
func main() {
doc, err := document.Open("form.docx")
if err != nil {
log.Fatalf("error opening form: %s", err)
}
// FindAllFields is a helper function that traverses the document
// identifying fields
fields := doc.FormFields()
fmt.Println("found", len(fields), "fields")
for _, fld := range fields {
fmt.Println("- Name:", fld.Name(), "Type:", fld.Type(), "Value:", fld.Value())
switch fld.Type() {
case document.FormFieldTypeText:
// you can directly set values on text fields
fld.SetValue("testing 123")
case document.FormFieldTypeCheckBox:
// you can check check boxes
fld.SetChecked(true)
case document.FormFieldTypeDropDown:
// and select items in a dropdown, here the value must be one of the
// fields possible values
lpv := len(fld.PossibleValues())
if lpv > 0 {
fld.SetValue(fld.PossibleValues()[lpv-1])
}
}
}
doc.SaveToFile("filled-form.docx")
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。