翻譯|使用教程|編輯:顏馨|2023-04-11 11:00:02.017|閱讀 155 次
概述:本文主要介紹如何在C#或VB.NET中調(diào)整Word文檔中插入腳注和尾注,歡迎查閱!
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
Spire.Doc for .NET是一款專門對 Word 文檔進(jìn)行操作的 .NET 類庫。在于幫助開發(fā)人員無需安裝 Microsoft Word情況下,輕松快捷高效地創(chuàng)建、編輯、轉(zhuǎn)換和打印 Microsoft Word 文檔。擁有近10年專業(yè)開發(fā)經(jīng)驗Spire系列辦公文檔開發(fā)工具,專注于創(chuàng)建、編輯、轉(zhuǎn)換和打印Word/PDF/Excel等格式文件處理,小巧便捷。
E-iceblue 功能類庫Spire 系列文檔處理組件均由中國本土團(tuán)隊研發(fā),不依賴第三方軟件,不受其他國家的技術(shù)或法律法規(guī)限制,同時適配國產(chǎn)操作系統(tǒng)如中科方德、中標(biāo)麒麟等,兼容國產(chǎn)文檔處理軟件 WPS(如 .wps/.et/.dps 等格式
腳注和尾注是簡短的注釋,可用于對文檔中的某些單詞或句子提供解釋、注釋或引用。腳注通常出現(xiàn)在包含其參考編號的頁面底部,而尾注出現(xiàn)在文檔或章節(jié)的末尾。如果您正在用 Word 撰寫學(xué)術(shù)論文,則插入腳注或尾注可能是必不可少的。本文將演示如何用Spire.Doc for .NET.在 C# 和 VB.NET 的 Word 文檔中插入腳注和尾注。
首先,您需要將 Spire.Doc for .NET 包中包含的 DLL 文件添加為 .NET 項目中的引用。DLL 文件可以從過以下方式安裝 NuGet.
PM> Install-Package Spire.Doc
腳注由兩部分組成 :腳注參考標(biāo)記和相應(yīng)的腳注文本。要插入特定文本的腳注,您需要搜索文本并獲取文本所在的段落,然后在段落中添加腳注,然后在找到的文本后插入腳注引用標(biāo)記并設(shè)置腳注文本。具體步驟如下:
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
尾注由兩部分組成 —— 尾注引用標(biāo)記和相應(yīng)的尾注文本。為特定文本插入尾注的步驟與上述示例非常相似:
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 文檔中插入腳注和尾注的方法,如果您有其他問題也可以繼續(xù)瀏覽本系列文章,獲取相關(guān)教程,你還可以給我留言或者加入我們的官方技術(shù)交流群。
歡迎下載|體驗更多E-iceblue產(chǎn)品
獲取更多信息請咨詢 ;技術(shù)交流Q群(767755948)
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn