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.

Fri Mar 03, 2017 2:01 am

Hi,

We have an original function would like to port over using Spire.Doc

Code: Select all
public void DeleteBookmarkRow(string bookmarkName, int rowNo)
        {
            object bookmark = bookmarkName;
            if (wordApp.ActiveDocument.Bookmarks.Exists(bookmarkName) == true)
            {
                Range rng = wordApp.ActiveDocument.Bookmarks.get_Item(ref bookmark).Range;
                rng.Select();
                wordApp.Selection.Rows[rowNo].Delete();
            }
        }

May I have your advice what is the best way of doing it? Thank in Advice!

chino
 
Posts: 1
Joined: Fri Mar 03, 2017 1:54 am

Fri Mar 03, 2017 7:48 am

Dear chino,

Thanks for your inquiry.
Here is sample code for your reference.
Code: Select all
            Document doc = new Document(@"F:\testing\doc form\original document\9933.docx");
            Section sec = doc.Sections[0];
            BookmarkCollection bookmarks = doc.Bookmarks;
           
            foreach (Bookmark bookmark in bookmarks)
            {
                if (bookmark.Name == "Row1")
                {
                    //get the row which has bookmark
                    TableRow row = bookmark.BookmarkStart.Owner.Owner.Owner as TableRow;
                    Table table = row.Owner as Table;
                    table.Rows.Remove(row);
                }
            }
            doc.SaveToFile("9933.docx", FileFormat.Docx);

Hope this can help. If it doesn't meet your requirement, please provide us your input file so that we can provide you corresponding code quickly.

Thanks,
Betsy
E-iceblue support team
User avatar

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

Fri Mar 10, 2017 3:48 am

Dear chino,

Did you test the code I provided ? Did it help you solve your issue ?

Thanks,
Betsy
User avatar

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

Return to Spire.Doc