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.

Tue Jan 03, 2017 1:51 pm

Hi,

I am trying to replace the contents of a bookmark and retain the original format using the following code (based on your example) but the formatting changes.

Section tempSection = doc.AddSection();
navigator.MoveToBookmark(placeHolder);

var paragraph = tempSection.AddParagraph();

// Populate paragraph content

ParagraphBase firstReplacementParagraph = tempSection.Paragraphs[0].Items.FirstItem as ParagraphBase;
ParagraphBase lastReplacementParagraph = tempSection.Paragraphs[tempSection.Paragraphs.Count - 1].Items.LastItem as ParagraphBase;

TextBodySelection selection = new TextBodySelection(firstReplacementParagraph, lastReplacementParagraph);
TextBodyPart part = new TextBodyPart(selection);
navigator.DeleteBookmarkContent(true);
navigator.ReplaceBookmarkContent(part);

doc.Sections.Remove(tempSection);

Is there a way I can preserve the formatting? There may be several paragraphs that are added at the bookmark location.

Thanks

S

[email protected]
 
Posts: 2
Joined: Tue Dec 13, 2016 2:47 pm

Wed Jan 04, 2017 7:25 am

Dear S,

Thanks for your inquiry.
Sorry that currently Spire.Doc doesn't support to keep original format of content in bookmark using that TextBodyPart method to replace the content in bookmark. But we have added that new feature into our schedule, once it is done, we will inform you soon.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Wed Jan 04, 2017 2:53 pm

That's great, thanks.

Stuart

[email protected]
 
Posts: 2
Joined: Tue Dec 13, 2016 2:47 pm

Wed Jan 25, 2017 6:22 am

Dear Stuart,

Thanks for waiting.
Now the new feature has been done, welcome to test Spire.Office Platinum (Hot Fix) Version:2.15.4.
Here is sample code for your reference.
Code: Select all
ReplaceBookmarkContent(TextBodyPart bodyPart, bool isKeepSourceFirstParaFormat, bool saveFormatting);

Looking forward to your feedback.

Thanks,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.Doc

cron