最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#/VB.NET實(shí)現(xiàn)在Word中插入或刪除腳注

 更新時間:2023年03月08日 14:02:25   作者:Carina-baby  
腳注,是可以附在文章頁面的最底端的,對某些東西加以說明,印在書頁下端的注文。這篇文章將為您展示如何通過C#/VB.NET代碼,以編程方式在Word中插入或刪除腳注,需要的可以參考一下

腳注,是可以附在文章頁面的最底端的,對某些東西加以說明,印在書頁下端的注文。腳注和尾注是對文本的補(bǔ)充說明。腳注一般位于頁面的底部,可以作為文檔某處內(nèi)容的注釋。常用在一些說明書、標(biāo)書、論文等正式文書用來引注的內(nèi)容。這篇文章將為您展示如何通過C#/VB.NET代碼,以編程方式在Word中插入或刪除腳注。以下是我整理的具體步驟及方法,并附上C#/VB.NET代碼供大家參考。

  • 在Word中的特定段落后插入腳注
  • 在Word中的特定文本后插入腳注
  • 刪除Word文檔中的腳注

程序環(huán)境

本次測試時,在程序中引入Free Spire.Doc for .NET??赏ㄟ^以下方法引用 Free Spire.Doc.dll文件:

方法1:將 Free Spire.Doc for .NET下載到本地,解壓,安裝。安裝完成后,找到安裝路徑下BIN文件夾中的 Spire.Doc.dll。然后在Visual Studio中打開“解決方案資源管理器”,鼠標(biāo)右鍵點(diǎn)擊“引用”,“添加引用”,將本地路徑BIN文件夾下的dll文件添加引用至程序。

方法2:通過NuGet安裝。可通過以下2種方法安裝:

(1)可以在Visual Studio中打開“解決方案資源管理器”,鼠標(biāo)右鍵點(diǎn)擊“引用”,“管理NuGet包”,然后搜索“Free Spire.Doc”,點(diǎn)擊“安裝”。等待程序安裝完成。

(2)將以下內(nèi)容復(fù)制到PM控制臺安裝。

Install-Package FreeSpire.Doc -Version 10.8.0

在Word中的特定段落后插入腳注

以下是在指定段落后插入腳注的詳細(xì)步驟。

  • 創(chuàng)建Document實(shí)例
  • 使用Document.LoadFromFile() 方法加載示例Word文檔。
  • 獲取第一節(jié),然后獲取該節(jié)中的指定段落。
  • 使用Paragraph.AppendFootnote(FootnoteType.Footnote) 方法在段落末尾添加腳注。
  • 設(shè)置腳注的文本內(nèi)容、字體和顏色,然后設(shè)置腳注上標(biāo)數(shù)字的格式。
  • 使用Document.SaveToFile() 方法保存結(jié)果文檔。

完整代碼

C#

using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;

namespace AddFootnote
{
    class Program
    {
        static void Main(string[] args)
        {
            //創(chuàng)建Document實(shí)例
            Document document = new Document();

            //加載Word文檔示例
            document.LoadFromFile("我與地壇.docx");

            //獲取第一節(jié)
            Section section = document.Sections[0];

            //獲取節(jié)中的指定段落
            Paragraph paragraph = section.Paragraphs[1];

            //在段落末尾添加腳注
            Footnote footnote = paragraph.AppendFootnote(FootnoteType.Footnote);

            //設(shè)置腳注的文本內(nèi)容
            TextRange text = footnote.TextBody.AddParagraph().AppendText("即使世界毀滅,那又怎樣,天地崩塌,于我何干,我在乎的只有他。");

            //設(shè)置文本字體和顏色
            text.CharacterFormat.FontName = "宋體";
            text.CharacterFormat.FontSize = 12;
            text.CharacterFormat.TextColor = Color.DarkBlue;

            //設(shè)置腳注上標(biāo)數(shù)字的格式
            footnote.MarkerCharacterFormat.FontName = "Calibri";
            footnote.MarkerCharacterFormat.FontSize = 15; 
            footnote.MarkerCharacterFormat.Bold = true;
            footnote.MarkerCharacterFormat.TextColor = Color.DarkCyan;

            //保存結(jié)果文檔
            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())
            '創(chuàng)建Document實(shí)例
            Dim document As Document = New Document()

            '加載Word文檔示例
            document.LoadFromFile("我與地壇.docx")

            '獲取第一節(jié)
            Dim section As Section = document.Sections(0)

            '獲取節(jié)中的指定段落
            Dim paragraph As Paragraph = section.Paragraphs(1)

            '在段落末尾添加腳注
            Dim footnote As Footnote = paragraph.AppendFootnote(FootnoteType.Footnote)

