Replace text between two bookmarks

Technical support for Spire.Doc

Moderator: iceblue support

Replace text between two bookmarks

Postby shu » Tue Aug 16, 2011 7:44 pm

Hi

At the moment, I'm in a evaluation process and i have follwing two questions:

1. Replace text between two bookmarks:
I have two bookmarks in a document "BMStart" and "BMEnd". It's possibe to replace the text between this two bookmarks?

2. ContentControls Office 2010:
It's possible to handle this controls for example like textformfields?

Kind regards
shu
 
Posts: 3
Joined: Tue Aug 16, 2011 6:52 am

Re: Replace text between two bookmarks

Postby harry.support » Wed Aug 17, 2011 8:11 am

Hi,

Thanks for your inquiry.
For #1, you could:
Code: Select all
Document doc = new Document("your_word_document.doc");

//locate
Bookmark markStart = doc.Bookmarks["BMStart"];
Bookmark markEnd = doc.Bookmarks["BMEnd"];
Paragraph p1 = markStart.BookmarkEnd.OwnerParagraph;
int startIndex = p1.Items.IndexOf(markStart.BookmarkEnd);
int endIndex = p1.Items.IndexOf(markEnd.BookmarkStart);

//insert new content
TextRange newContent = new TextRange(doc);
newContent.Text = "(New Mark)";
p1.Items.Insert(endIndex, newContent);

//copy style
for (int i = startIndex + 1; i < endIndex; i++)
{
    if (p1.Items[i] is TextRange)
    {
        newContent.ApplyCharacterFormat((p1.Items[i] as TextRange).CharacterFormat);
        break;
    }
}

//remove old content
for (int i = startIndex + 1; i < endIndex; i++)
{
    p1.Items.RemoveAt(startIndex + 1);
}


For #2, please see the demo CreateFormField and FillFormField. They are under the folder $YOUR_INSTALATION_FOLDER$\Demos\CS\WinForms\10_FormField
Harry
Technical Support / Developer,
e-iceblue Support Team
User avatar
harry.support
 
Posts: 180
Joined: Mon Nov 08, 2010 3:11 pm

Re: Replace text between two bookmarks

Postby shu » Wed Aug 17, 2011 5:17 pm

Hi

Thanks for your answer. I'll try it.

About my second question:
I checked the sample, the textformfield an so on are not a problem.
But Word 2010 supports the new contentcontrols like RichText, PlainText, Picture , Combobox, DropDown-List an so on.

It's possible to access those controls - how? Are there also DocumentObjectTypes like DocumentObjectType.TextFormField for the TextFormField-Object?

Following Code shows the VBA-Code to Access a PlainText-ContentControl having the Tag "SampleTag".
Code: Select all
Sub ControlTest()
   Dim CC As ContentControl
   Set CC = ActiveDocument.SelectContentControlsByTag("SampleTag")
   CC.Range.Text = "Hello World"
End Sub


I hope you understand what I mean.
Kine Regards
You do not have the required permissions to view the files attached to this post.
shu
 
Posts: 3
Joined: Tue Aug 16, 2011 6:52 am

Re: Replace text between two bookmarks

Postby harry.support » Thu Aug 18, 2011 3:42 am

Hi,

Thanks for your new inquiry.
But we do not support these new contentcontrols of word2010 at present.
We are sorry for that.
Harry
Technical Support / Developer,
e-iceblue Support Team
User avatar
harry.support
 
Posts: 180
Joined: Mon Nov 08, 2010 3:11 pm


Return to Spire.Doc

Who is online

Users browsing this forum: No registered users and 0 guests

cron