脚注,是可以附在文章页面的最底端的,对某些东西加以说明,印在书页下端的注文。脚注和尾注是对文本的补充说明。脚注一般位于页面的底部,可以作为文档某处内容的注释。常用在一些说明书、标书、论文等正式文书用来引注的内容。这篇文章将为您展示如何通过C#/VB.NET代码,以编程方式在Word中插入或删除脚注。以下是我整理的具体步骤及方法,并附上C#/VB.NET代码供大家参考。
本次测试时,在程序中引入Free Spire.Doc for .NET。可通过以下方法引用 Free Spire.Doc.dll文件:
方法1:将 Free Spire.Doc for .NET下载到本地,解压,安装。安装完成后,找到安装路径下BIN文件夹中的 Spire.Doc.dll。然后在Visual Studio中打开“解决方案资源管理器”,鼠标右键点击“引用”,“添加引用”,将本地路径BIN文件夹下的dll文件添加引用至程序。
方法2:通过NuGet安装。可通过以下2种方法安装:
(1)可以在Visual Studio中打开“解决方案资源管理器”,鼠标右键点击“引用”,“管理NuGet包”,然后搜索“Free Spire.Doc”,点击“安装”。等待程序安装完成。
(2)将以下内容复制到PM控制台安装。
Install-Package FreeSpire.Doc -Version 10.8.0
以下是在指定段落后插入脚注的详细步骤。
C#
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;
namespace AddFootnote
{
class Program
{
static void Main(string[] args)
{
//创建Document实例
Document document = new Document();
//加载Word文档示例
document.LoadFromFile("我与地坛.docx");
//获取第一节
Section section = document.Sections[0];
//获取节中的指定段落
Paragraph paragraph = section.Paragraphs[1];
//在段落末尾添加脚注
Footnote footnote = paragraph.AppendFootnote(FootnoteType.Footnote);
//设置脚注的文本内容
TextRange text = footnote.TextBody.AddParagraph().AppendText("即使世界毁灭,那又怎样,天地崩塌,于我何干,我在乎的只有他。");
//设置文本字体和颜色
text.CharacterFormat.FontName = "宋体";
text.CharacterFormat.FontSize = 12;
text.CharacterFormat.TextColor = Color.DarkBlue;
//设置脚注上标数字的格式
footnote.MarkerCharacterFormat.FontName = "Calibri";
footnote.MarkerCharacterFormat.FontSize = 15;
footnote.MarkerCharacterFormat.Bold = true;
footnote.MarkerCharacterFormat.TextColor = Color.DarkCyan;
//保存结果文档
document.SaveToFile("添加脚注.docx", FileFormat.Docx);
}
}
}
VB.NET
Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields
Imports System.Drawing
Namespace AddFootnote
Friend Class Program
Private Shared Sub Main(ByVal args As String())
'创建Document实例
Dim document As Document = New Document()
'加载Word文档示例
document.LoadFromFile("我与地坛.docx")
'获取第一节
Dim section As Section = document.Sections(0)
'获取节中的指定段落
Dim paragraph As Paragraph = section.Paragraphs(1)
'在段落末尾添加脚注
Dim footnote As Footnote = paragraph.AppendFootnote(FootnoteType.Footnote)
'设置脚注的文本内容
Dim text As TextRange = footnote.TextBody.AddParagraph().AppendText("即使世界毁灭,那又怎样,天地崩塌,于我何干,我在乎的只有他。")
'设置文本字体和颜色
text.CharacterFormat.FontName = "宋体"
text.CharacterFormat.FontSize = 12
text.CharacterFormat.TextColor = Color.DarkBlue
'设置脚注上标数字的格式
footnote.MarkerCharacterFormat.FontName = "Calibri"
footnote.MarkerCharacterFormat.FontSize = 15
footnote.MarkerCharacterFormat.Bold = True
footnote.MarkerCharacterFormat.TextColor = Color.DarkCyan
'保存结果文档
document.SaveToFile("添加脚注.docx", FileFormat.Docx)
End Sub
End Class
End Namespace

