DocX icon indicating copy to clipboard operation
DocX copied to clipboard

ReplaceText in Header/Footer broke in v 2.5.0

Open tlambert opened this issue 2 years ago • 3 comments

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) ...

tlambert avatar Aug 22 '23 15:08 tlambert

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

XceedBoucherS avatar Aug 23 '23 12:08 XceedBoucherS

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: @.***>

tlambert avatar Aug 23 '23 13:08 tlambert

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

XceedBoucherS avatar Aug 24 '23 11:08 XceedBoucherS