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

ReplaceText in Header/Footer broke in v 2.5.0 #457

Open
tlambert opened this issue Aug 22, 2023 · 3 comments
Open

ReplaceText in Header/Footer broke in v 2.5.0 #457

tlambert opened this issue Aug 22, 2023 · 3 comments

Comments

@tlambert
Copy link

Its adding the text but not removing the search value in the header/footer if I step over the error. Its fine in the body. Rolling back to 2.4.1 or 2.4.0 works fine.

        doc.ReplaceText(new StringReplaceTextOptions() { SearchValue = "%LoanNum%", NewValue = loan.LoanNum ?? "" });

header shows this if I step to next line in code:
Loan# %LoanNum%123456

at Xceed.Document.NET.Paragraph.InsertText(Int32 index, String value, Boolean trackChanges, Formatting formatting)
at Xceed.Document.NET.Paragraph.ReplaceTextCore(Match singleMatch, StringReplaceTextOptions replaceTextOptions)
at Xceed.Document.NET.Paragraph.ReplaceText(StringReplaceTextOptions replaceTextOptions)
at Xceed.Document.NET.Container.ReplaceTextCore(ReplaceTextOptionsBase replaceTextOptions)
at Xceed.Document.NET.Document.ReplaceText(StringReplaceTextOptions replaceTextOptions)
...

@XceedBoucherS
Copy link
Collaborator

Hello,

I tried a simle sample with DocX v2.5.0 from NuGet, like this:

var doc = DocX.Load( "test.docx" );
doc.ReplaceText( new StringReplaceTextOptions() { SearchValue = "%LoanNum%", NewValue = "123" } );
doc.SaveAs( "result.docx" );

in the "test.docx",
the header contains:
"In the header %LoanNum% is not important."
and the body contains:
"In the Body %LoanNum% is important."

As expeced, the resulting "result.docx" file shows:
in the header:
"In the header 123 is not important."
and in the body:
"In the Body 123 is important."

Could it be related to your "loan.LoanNum" variable ?

Thanks

@tlambert
Copy link
Author

tlambert commented Aug 23, 2023 via email

@XceedBoucherS
Copy link
Collaborator

Hi,
I am not able to reproduce the issue (you will find my sample docx in attachment), but with a section break, I have a NullRefException.
test.docx

This will be fixed in the next release (v2.6).

Thank you

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

2 participants