我们还可以在文档中任何位置的指定文本后插入脚注。以下是详细步骤。
C#
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;
namespace InsertFootnote
{
class Program
{
static void Main(string[] args)
{
//创建Document实例
Document document = new Document();
//加载Word文档示例
document.LoadFromFile("我与地坛.docx");
//查找指定的文本字符串
TextSelection selection = document.FindString("最苦的母亲", false, true);
//获取指定文本的文本范围
TextRange textRange = selection.GetAsOneRange();
//获取文本范围所在的段落
Paragraph paragraph = textRange.OwnerParagraph;
//获取段落中文本范围的位置索引
int index = paragraph.ChildObjects.IndexOf(textRange);
//添加脚注
Footnote footnote = paragraph.AppendFootnote(FootnoteType.Footnote);
//在指定段落后插入脚注
paragraph.ChildObjects.Insert(index + 1, footnote);
//设置脚注的文本内容
TextRange text = footnote.TextBody.AddParagraph().AppendText("不知道儿子的不幸在母亲那儿总是要加倍的。");
//设置文本字体和颜色
text.CharacterFormat.FontName = "宋体";
text.CharacterFormat.FontSize = 12;
text.CharacterFormat.TextColor = Color.DarkBlue;
//设置脚注上标数字的格式
footnote.MarkerCharacterFormat.FontName = "Calibri";
footnote.MarkerCharacterFormat.FontSize = 15;
footnote.MarkerCharacterFormat.Bold = true;
footnote.MarkerCharacterFormat.TextColor = Color.DarkGreen;
//保存结果文档
document.SaveToFile("插入脚注.docx", FileFormat.Docx);
}
}
}
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())
'创建Document实例
Dim document As Document = New Document()
'加载Word文档示例
document.LoadFromFile("我与地坛.docx")
'查找指定的文本字符串
Dim selection As TextSelection = document.FindString("最苦的母亲", False, True)
'获取指定文本的文本范围
Dim textRange As TextRange = selection.GetAsOneRange()
'获取文本范围所在的段落
Dim paragraph As Paragraph = textRange.OwnerParagraph
'获取段落中文本范围的位置索引
Dim index As Integer = paragraph.ChildObjects.IndexOf(textRange)
'添加脚注
Dim footnote As Footnote = paragraph.AppendFootnote(FootnoteType.Footnote)
'在指定段落后插入脚注
paragraph.ChildObjects.Insert(index + 1, footnote)
'设置脚注的文本内容
Dim text As TextRange = footnote.TextBody.AddParagraph().AppendText("不知道儿子的不幸在母亲那儿总是要加倍的。")
'设置文本字体和颜色
text.CharacterFormat.FontName = "宋体"
text.CharacterFormat.FontSize = 12
text.CharacterFormat.TextColor = Color.DarkBlue
'设置脚注上标数字的格式
footnote.MarkerCharacterFormat.FontName = "Calibri"
footnote.MarkerCharacterFormat.FontSize = 15
footnote.MarkerCharacterFormat.Bold = True
footnote.MarkerCharacterFormat.TextColor = Color.DarkGreen
'保存结果文档
document.SaveToFile("插入脚注.docx", FileFormat.Docx)
End Sub
End Class
End Namespace

—本文完—
我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div
总的来说,我对ruby还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用
作为我的Rails应用程序的一部分,我编写了一个小导入程序,它从我们的LDAP系统中吸取数据并将其塞入一个用户表中。不幸的是,与LDAP相关的代码在遍历我们的32K用户时泄漏了大量内存,我一直无法弄清楚如何解决这个问题。这个问题似乎在某种程度上与LDAP库有关,因为当我删除对LDAP内容的调用时,内存使用情况会很好地稳定下来。此外,不断增加的对象是Net::BER::BerIdentifiedString和Net::BER::BerIdentifiedArray,它们都是LDAP库的一部分。当我运行导入时,内存使用量最终达到超过1GB的峰值。如果问题存在,我需要找到一些方法来更正我的代
关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。
给定这段代码defcreate@upgrades=User.update_all(["role=?","upgraded"],:id=>params[:upgrade])redirect_toadmin_upgrades_path,:notice=>"Successfullyupgradeduser."end我如何在该操作中实际验证它们是否已保存或未重定向到适当的页面和消息? 最佳答案 在Rails3中,update_all不返回任何有意义的信息,除了已更新的记录数(这可能取决于您的DBMS是否返回该信息)。http://ar.ru
我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t
我正在寻找执行以下操作的正确语法(在Perl、Shell或Ruby中):#variabletoaccessthedatalinesappendedasafileEND_OF_SCRIPT_MARKERrawdatastartshereanditcontinues. 最佳答案 Perl用__DATA__做这个:#!/usr/bin/perlusestrict;usewarnings;while(){print;}__DATA__Texttoprintgoeshere 关于ruby-如何将脚
如何在buildr项目中使用Ruby?我在很多不同的项目中使用过Ruby、JRuby、Java和Clojure。我目前正在使用我的标准Ruby开发一个模拟应用程序,我想尝试使用Clojure后端(我确实喜欢功能代码)以及JRubygui和测试套件。我还可以看到在未来的不同项目中使用Scala作为后端。我想我要为我的项目尝试一下buildr(http://buildr.apache.org/),但我注意到buildr似乎没有设置为在项目中使用JRuby代码本身!这看起来有点傻,因为该工具旨在统一通用的JVM语言并且是在ruby中构建的。除了将输出的jar包含在一个独特的、仅限ruby
尝试通过RVM将RubyGems升级到版本1.8.10并出现此错误:$rvmrubygemslatestRemovingoldRubygemsfiles...Installingrubygems-1.8.10forruby-1.9.2-p180...ERROR:Errorrunning'GEM_PATH="/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/ruby-1.9.2-p180@global:/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/rub
Rackup通过Rack的默认处理程序成功运行任何Rack应用程序。例如:classRackAppdefcall(environment)['200',{'Content-Type'=>'text/html'},["Helloworld"]]endendrunRackApp.new但是当最后一行更改为使用Rack的内置CGI处理程序时,rackup给出“NoMethodErrorat/undefinedmethod`call'fornil:NilClass”:Rack::Handler::CGI.runRackApp.newRack的其他内置处理程序也提出了同样的反对意见。例如Rack