Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
ODF .NET
>
Tutorial
> List bookmarks
The following example shows you how to list all document's bookmarks.
C# example
using System; using System.Collections.Generic; using Independentsoft.Office.Odf; namespace Sample { class Program { static void Main(string[] args) { TextDocument doc = new TextDocument("c:\\test\\input.odt"); IList
paragraphs = doc.GetParagraphs(); for (int i = 0; i < paragraphs.Count; i++) { foreach (IParagraphContent paragraphElement in paragraphs[i].Content) { if (paragraphElement is Bookmark) { Bookmark bookmark = (Bookmark)paragraphElement; Console.WriteLine("Bookmark: " + bookmark.Name); } else if (paragraphElement is BookmarkStart) { BookmarkStart bookmarkStart = (BookmarkStart)paragraphElement; Console.WriteLine("BookmarkStart: " + bookmarkStart.Name); } else if (paragraphElement is BookmarkEnd) { BookmarkEnd bookmarkEnd = (BookmarkEnd)paragraphElement; Console.WriteLine("BookmarkEnd: " + bookmarkEnd.Name); } } } Console.WriteLine("Pess any key to close."); Console.Read(); } } }
VB example
Imports System Imports System.Collections.Generic Imports Independentsoft.Office.Odf Module Module1 Sub Main(ByVal args() As String) Dim doc As New TextDocument("c:\test\input.odt") Dim paragraphs As IList(Of Paragraph) = doc.GetParagraphs() For i As Integer = 0 To paragraphs.Count - 1 For Each paragraphElement As IParagraphContent In paragraphs(i).Content If TypeOf paragraphElement Is Bookmark Then Dim bookmark As Bookmark = DirectCast(paragraphElement, Bookmark) Console.WriteLine("Bookmark: " + bookmark.Name) ElseIf TypeOf paragraphElement Is BookmarkStart Then Dim bookmarkStart As BookmarkStart = DirectCast(paragraphElement, BookmarkStart) Console.WriteLine("BookmarkStart: " + bookmarkStart.Name) ElseIf TypeOf paragraphElement Is BookmarkEnd Then Dim bookmarkEnd As BookmarkEnd = DirectCast(paragraphElement, BookmarkEnd) Console.WriteLine("BookmarkEnd: " + bookmarkEnd.Name) End If Next Next Console.WriteLine("Pess any key to close.") Console.Read() End Sub End Module
Need help? Ask our developers:
Name*
Email*
Message*