Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Word Fields not loaded #370

Open
crostagnol opened this issue Feb 4, 2020 · 2 comments
Open

Word Fields not loaded #370

crostagnol opened this issue Feb 4, 2020 · 2 comments

Comments

@crostagnol
Copy link

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:

unsupported relationship type: http://schemas.openxmlformats.org/officeDocument/2006/relationships/glossaryDocument tgt: word/glossary/document.xml

or like these:

2020/02/04 09:19:00 skipping unsupported element on CT_Object {urn:schemas-microsoft-com:vml shapetype}
2020/02/04 09:19:00 skipping unsupported element on CT_Object {urn:schemas-microsoft-com:vml shape}
2020/02/04 09:19:00 skipping unsupported element on CT_Object {urn:schemas-microsoft-com:vml shape}
2020/02/04 09:19:00 skipping unsupported element on CT_Object {urn:schemas-microsoft-com:vml shape}
2020/02/04 09:19:00 unsupported relationship type: http://schemas.openxmlformats.org/officeDocument/2006/relationships/control tgt: word/activeX/activeX1.xml
2020/02/04 09:19:00 unsupported relationship type: http://schemas.openxmlformats.org/officeDocument/2006/relationships/control tgt: word/activeX/activeX2.xml
2020/02/04 09:19:00 unsupported relationship type: http://schemas.openxmlformats.org/officeDocument/2006/relationships/control tgt: word/activeX/activeX3.xml

This is the example source code:

`
...

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)
}

`

Example 1:

form2.docx
form2-test.docx

Example2:

Documento de prueba.docx
Documento de prueba-test.docx

Example 3:

TestForm1.docx
TestForm1-test.docx

@github-actions
Copy link

github-actions bot commented Feb 4, 2020

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/

@crostagnol
Copy link
Author

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.

Example 4 --- only legacy fields:

Word document:
formLegacy1.docx

Open XML document:
formLegacy2.docx

Example 5 --- legacy and activeX fields:

Word document:
formActiveX1.docx

Open XML document:
formActiveX2.docx

Comments:

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".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants