打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
在Aspose.Word上使用书签bookmarks

在Microsoft Word里咱们常使用书签,Aspose.Word书签功能也可以完全实现word的效果,就是让你标识和命名位置的工具,以便以后能够快速查阅,这样的话就无需在文档中上下滚动来定位该文。只需要双击书签,光标就自动字位到关键字这一行,然后选中,是不是很方便呢。

Aspose.Word可以插入一个新的书签、删除书签、移动书签,设置书签的名字、文本等。下面咱们简单介绍Aspose.Word中书签的几个简单用法:

1.使用Aspose.Word快速创建一个新的书签,具体代码如下:
[C#]
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.StartBookmark("MyBookmark");
builder.Writeln("Text inside a bookmark.");
builder.EndBookmark("MyBookmark");
 
[Visual Basic]
Dim doc As New Document()
Dim builder As New DocumentBuilder(doc)

builder.StartBookmark("MyBookmark")
builder.Writeln("Text inside a bookmark.")
builder.EndBookmark("MyBookmark")

2.如何获取word里里的书签,在word里经常会存在多个书签,控件提供了方法用于查找和获取word里的书签,具体代码如下:
[C#]
Document doc = new Document(MyDir + "Bookmarks.doc");
Bookmark bookmark1 = doc.Range.Bookmarks[0];
Bookmark bookmark2 = doc.Range.Bookmarks["Bookmark2"];
[Visual Basic]
Dim doc As New Document(MyDir & "Bookmarks.doc")
Dim bookmark1 As Bookmark = doc.Range.Bookmarks(0)
Dim bookmark2 As Bookmark = doc.Range.Bookmarks("Bookmark2")

3. 如何得到和设置书签名字和文本,具体代码如下:
[C#]
Document doc = new Document(MyDir + "Bookmark.doc");
// Use the indexer of the Bookmarks collection to obtain the desired bookmark.
Bookmark bookmark = doc.Range.Bookmarks["MyBookmark"];
// Get the name and text of the bookmark.
string name = bookmark.Name;
string text = bookmark.Text;
// Set the name and text of the bookmark.
bookmark.Name = "RenamedBookmark";
bookmark.Text = "This is a new bookmarked text.";
[VB.NET]
Dim doc As New Document(MyDir & "Bookmark.doc")
' Use the indexer of the Bookmarks collection to obtain the desired bookmark.
Dim bookmark As Bookmark = doc.Range.Bookmarks("MyBookmark")
' Get the name and text of the bookmark.
Dim name As String = bookmark.Name
Dim text As String = bookmark.Text
' Set the name and text of the bookmark.
bookmark.Name = "RenamedBookmark"
bookmark.Text = "This is a new bookmarked text."

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
实现Word文档和Excel文档的模板化导出
利用access VBA批量输出word文档 Excel VBA
vb操作word字符替换添加表格文字格式
Java操作word转pdf
打开另一个WORD文档并从中复制数据
文档怎么操作
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服