DocX
DocX copied to clipboard
ReplaceText in Header/Footer broke in v 2.5.0
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) ...
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
Its with a section break - 1st page has a different header/footer than the rest of the document. It does work fine with one header/footer though.
On Wed, Aug 23, 2023 at 8:23 AM XceedBoucherS @.***> wrote:
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
— Reply to this email directly, view it on GitHub https://github.com/xceedsoftware/DocX/issues/457#issuecomment-1689867229, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAMZBZGNSBFTPP6IMCWKKRLXWXY4RANCNFSM6AAAAAA32DQPBI . You are receiving this because you authored the thread.Message ID: @.***>
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