            '設(shè)置腳注的文本內(nèi)容
            Dim text As TextRange = footnote.TextBody.AddParagraph().AppendText("即使世界毀滅,那又怎樣,天地崩塌,于我何干,我在乎的只有他。")

            '設(shè)置文本字體和顏色
            text.CharacterFormat.FontName = "宋體"
            text.CharacterFormat.FontSize = 12
            text.CharacterFormat.TextColor = Color.DarkBlue

            '設(shè)置腳注上標(biāo)數(shù)字的格式
            footnote.MarkerCharacterFormat.FontName = "Calibri"
            footnote.MarkerCharacterFormat.FontSize = 15
            footnote.MarkerCharacterFormat.Bold = True
            footnote.MarkerCharacterFormat.TextColor = Color.DarkCyan

            '保存結(jié)果文檔
            document.SaveToFile("添加腳注.docx", FileFormat.Docx)

        End Sub
    End Class
End Namespace

效果圖

在Word中的特定文本后插入腳注

我們還可以在文檔中任何位置的指定文本后插入腳注。以下是詳細(xì)步驟。

  • 創(chuàng)建Document實(shí)例。
  • 使用Document.LoadFromFile() 方法加載Word文檔。
  • 使用Document.FindString() 方法查找指定的文本。
  • 使用TextSelection.GetAsOneRange() 方法獲取指定文本的文本范圍。
  • 使用TextRange.OwnerParagraph 屬性獲取文本范圍所在的段落。
  • 使用Paragraph.ChildObjects.IndexOf() 方法獲取段落中文本范圍的位置索引。
  • 使用Paragraph.AppendFootnote(FootnoteType.Footnote)方法添加腳注,然后使用Paragraph.ChildObjects.Insert() 方法在指定文本后插入腳注
  • 設(shè)置腳注的文本內(nèi)容、字體和顏色,然后設(shè)置腳注上標(biāo)數(shù)字的格式。
  • 使用Document.SaveToFile() 方法保存結(jié)果文檔。

完整代碼

C#

using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;

namespace InsertFootnote
{
    class Program
    {
        static void Main(string[] args)
        {
            //創(chuàng)建Document實(shí)例
            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);

            //設(shè)置腳注的文本內(nèi)容
            TextRange text = footnote.TextBody.AddParagraph().AppendText("不知道兒子的不幸在母親那兒總是要加倍的。");

            //設(shè)置文本字體和顏色
            text.CharacterFormat.FontName = "宋體";
            text.CharacterFormat.FontSize = 12;
            text.CharacterFormat.TextColor = Color.DarkBlue;

            //設(shè)置腳注上標(biāo)數(shù)字的格式
            footnote.MarkerCharacterFormat.FontName = "Calibri";
            footnote.MarkerCharacterFormat.FontSize = 15;
            footnote.MarkerCharacterFormat.Bold = true;
            footnote.MarkerCharacterFormat.TextColor = Color.DarkGreen;

            //保存結(jié)果文檔
            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())
            '創(chuàng)建Document實(shí)例
            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)

            '設(shè)置腳注的文本內(nèi)容
            Dim text As TextRange = footnote.TextBody.AddParagraph().AppendText("不知道兒子的不幸在母親那兒總是要加倍的。")

            '設(shè)置文本字體和顏色
            text.CharacterFormat.FontName = "宋體"
            text.CharacterFormat.FontSize = 12
            text.CharacterFormat.TextColor = Color.DarkBlue

            '設(shè)置腳注上標(biāo)數(shù)字的格式
            footnote.MarkerCharacterFormat.FontName = "Calibri"
            footnote.MarkerCharacterFormat.FontSize = 15
            footnote.MarkerCharacterFormat.Bold = True
            footnote.MarkerCharacterFormat.TextColor = Color.DarkGreen

            '保存結(jié)果文檔
            document.SaveToFile("插入腳注.docx", FileFormat.Docx)
        End Sub
    End Class
End Namespace

效果圖

以上就是C#/VB.NET實(shí)現(xiàn)在Word中插入或刪除腳注的詳細(xì)內(nèi)容,更多關(guān)于C# Word插入刪除腳注的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評論

河西区| 玛纳斯县| 平顺县| 哈尔滨市| 秦皇岛市| 马尔康县| 五华县| 沐川县| 德兴市| 望江县| 墨江| 重庆市| 和田市| 普宁市| 嘉定区| 吴忠市| 博兴县| 巴林右旗| 普宁市| 玉屏| 扶沟县| 普兰店市| 平乐县| 甘南县| 成武县| 施甸县| 武宁县| 开封县| 合阳县| 昆山市| 大安市| 阜阳市| 古田县| 永泰县| 荆州市| 桂东县| 油尖旺区| 通海县| 麟游县| 凉城县| 天气|