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

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

 更新時(shí)間: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)境

本次測試時(shí),在程序中引入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)文章

  • Unity3D創(chuàng)建圓柱體的方法

    Unity3D創(chuàng)建圓柱體的方法

    這篇文章主要為大家詳細(xì)介紹了Unity3D創(chuàng)建圓柱體的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-02-02
  • C#讀寫配置文件方式(config.ini)入門

    C#讀寫配置文件方式(config.ini)入門

    這篇文章主要介紹了C#讀寫配置文件方式(config.ini)入門,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-06-06
  • C#通過xpath查找xml指定元素的方法

    C#通過xpath查找xml指定元素的方法

    這篇文章主要介紹了C#通過xpath查找xml指定元素的方法,涉及C#操作XML文件的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2015-04-04
  • C#調(diào)用JS的幾種方法

    C#調(diào)用JS的幾種方法

    這篇文章主要介紹了C#調(diào)用JS的幾種方法,幫助大家更好的理解和使用c#,感興趣的朋友可以了解下
    2020-12-12
  • C#正則表達(dá)式與HashTable詳解

    C#正則表達(dá)式與HashTable詳解

    這篇文章主要介紹了C#正則表達(dá)式與HashTable詳解,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下
    2022-07-07
  • C# Dictionary的使用實(shí)例代碼

    C# Dictionary的使用實(shí)例代碼

    C# Dictionary的使用實(shí)例代碼,需要的朋友可以參考一下
    2013-04-04
  • C#引用類型轉(zhuǎn)換的常見方式總結(jié)

    C#引用類型轉(zhuǎn)換的常見方式總結(jié)

    這篇文章主要介紹了C#引用類型轉(zhuǎn)換的常見方式,包括子類轉(zhuǎn)換成父類,父類轉(zhuǎn)換成子類,以及不是子父級關(guān)系類之間的轉(zhuǎn)換,需要的朋友可以參考下
    2014-09-09
  • C#9.0新特性詳解——頂級程序語句(Top-Level Programs)

    C#9.0新特性詳解——頂級程序語句(Top-Level Programs)

    這篇文章主要介紹了C#9.0新特性詳解——頂級程序語句(Top-Level Programs)的相關(guān)資料,幫助大家更好的理解和學(xué)習(xí)c#,感興趣的朋友可以了解下
    2020-12-12
  • C#檢測遠(yuǎn)程計(jì)算機(jī)端口是否打開的方法

    C#檢測遠(yuǎn)程計(jì)算機(jī)端口是否打開的方法

    這篇文章主要介紹了C#檢測遠(yuǎn)程計(jì)算機(jī)端口是否打開的方法,實(shí)例分析了C#實(shí)現(xiàn)檢測遠(yuǎn)程端口開啟的技巧,需要的朋友可以參考下
    2015-03-03
  • C#精確計(jì)算年齡的方法分析

    C#精確計(jì)算年齡的方法分析

    這篇文章主要介紹了C#精確計(jì)算年齡的方法,實(shí)例分析了C#計(jì)算時(shí)間的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-03-03

最新評論

西贡区| 教育| 比如县| 南安市| 左贡县| 贡觉县| 江安县| 宁德市| 正镶白旗| 施甸县| 大悟县| 光泽县| 房产| 扶风县| 札达县| 绥宁县| 广昌县| 永宁县| 荥经县| 龙海市| 屏山县| 绥棱县| 朝阳市| 安阳市| 凯里市| 南宫市| 绥芬河市| 尼勒克县| 犍为县| 平罗县| 五峰| 常熟市| 万源市| 宜宾县| 安西县| 济南市| 桃源县| 临武县| 禹州市| 临邑县| 丹阳市|