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.

Mon Aug 05, 2024 10:18 am

We are evaluating the porting of desktop .net application that use Microsoft Word COM api to Spire.Doc.

This application use the Word.Range object , Word.Range.Select() method and Word.Application.Selection property.

In Spire.Doc are there functional equivalent object method and properties ?
In such case wich are ?

Hope that it exists, thanks for all response.

banca05156
 
Posts: 4
Joined: Mon Aug 05, 2024 10:00 am

Tue Aug 06, 2024 6:50 am

Hi,

Thanks for your interests in our Spire.Doc. I guess you want to manipulate textrange. You can refer to some tutorials of our product.
https://www.e-iceblue.com/Tutorials/Spire.Doc/Spire.Doc-Program-Guide/NET-Word-Find-and-Highlight-Text-in-Word-with-C-VB.NET.html
https://www.e-iceblue.com/Tutorials/Spire.Doc/Spire.Doc-Program-Guide/Text/C-add-new-text-strings-after-the-searched-text-string-in-word-document.html

The following link can learn more features of our product:
https://www.e-iceblue.com/Tutorials/Spire.Doc/Spire.Doc-Program-Guide/Spire.Doc-Program-Guide-Content.html

If there is still any question when you testing, please provide us with your testing documentation and expected results, you can upload here or send them to us via email(support@e-iceblue.com),then we can make the sample demo for you.

Sincerely,
Amin
E-iceblue support team
User avatar

Amin.Gan
 
Posts: 164
Joined: Mon Jul 15, 2024 5:40 am

Tue Aug 06, 2024 8:50 am

Amin more thanks.

The example in the tutorial show the use of range over a specific words coded in the program.
In my case I have some placeholder and the range can cover arbithrary words on contiguos paragraph between the placeholders.

For example with Microsoft COM after identify <STARTTAG> and <ENDTAG> ( in the following example ) I can build a range that cover all within the tags without the program need to know the content within tags.

EXAMPLE
"""
Thanks for your interests in our Spire.Doc. <STARTTAG>I guess you want to manipulate textrange.
You can refer to some tutorials of our product.

Please provide us with your testing <ENDTAG>documentation and expected results, """

With Spire.doc for example how can do this for delete the content of the range without need to iterate over word or paragraph ?

banca05156
 
Posts: 4
Joined: Mon Aug 05, 2024 10:00 am

Wed Aug 07, 2024 7:44 am

Hello,

Thanks for your reply.
Our product also supports matching the placeholders by regex. For your situation, you can refer to the following sample code to change the placeholders text, and I attached my input document and output document for your reference. If you have any other questions when testing your document, please provide us with it for turther investigation. You can upload here or send it to us via email(support@e-iceblue.com ). Thank you in advance.

Code: Select all
             Document doc = new Document();
            doc.LoadFromFile("in.docx");
            //Use regular expressions to match
            Regex regex = new Regex("<([^>]+)>");
            TextSelection[] text = doc.FindAllPattern(regex);
            //Loop over all matched text and remove it
            foreach (TextSelection seletion in text)
            {
                seletion.GetAsOneRange().Text = "";
            }
            doc.SaveToFile("out.docx", FileFormat.Docx);


Sincerely,
Amin
E-iceblue support team
User avatar

Amin.Gan
 
Posts: 164
Joined: Mon Jul 15, 2024 5:40 am

Wed Aug 07, 2024 9:59 am

Hello and thanks again.

Excuse me for bad explanation of one of the needs.

In addiction to delete the content of the tag ( that is the most simple action), one of the need is to delete all between the tags.

And this ALL can include all arbitrary elements such as paragraph, word, table, pictures etc.

banca05156
 
Posts: 4
Joined: Mon Aug 05, 2024 10:00 am

Thu Aug 08, 2024 10:11 am

Hello,

Thanks for your more details.Combined with your needs, I adjusted my testing document and code. You can check again. If there is still any issues, please provide us with your template testing document, so that we can further investigate it.

Code: Select all
Document doc = new Document();
            doc.LoadFromFile("in.docx");
            //Match using regular expressions
            Regex regex = new Regex("<([^>]+)>");
            TextSelection[] text = doc.FindAllPattern(regex);
            //Use bookmarks to match content
            BookmarkStart start = new BookmarkStart(doc, "obj");
            BookmarkEnd end = new BookmarkEnd(doc, "obj");
       //Bookmark start position
             TextRange rangeStart = text[0].GetAsOneRange();
             Paragraph p = rangeStart.OwnerParagraph;
             int index = p.GetIndex(rangeStart);
             p.ChildObjects.Insert(index, start);
           //End position of bookmark
            TextRange rangeEnd = text[text.Length-1].GetAsOneRange();
            p = rangeEnd.OwnerParagraph;
            int endIndex = p.GetIndex(rangeEnd);
            p.ChildObjects.Insert(endIndex+1, end);
            //Delete the middle content
            //Create an instance of BookmarksNavigator
            BookmarksNavigator navigator = new BookmarksNavigator(doc);
            //Point to a specific bookmark
            navigator.MoveToBookmark("obj");
            //Delete content from bookmarks
            navigator.DeleteBookmarkContent(false);
            //delete bookmark
            doc.Bookmarks.Remove(doc.Bookmarks.FindByName("obj"));
            doc.SaveToFile("out.docx", FileFormat.Docx);


Sincerely,
Amin
E-iceblue support team
User avatar

Amin.Gan
 
Posts: 164
Joined: Mon Jul 15, 2024 5:40 am

Thu Aug 08, 2024 1:17 pm

Thank you for your suggestion

I didn't know the features of Bookmarks and BookmarksNavigator.

For my needs they have the same functionality as Range and Selection.
I think to be able to recode our program using your library.

Thanks again.

banca05156
 
Posts: 4
Joined: Mon Aug 05, 2024 10:00 am

Fri Aug 09, 2024 1:57 am

Hello,

Thanks for your reply.
I'm glad to hear this news. If you have any other questions, please feel free to write to me.

Sincerely,
Amin
E-iceblue support team
User avatar

Amin.Gan
 
Posts: 164
Joined: Mon Jul 15, 2024 5:40 am

Return to Spire.Doc

cron