You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm testing Word fields manipulation with uniOffice, but I'm not being able to load the fields from my documents. The "fill-out-form" example is working, but not my own examples.
Expected Behavior
I've created few test documents (see attachments), similar to "fill-out-form" example, with some form fields. They should be loaded, filled out with some fake content and saved back into a new .docx document.
Actual Behavior
The document is opened, no fields loaded, and saved document has no fields.
I get messages in console like this:
package main
import (
"flag"
"fmt"
"log"
"path/filepath"
"strings"
"github.com/unidoc/unioffice/document"
)
var source = flag.String("source", "", "Absolute path to the source document (.docx)")
func main() {
// Process input parameters
flag.Parse()
if source == nil || len(*source) <= 0 {
log.Fatal("You MUST provide a source document (.docx)")
}
sourcePath := filepath.Clean(*source)
baseDir := filepath.Dir(sourcePath)
filename := filepath.Base(sourcePath)
extension := filepath.Ext(filename)
extension = strings.ToLower(extension[1:len(extension)])
log.Println("Base dir:", baseDir)
log.Println("Filename:", filename)
log.Println("Extension:", extension)
if extension != "docx" {
log.Fatal("Only .docx document are allowed as source file")
}
// Open source document
doc, err := document.Open(sourcePath)
if err != nil {
log.Fatalf("Error opening source (%s): %v", sourcePath, err)
}
fmt.Println("Document", filename, "loaded")
// Get the list of all fields inside the document
// --- Copied from "unioffice example "fill-out-form" ---
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])
}
}
}
// Save resulting document
destFilename := fmt.Sprintf("%s-test.%s", filename[0:len(filename)-len(extension)-1], extension)
destination := filepath.Join(baseDir, destFilename)
doc.SaveToFile(destination)
fmt.Println("Result saved at:", destination)
}
Welcome! Thanks for posting your first issue. The way things work here is that while customer issues are prioritized,
other issues go into our backlog where they are assessed and fitted into the roadmap when suitable.
If you need to get this done, consider buying a license which also enables you to use it in your commercial products.
More information can be found on https://unidoc.io/
After some deep testing, I found that the library is working for "legacy fields" but not for "activeX fields".
I've created some more test documents based on "fill-out-form" and it is clear that only "legacy fields" are loaded.
Using LibreOffice I could never found a way to use "legacy fields". I could only add "fields" that at the end seems to be "activeX fields".
I've tried with Word (Office 365), and then I could find both form controls (legacy and activeX) and only then I could realize that there were 2 different form controls and that the library seems to work only for the first type.
Please, confirm if that's true, or if there's a way to make "uniOffice" work with "activeX form fields".
I'm testing Word fields manipulation with uniOffice, but I'm not being able to load the fields from my documents. The "fill-out-form" example is working, but not my own examples.
Expected Behavior
I've created few test documents (see attachments), similar to "fill-out-form" example, with some form fields. They should be loaded, filled out with some fake content and saved back into a new .docx document.
Actual Behavior
The document is opened, no fields loaded, and saved document has no fields.
I get messages in console like this:
or like these:
This is the example source code:
`
...
`
Example 1:
form2.docx
form2-test.docx
Example2:
Documento de prueba.docx
Documento de prueba-test.docx
Example 3:
TestForm1.docx
TestForm1-test.docx
The text was updated successfully, but these errors were encountered: