EvotecIT / OfficeIMO

Fast and easy to use cross-platform .NET library that creates or modifies Microsoft Word (DocX) and later also Excel (XLSX) files without installing any software. Library is based on Open XML SDK
MIT License
279 stars 49 forks source link

Update fields on open has no effect #118

Closed kristofferjalen closed 1 year ago

kristofferjalen commented 1 year ago

If I add fields to a document:

.AddField(WordFieldType.Page)
.AddField(WordFieldType.NumPages)

then Word shows a dialog:

"This document contains fields that may refer to other files. Do you want to update the fields in this document"

Is there any way to avoid this dialog? I have tried using property UpdateFieldsOnOpen, but there was no difference:

document.Settings.UpdateFieldsOnOpen = true;
PrzemyslawKlys commented 1 year ago

This is how the fields work, as far as I understand. It's the same with TOC. You can create XML entries, but to get them updated, you force Word to refresh them on open. Isn't what you would expect?

kristofferjalen commented 1 year ago

When I insert a page number in Microsoft Word, I don't get that dialog. So the user does not expect such a dialog.

PrzemyslawKlys commented 1 year ago

There is a difference between the standard page number which we have available in headers/footers (probably would require some work to get it "anywhere") that is inserted as stdBlock

var pageNumber = document.Header.Default.AddPageNumber(WordPageNumberStyle.PlainNumber);

image

And using Fields:

document.AddField(WordFieldType.NumPages);

image

1st one doesn't force Word to do anything, the other one does (regardless if you have UpdateFields on or don't have nothing added) triggers word to do something. Maybe being inside StdBlocks impacts how it's parsed or maybe the way it's added. Surely there's a difference.

kristofferjalen commented 1 year ago

Oh! Thanks! I had missed the standard page number. No need to do anything then :) Thanks again!