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

Using run.AddField(document.FieldNumberOfPages) for footer produces "document contains fields that may refer to other files" prompt #171

Closed
kkesley opened this issue Mar 29, 2018 · 3 comments

Comments

@kkesley
Copy link

kkesley commented Mar 29, 2018

Hi, I'm trying to add page numbers to my document in the footer using the sample example provided. The document was created successfully but there's a prompt of 'This document contains fields that may refer to other files. Do you want to update the fields in this document?'

The content of the document is correct though even though I click No for the prompt

Here's my code for the footer

doc := document.New()
ftr := doc.AddFooter()
para := ftr.AddParagraph()
run := para.AddRun()
run.AddText("Test")
run.AddTab()
run.AddTab()
run.AddField(document.FieldCurrentPage)
run.AddText(" of ")
run.AddField(document.FieldNumberOfPages)
doc.BodySection().SetFooter(ftr, wml.ST_HdrFtrDefault)
@kkesley kkesley changed the title Using run.AddField(document.FieldNumberOfPages) for footer produces document contains fields that may refer to other files prompt Using run.AddField(document.FieldNumberOfPages) for footer produces "document contains fields that may refer to other files" prompt Mar 29, 2018
@tbaliance
Copy link
Contributor

@kendrickkesley This is because of the dirty flag in:

func (r Run) AddFieldWithFormatting(code string, fmt string) {
	ic := r.newIC()
	ic.FldChar = wml.NewCT_FldChar()
	ic.FldChar.FldCharTypeAttr = wml.ST_FldCharTypeBegin
	ic.FldChar.DirtyAttr = &sharedTypes.ST_OnOff{}
	ic.FldChar.DirtyAttr.Bool = gooxml.Bool(true)

I added this originally as the fields I was using (e.g. TOC) required the update to generate the content, otherwise the table of contents would be blank. It looks like in your case, it's not absolutely needed.

I'm not sure of the best way to fix this, either a flag to indicate if the field should be marked as dirty or a separate method. I'll look into it, but if you need a quick fix setting DirtyAttr to nil through the X() method should work.

tbaliance added a commit that referenced this issue Mar 31, 2018
@kkesley
Copy link
Author

kkesley commented Apr 5, 2018

Thanks! @tbaliance btw I'm updating the library with dep ensure -update baliance.com/gooxml but it still uses AddFieldWithFormatting(code string, fmt string). but if I use go get, it's picking the right version. do you know why it happens?

@tzneal
Copy link

tzneal commented Apr 5, 2018

@kendrickkesley Yeah, I didn't tag a new release which is what dep uses. I'll tag one now.

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

No branches or pull requests

3 participants