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.DrawingNamespace 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.DrawingNamespace 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 文档中插入脚注和尾注的方法,如果您有其他问题也可以继续浏览本系列文章,获取相关教程,你还可以给我留言或者加入我们的官方技术交流群。

Word控件Spire.Doc 【脚注】教程(1) 使用C#或VB.NET在 Word 文档中插入脚注和尾注相关推荐

  1. Word控件Spire.Doc 转换教程(二十三):保留或禁用从 Word 到 PDF 转换的超链接

    超链接为读者提供了更多的附加信息,它被广泛用于我们的 word 文档.Spire.Doc 具有强大的超链接文字元素操作功能.开发者可以在word文档中添加.修改和删除超链接.Spire.Doc for ...

  2. Word控件Spire.Doc 转换教程(十二):如何将 Word 转换为 EPub、XPS、Emf

    本文将介绍一种通过名为 Spire.Doc 的强大且独立的Word .NET 组件将 Word 转换为 EPub.XPS.Emf的简单方法,无需在机器上安装 Microsoft Word.它还支持将 ...

  3. Word控件Spire.Doc 转换教程(六):如何将 XML 转换为 Word

    为什么使用 C#/VB.NET 将 Office OpenXML 转换为 Word? 作为一种出色的编程语言,Office OpenXML 在其自然形式下很难导航和访问.将文件从 Office Ope ...

  4. Word控件Spire.Doc 转换教程(九):在 Doc 转PDF 转换期间设置图像质量

    您可能会好奇为什么我们在将Doc 转换为 PDF时设置图像质量.在我们转换Word文档后,尤其是文档中有很多图像,输出的PDF文档的大小明显大于原始的Doc文件.现在,Spire.Doc 新版本的新功 ...

  5. Word控件Spire.Doc 转换教程(十八): 将 RTF 转换为图像并重置图像分辨率

    Spire.Doc具有在 C# 和 VB.NET 中操作 RTF 文件格式的强大能力.通过使用 Spire.Doc,开发人员可以将 RTF 转换为 PDF.HTML和 .doc..docx 格式的 w ...

  6. Word控件Spire.Doc 转换教程(十一):如何将 HTML 转换为图像

    Spire.Doc 可以帮助用户使用 C#/VB.NET 将HTML 转换为 Image.该解决方案使用户可以随时随地通过手机.MP4播放器.PSP.iPad.iTouch等便携式设备阅读HTML.按 ...

  7. Word控件Spire.Doc 转换教程(七):如何将 Word 转换为 RTF

    为什么要将 Word 转换为 RTF? 自 1990 年代以来,Microsoft 开始为其一系列专有的文字处理格式使用 .doc 扩展名.Doc 格式通常与 Microsoft Office 应用程 ...

  8. Word控件Spire.Doc 转换教程(二十八):将 Word 转换为 PCL

    PCL 文件是以打印机命令语言(通常称为 PCL)页面描述语言创建的数字打印文档.从v7.1.19 开始,Spire.Doc 支持将 word 文档转换为 PCL.PCL文件的标准有很多种:这里的 P ...

  9. Word控件Spire.Doc 转换教程(二十五):在 C#、VB.NET 中将 ODT 转换为 DOC

    具有 .ODT 文件扩展名的文件是 OpenDocument 文本文档文件.这些文件通常由免费的 OpenOffice Writer 文字处理器程序创建.ODT 文件类似于与 Microsoft Wo ...

  10. Word控件Spire.Doc 转换教程(二十六):在 C#、VB.NET 中将 Word 转换为 EPUB 时添加封面图片

    我们之前介绍如何将 Word 转换为 EPUB的文档.但是,在从 Word 文档创建 EPUB 图书时,您可能希望将封面图像添加到 EPUB.以下代码片段将演示相同的内容. Spire.Doc for ...

最新文章

  1. mysql主从复制 跳过表_mysql主从复制-从库跳过异常日志点
  2. 芯片短缺加剧,上半年汽车销量逆势上涨的丰田也扛不住了,9月减产40%
  3. centos7 安装配置openstack-dashboard (官网openstack-juno版)
  4. scp 安全复制(远程文件复制工具)
  5. oracle connection 有时能取到有时候又取不到
  6. WWW超文本源码浏览器
  7. Javascript 获取和设置日期
  8. suse linux 11如何分区,新手发帖,关于SUSE11挂载磁盘阵列并分区的问题
  9. 小红书:笔试题(棋盘最短路径,笔记本草稿栈,迷宫游戏)
  10. 【已解决】 c8812在eclipse上调试打不出log来?求帮助如何解决?!!!
  11. PM3GUI 和 RDV4GUI 专业版软件试用手札
  12. 硬币的一分、二分与五分有收藏价值吗,都是怎样的?
  13. 携手业内专家赋能AI时代--EpiK铭识协议发起开源知识运动
  14. win10系统停止更新服务器,Win10系统关闭自动更新功能的三种最佳方法
  15. vue3中的tsx写法
  16. 用selenium全自动化爬取教务系统作业清单
  17. java 适合练手的java项目
  18. java 通过User-Agent来判断是否是移动浏览器
  19. 学计算机去旧金山,旧金山大学的计算机专业如何?
  20. QMetaMethod::invoke: Unable to invoke methods with return values in queued connections

热门文章

  1. 盛合晶微半导体公司C轮融资3亿美元;调研显示,人工智能/大数据/云计算调薪率领跑高科技 | 全球TMT...
  2. mpeg转换mp4格式怎么转?
  3. 创维E900-S-Hi3798MV100-当贝纯净桌面-卡刷固件包
  4. 安装ubuntu出现花屏_在Ubuntu 18.04系统中挂起,再唤醒就出现花屏的解决办法
  5. CSS3+HTML蜡烛燃烧动画
  6. CocosCreator | 自定义启动页之H5
  7. Android Studio 新版本 Logcat 速查
  8. jekyll个人博客中添加音乐播放插件
  9. 蓝牙技术|蓝牙与机器人
  10. python合并excel要求_通过Python合并Excel文件,进行,excel