Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Thu Jul 01, 2021 5:29 am

Hello,
is there a way to update fields and save them as docx ??
At the moment it looks like I'm loading a document and replacing the fields. If I set Document.isUpdateFields = true and save it as pdf or xps, then the data will be displayed.
If I save it as docx ist doesnt work.

Best regards
Dirk

Yerodin84
 
Posts: 13
Joined: Thu May 27, 2021 1:39 pm

Thu Jul 01, 2021 6:25 am

Hello Dirk,

Thanks for your inquiry.
I simulated a docx file and update fields and then save it as docx with the latest Spire.Doc Pack(hot fix) Version:9.6.10, but I did not reproduce your issue. If you are using an older version, please download the latest version and try it again.
If the issue still occurs after trying, to help us investigate further, please provide your input file and your complete code. You could send them to us (support@e-iceblue.com) via email. Thanks in advance.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Thu Jul 01, 2021 11:06 am

Hello Dirk,

Thanks for your sharing via email.
I checked our records and found that you previously reported a similar issue (SPIREDOC-6124). My colleague Andy has provided you the following solution. However, I notice that your code does not use this solution, so I suggest you try this code to see if the issue occurs.
Code: Select all
        private static Document SetInhalt(Document doc)
        {
            const string Pattern = @"\{+(\s?)+(.*?)+(\s?)+\}";
            const string Patter = @"""[^""]*""";
            var docVarPattern = new Regex(Pattern);
            var docVarNamePattern = new Regex(Patter);

            var selections = doc.FindAllPattern(docVarPattern);
            foreach (var selection in selections)
            {
                var name = ExtractName(docVarNamePattern.Match(selection.SelectedText).Value);
                var range = selection.GetAsOneRange();
                var index = range.OwnerParagraph.ChildObjects.IndexOf(range);
                Field field = new Field(doc);
                field.Type = FieldType.FieldAdvance;
                field.Code = " DOCVARIABLE " + name + " ";
                range.OwnerParagraph.ChildObjects.Insert(index++, field);
                FieldMark fm = new FieldMark(doc, FieldMarkType.FieldSeparator);
                range.OwnerParagraph.ChildObjects.Insert(index++, fm);
                FieldMark endFM = new FieldMark(doc, FieldMarkType.FieldEnd);
                field.End = endFM;
                range.OwnerParagraph.ChildObjects.Insert(index++, endFM);
                range.OwnerParagraph.ChildObjects.Remove(range);
            }
            return doc;
        }


If the issue persists after trying, we cannot directly run your code due to many custom methods in your code, please provide your runnable project to help us investigate further.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Thu Jul 01, 2021 3:43 pm

Hello,
I'm so stupid.

The Problem was my View in Word. I had the View to see Fields and not the Values. So i thought it wasn't updated.

Thx for all.

Sincerly
Dirk

Yerodin84
 
Posts: 13
Joined: Thu May 27, 2021 1:39 pm

Fri Jul 02, 2021 1:29 am

Hello Dirk,

It doesn’t matter.
If you need any other help, just feel free to let us know. We are always here to help.
Have a nice day!

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Return to Spire.Doc