Word控件Spire.Doc 【脚注】教程(1) 使用C#或VB.NET在 Word 文档中插入脚注和尾注
Spire.Doc for .NET是一款专门对 Word 文档进行操作的 .NET 类库。在于帮助开发人员无需安装 Microsoft Word情况下,轻松快捷高效地创建、编辑、转换和打印 Microsoft Word 文档。拥有近10年专业开发经验Spire系列办公文档开发工具,专注于创建、编辑、转换和打印Word/PDF/Excel等格式文件处理,小巧便捷。
E-iceblue 功能类库Spire 系列文档处理组件均由中国本土团队研发,不依赖第三方软件,不受其他国家的技术或法律法规限制,同时适配国产操作系统如中科方德、中标麒麟等,兼容国产文档处理软件 WPS(如 .wps/.et/.dps 等格式
Spire.Doc for.NET 最新下载(qun:767755948)https://www.evget.com/product/3368/download
脚注和尾注是简短的注释,可用于对文档中的某些单词或句子提供解释、注释或引用。脚注通常出现在包含其参考编号的页面底部,而尾注出现在文档或章节的末尾。如果您正在用 Word 撰写学术论文,则插入脚注或尾注可能是必不可少的。本文将演示如何用Spire.Doc for .NET.在 C# 和 VB.NET 的 Word 文档中插入脚注和尾注。
安装 Spire.Doc for .NET
首先,您需要将 Spire.Doc for .NET 包中包含的 DLL 文件添加为 .NET 项目中的引用。DLL 文件可以从过以下方式安装 NuGet.
PM> Install-Package Spire.Doc
在 C# 和 VB.NET Word 中插入脚注
脚注由两部分组成 :脚注参考标记和相应的脚注文本。要插入特定文本的脚注,您需要搜索文本并获取文本所在的段落,然后在段落中添加脚注,然后在找到的文本后插入脚注引用标记并设置脚注文本。具体步骤如下:
- 初始化文档
- 使用加载 Word 文档 Document.LoadFromFile() 方法。
- 使用 Document.FindString() 方法,并使用以下命令将找到的文本作为单个文本范围获取 TextSelection.GetAsOneRange() 方法。
- 通过以下方式访问文本范围的所有者段落 TextRange.OwnerParagraph 属性,并使用 Paragraph.ChildObjects.IndexOf() 方法。
- 使用在段落中添加脚注 Paragraph.AppendFootnote(FootnoteType.Footnote) 方法。
- 在文本范围后插入脚注引用标记,使用 Paragraph.ChildObjects.Insert() 方法。
- 使用设置脚注文本 Footnote.TextBody.AddParagraph().追加文本() 方法。
- 设置脚注文本和参考标记的格式,例如字体名称、字体大小和文本颜色。
- 保存结果文档使用 Document.SaveToFile() 方法。
C#
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;
namespace InsertFootnote
{
internal class Program
{
static void Main(string[] args)
{
//Initialize an instance of the Document class
Document document = new Document();
//Load a Word document
document.LoadFromFile(@"Sample.docx");
//Find a specific text in the document
TextSelection selection = document.FindString("Spire.Doc for .NET", false, true);
//Get the found text as a single text range
TextRange textRange = selection.GetAsOneRange();
//Get the owner paragraph of the text range
Paragraph paragraph = textRange.OwnerParagraph;
//Get the index of the text range in the paragraph
int index = paragraph.ChildObjects.IndexOf(textRange);
//Add a footnote to the paragraph
Footnote footnote = paragraph.AppendFootnote(FootnoteType.Footnote);
//Insert the footnote reference mark after the text range
paragraph.ChildObjects.Insert(index + 1, footnote);
//Set the footnote text
textRange = footnote.TextBody.AddParagraph().AppendText("Developed by E-iceblue Co., LTD.");
//Set format for the footnote text
textRange.CharacterFormat.FontName = "Arial Black";
textRange.CharacterFormat.FontSize = 12;
textRange.CharacterFormat.TextColor = Color.DarkGray;
//Set format for the footnote reference mark
footnote.MarkerCharacterFormat.FontName = "Calibri";
footnote.MarkerCharacterFormat.FontSize = 12;
footnote.MarkerCharacterFormat.Bold = true;
footnote.MarkerCharacterFormat.TextColor = Color.DarkGreen;
//Save the result document
document.SaveToFile("InsertFootnote.docx", FileFormat.Docx2013);
document.Close();
}
}
}
VB.NET
Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields
Imports System.Drawing
Namespace InsertFootnote
Friend Class Program
Private Shared Sub Main(ByVal args As String())
'Initialize an instance of the Document class
Dim document As Document = New Document()
'Load a Word document
document.LoadFromFile("Sample.docx")
'Find a specific text in the document
Dim selection As TextSelection = document.FindString("Spire.Doc for .NET", False, True)
'Get the found text as a single text range
Dim textRange As TextRange = selection.GetAsOneRange()
'Get the owner paragraph of the text range
Dim paragraph As Paragraph = textRange.OwnerParagraph
'Get the index of the text range in the paragraph
Dim index As Integer = paragraph.ChildObjects.IndexOf(textRange)
'Add a footnote to the paragraph
Dim footnote As Footnote = paragraph.AppendFootnote(FootnoteType.Footnote)
'Insert the footnote reference mark after the text range
paragraph.ChildObjects.Insert(index + 1, footnote)
'Set the footnote text
textRange = footnote.TextBody.AddParagraph().AppendText("Developed by E-iceblue Co., LTD.")
'Set format for the footnote text
textRange.CharacterFormat.FontName = "Arial Black"
textRange.CharacterFormat.FontSize = 12
textRange.CharacterFormat.TextColor = Color.DarkGray
'Set format for the footnote reference mark
footnote.MarkerCharacterFormat.FontName = "Calibri"
footnote.MarkerCharacterFormat.FontSize = 12
footnote.MarkerCharacterFormat.Bold = True
footnote.MarkerCharacterFormat.TextColor = Color.DarkGreen
'Save the result document
document.SaveToFile("InsertFootnote.docx", FileFormat.Docx2013)
document.Close()
End Sub
End Class
End Namespace
在 C# 和 VB.NET 的 Word 中插入尾注
尾注由两部分组成 —— 尾注引用标记和相应的尾注文本。为特定文本插入尾注的步骤与上述示例非常相似:
- 初始化文档。
- 使用 加载 Word 文档 Document.LoadFromFile() 方法。
- 使用 Document.FindString() 方法,并使用以下命令将找到的文本作为单个文本范围获取 TextSelection.GetAsOneRange() 方法。
- 通过以下方式访问文本范围的所有者段落 TextRange.OwnerParagraph 属性,并使用 Paragraph.ChildObjects.IndexOf() 方法。
- 使用 向段落添加尾注 Paragraph.AppendFootnote(FootnoteType.Endnote) 方法。
- 在文本范围后插入尾注引用标记 Paragraph.ChildObjects.Insert() 方法。
- 使用 设置尾注文本 Footnote.TextBody.AddParagraph().追加文本() 方法。
- 设置尾注文本和参考标记的字体名称、字体大小和文本颜色等格式。
- 保存结果文档使用 Document.SaveToFile() 方法。
C#
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;
namespace InsertEndnote
{
internal class Program
{
static void Main(string[] args)
{
//Initialize an instance of the Document class
Document document = new Document();
//Load a Word document
document.LoadFromFile(@"Sample.docx");
//Find a specific text in the document
TextSelection selection = document.FindString("Microsoft Office", false, true);
//Get the found text as a single text range
TextRange textRange = selection.GetAsOneRange();
//Get the owner paragraph of the text range
Paragraph paragraph = textRange.OwnerParagraph;
//Get the index of the text range in the paragraph
int index = paragraph.ChildObjects.IndexOf(textRange);
//Add an endnote to the paragraph
Footnote endnote = paragraph.AppendFootnote(FootnoteType.Endnote);
//Insert the endnote reference mark after the text range
paragraph.ChildObjects.Insert(index + 1, endnote);
//Set the endnote text
textRange = endnote.TextBody.AddParagraph().AppendText("Developed by Microsoft.");
//Set format for the endnote text
textRange.CharacterFormat.FontName = "Arial Black";
textRange.CharacterFormat.FontSize = 12;
textRange.CharacterFormat.TextColor = Color.DarkGray;
//Set format for the endnote reference mark
endnote.MarkerCharacterFormat.FontName = "Calibri";
endnote.MarkerCharacterFormat.FontSize = 12;
endnote.MarkerCharacterFormat.Bold = true;
endnote.MarkerCharacterFormat.TextColor = Color.DarkGreen;
//Save the result document
document.SaveToFile("InsertEndnote.docx", FileFormat.Docx2013);
document.Close();
}
}
}
VB.NET
Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields
Imports System.Drawing
Namespace InsertEndnote
Friend Class Program
Private Shared Sub Main(ByVal args As String())
'Initialize an instance of the Document class
Dim document As Document = New Document()
'Load a Word document
document.LoadFromFile("Sample.docx")
'Find a specific text in the document
Dim selection As TextSelection = document.FindString("Microsoft Office", False, True)
'Get the found text as a single text range
Dim textRange As TextRange = selection.GetAsOneRange()
'Get the owner paragraph of the text range
Dim paragraph As Paragraph = textRange.OwnerParagraph
'Get the index of the text range in the paragraph
Dim index As Integer = paragraph.ChildObjects.IndexOf(textRange)
'Add a endnote to the paragraph
Dim endnote As Footnote = paragraph.AppendFootnote(FootnoteType.Endnote)
'Insert the endnote reference mark after the text range
paragraph.ChildObjects.Insert(index + 1, endnote)
'Set the endnote text
textRange = endnote.TextBody.AddParagraph().AppendText("Developed by Microsoft.")
'Set format for the endnote text
textRange.CharacterFormat.FontName = "Arial Black"
textRange.CharacterFormat.FontSize = 12
textRange.CharacterFormat.TextColor = Color.DarkGray
'Set format for the endnote reference mark
endnote.MarkerCharacterFormat.FontName = "Calibri"
endnote.MarkerCharacterFormat.FontSize = 12
endnote.MarkerCharacterFormat.Bold = True
endnote.MarkerCharacterFormat.TextColor = Color.DarkGreen
'Save the result document
document.SaveToFile("InsertEndnote.docx", FileFormat.Docx2013)
document.Close()
End Sub
End Class
End Namespace
申请临时许可证
如果您想从生成的文档中删除评估消息,或摆脱功能限制,请 为自己申请 30 天试用许可证 。
以上便是如何使用C#或VB.NET:在 Word 文档中插入脚注和尾注的方法,如果您有其他问题也可以继续浏览本系列文章,获取相关教程,你还可以给我留言或者加入我们的官方技术交流群。
相关文章
- 推荐.Net、C# 逆向反编译四大工具利器(请勿用来非法行为)
- C# Net Core 使用 ClientWebSocket 实现 WebSocket 客户端
- ExpandoObject与DynamicObject的使用 RabbitMQ与.net core(一)安装 RabbitMQ与.net core(二)Producer与Exchange ASP.NET Core 2.1 : 十五.图解路由(2.1 or earler) .NET Core中的一个接口多种实现的依赖注入与动态选择看这篇就够了
- .NET压缩图片保存 .NET CORE WebApi Post跨域提交 C# Debug和release判断用法 tofixed方法 四舍五入 (function($){})(jQuery); 使用VUE+iView+.Net Core上传图片
- 中小研发团队架构实践之生产环境诊断工具WinDbg 三分钟学会.NET微服务之Polly 使用.Net Core+IView+Vue集成上传图片功能 Fiddler原理~知多少? ABP框架(asp.net core 2.X+Vue)模板项目学习之路(一) C#程序中设置全局代理(Global Proxy) WCF 4.0 使用说明 如何在IIS上发布,并能正常访问
- SQL 横转竖 、竖专横 (转载) 使用Dapper.Contrib 开发.net core程序,兼容多种数据库 C# 读取PDF多级书签 Json.net日期格式化设置 ASPNET 下载共享文件 ASPNET 文件批量下载 递归,循环,尾递归 利用IDisposable接口构建包含非托管资源对象 《.NET 进阶指南》读书笔记2------定义不可改变类型
- C# 2进制、8进制、10进制、16进制...各种进制间的转换(三) 数值运算和位运算 C# 2进制、8进制、10进制、16进制...各种进制间的转换(二)搜集的各种转换及方法 C# 2进制、8进制、10进制、16进制...各种进制间的转换(一) convert 类中的方法 C#.NET 中的定时器及使用方法 依赖注入 加密 解密
- 反爬虫:利用ASP.NET MVC的Filter和缓存(入坑出坑) C#中缓存的使用 C#操作redis WPF 控件库——可拖动选项卡的TabControl 【Bootstrap系列】详解Bootstrap-table AutoFac event 和delegate的分别 常见的异步方式async 和 await C# Task用法 c#源码的执行过程
- 项目开发中的一些注意事项以及技巧总结 基于Repository模式设计项目架构—你可以参考的项目架构设计 Asp.Net Core中使用RSA加密 EF Core中的多对多映射如何实现? asp.net core下的如何给网站做安全设置 获取服务端https证书 Js异常捕获
- ASP.NET MVC深入浅出系列(持续更新) ORM系列之Entity FrameWork详解(持续更新) 第十六节:语法总结(3)(C#6.0和C#7.0新语法) 第三节:深度剖析各类数据结构(Array、List、Queue、Stack)及线程安全问题和yeild关键字 各种通讯连接方式 设计模式篇 第十二节: 总结Quartz.Net几种部署模式(IIS、Exe、服务部署【借
- ASP.NET MVC Filters 4种默认过滤器的使用【附示例】 数据库常见死锁原因及处理 .NET源码中的链表 多线程下C#如何保证线程安全? .net实现支付宝在线支付 彻头彻尾理解单例模式与多线程 App.Config详解及读写操作 判断客户端是iOS还是Android,判断是不是在微信浏览器打开
- ASP.NET MVC WebApi 返回数据类型序列化控制(json,xml) 用javascript在客户端删除某一个cookie键值对 input点击链接另一个页面,各种操作。 C# 往线程里传参数的方法总结 TCP/IP 协议 用C#+Selenium+ChromeDriver 生成我的咕咚跑步路线地图 (转)值得学习百度开源70+项目
- Task C# 多线程和异步模型 TPL模型 【C#】43. TPL基础——Task初步 22 C# 第十八章 TPL 并行编程 TPL 和传统 .NET 异步编程一 Task.Delay() 和 Thread.Sleep() 区别
- MVC的验证(模型注解和非侵入式脚本的结合使用) .Net中初探Redis .net通过代码发送邮件 Log4net (Log for .net) 使用GDI技术创建ASP.NET验证码 Razor模板引擎 (RazorEngine) .Net程序员应该掌握的正则表达式
- C#构造方法(函数) C#方法重载 C#字段和属性 MUI实现上拉加载和下拉刷新 SVN常用功能介绍(二) SVN常用功能介绍(一) ASP.NET常用内置对象之——Server sql server——子查询 C#接口 字符串的本质 AJAX原生JavaScript写法
- (六)Net Core项目使用Controller之一 c# log4net 不输出日志 .NET Standard库引用导致的FileNotFoundException探究 获取json串里的某个属性值 common.js 如何调用common.js js 筛选数据 Join 具体用法
- easyui datagrid 禁止选中行 EF的增删改查(转载) C# 获取用户IP地址(转载) MVC EF 执行SQL语句(转载) 在EF中执行SQL语句(转载) EF中使用SQL语句或存储过程 .net MVC使用Session验证用户登录 PowerDesigner 参照完整性约束(转载)
- 深入理解MVC C#+HtmlAgilityPack+Dapper走一波爬虫 StackExchange.Redis 二次封装 C# WPF 用MediaElement控件实现视频循环播放 net 异步与同步
- 使用 C#/.NET Core 实现单体设计模式
- Word控件Spire.Doc 【评论】教程(3):在C#、VB.NET中从Word文档中提取注释并保存在TXT文件中
- Word控件Spire.Doc 【超链接】教程(8):在 C#/VB.NET 中链接到 Word 文档中的书签
- Word控件Spire.Doc 【文档操作】教程(四):在 C#、VB.NET 中设置 Word 视图模式
- Word控件Spire.Doc 【文档操作】教程(五):在 C#、VB.NET 中合并、设置多个 Word 文档
- Word控件Spire.Doc 【文档操作】教程(四):在 C#、VB.NET 中设置 Word 视图模式
- Word控件Spire.Doc 转换教程(二十):在 C#、VB.NET 中将 Word 转换为 Word XML
- c# .net 模拟请求 POST, Get,Put,Delete,并带Headers,BUF加持异步多线程执行
- 如鹏网.NET软件工程师提高班 杨中科.net高级视频
- [C#] Direct2D 学习笔记 (一)vb.net转换为c#
- .NET/C# 反射的的性能数据,以及高性能开发建议(反射获取 Attribute 和反射调用方法)——转载
- 数字转换字母C#与VB.net方法
- C# asp.net开源插件推荐:PdfiumViewer ( pdf 转成 图片png pdf convert to image )
- [.NET]c#.net程序中使用ffmpeg.exe来处理视频并生成上传视频的截图
- C#与.NET Framework c#编程语言,和java是一样的。(c#,java) -->javaweb,asp.net