成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

C#/VB.NET添加、讀取Word腳注/尾注

前言

腳注和尾注是對文本的補(bǔ)充說明。腳注一般位于頁面的底部,可以作為文檔某處內(nèi)容的注釋;尾注一般位于文檔的末尾,列出引文 的出處等。在本示例中將介紹如何來添加或刪除Word腳注。

成都創(chuàng)新互聯(lián)公司專注于威海網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠為您提供威海營銷型網(wǎng)站建設(shè),威海網(wǎng)站制作、威海網(wǎng)頁設(shè)計(jì)、威海網(wǎng)站官網(wǎng)定制、小程序定制開發(fā)服務(wù),打造威海網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供威海網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。

工具使用

Free Spire. Doc for .NET

第一步 dll引用

C# /VB.NET添加、讀取Word腳注/尾注

第二步 添加Word腳注、尾注

【C#】

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

namespace InsertFootnote_Doc
{
    class Program
    {
        static void Main(string[] args)
        {
            //新建一個(gè)word文檔對象并加載需要添加腳注尾注的word文檔
            Document document = new Document();
            document.LoadFromFile("sample.docx", FileFormat.Docx2010);

            //獲取第3個(gè)段落
            Paragraph paragraph = document.Sections[0].Paragraphs[2];

            //添加腳注
            Footnote footnote = paragraph.AppendFootnote(FootnoteType.Footnote);

            //查找指定字符串,并添加腳注
            DocumentObject obj = null;

            for (int i = 0; i < paragraph.ChildObjects.Count; i++)
            {
                obj = paragraph.ChildObjects[i];
                if (obj.DocumentObjectType == DocumentObjectType.TextRange)
                {
                    TextRange textRange = obj as TextRange;

                    if (textRange.Text == "中國——東盟自貿(mào)區(qū)框架")
                    {
                        //為添加腳注的字符串設(shè)置加粗格式
                        textRange.CharacterFormat.Bold = true;
                        //插入腳注
                        paragraph.ChildObjects.Insert(i + 1, footnote);
                        break;
                    }
                }
            }

            //添加腳注內(nèi)容被設(shè)置字體格式
            TextRange text = footnote.TextBody.AddParagraph().AppendText("2002年11月4日,朱镕基總理和東盟10國領(lǐng)導(dǎo)人共同簽署了《中國-東盟全面經(jīng)濟(jì)合作框架協(xié)議》,這標(biāo)志著中國與東盟的經(jīng)貿(mào)合作進(jìn)入了一個(gè)新的歷史階段。");
            text.CharacterFormat.FontName = "Arial Black";
            text.CharacterFormat.FontSize = 9;
            text.CharacterFormat.TextColor = Color.DarkGray;
            footnote.MarkerCharacterFormat.FontName = "Calibri";
            footnote.MarkerCharacterFormat.FontSize = 12;
            footnote.MarkerCharacterFormat.Bold = true;
            footnote.MarkerCharacterFormat.TextColor = Color.DarkGreen;

            //獲取第5段落
            Paragraph paragraph3 = document.Sections[0].Paragraphs[4];

            //添加尾注并設(shè)置尾注和格式
            Footnote endnote = paragraph3.AppendFootnote(FootnoteType.Endnote);

            TextRange text2 = endnote.TextBody.AddParagraph().AppendText("黨的十七大報(bào)告明確指出:“堅(jiān)持對外開放的基本國策,把‘引進(jìn)來’和‘走出去’更好地結(jié)合起來,擴(kuò)大開放領(lǐng)域,優(yōu)化開放結(jié)構(gòu),提高開放質(zhì)量,完善內(nèi)外聯(lián)動,互利共贏、安全高效的開放型經(jīng)濟(jì)體系,形成經(jīng)濟(jì)全球化條件下參與國際經(jīng)濟(jì)合作和競爭的新優(yōu)勢。");
            text2.CharacterFormat.FontName = "Arial Black";
            text2.CharacterFormat.FontSize = 9;
            text2.CharacterFormat.TextColor = Color.Black;
            endnote.MarkerCharacterFormat.FontName = "Calibri";
            endnote.MarkerCharacterFormat.FontSize = 12;
            endnote.MarkerCharacterFormat.Bold = false;
            endnote.MarkerCharacterFormat.TextColor = Color.DarkGreen;

            //保存并打開文檔
            document.SaveToFile("添加腳注尾注.docx", FileFormat.Docx2010);
            System.Diagnostics.Process.Start("添加腳注尾注.docx");
        }
    }
}

測試結(jié)果:
C# /VB.NET添加、讀取Word腳注/尾注

【VB.NET】

Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields
Imports System.Drawing

Namespace InsertFootnote_Doc

    Class Program

        Private Shared Sub Main(ByVal args As String())
            Dim document As Document = New Document()
            document.LoadFromFile("sample.docx", FileFormat.Docx2010)
            Dim paragraph As Paragraph = document.Sections(0).Paragraphs(2)
            Dim footnote As Footnote = paragraph.AppendFootnote(FootnoteType.Footnote)
            Dim obj As DocumentObject = Nothing
            For i As Integer = 0 To paragraph.ChildObjects.Count - 1
                obj = paragraph.ChildObjects(i)
                If obj.DocumentObjectType = DocumentObjectType.TextRange Then
                    Dim textRange As TextRange = TryCast(obj, TextRange)
                    If textRange.Text = "中國——東盟自貿(mào)區(qū)框架" Then
                        textRange.CharacterFormat.Bold = True
                        paragraph.ChildObjects.Insert(i + 1, footnote)
                        Exit For
                    End If
                End If
            Next

            Dim text As TextRange = footnote.TextBody.AddParagraph().AppendText("2002年11月4日,朱镕基總理和東盟10國領(lǐng)導(dǎo)人共同簽署了《中國-東盟全面經(jīng)濟(jì)合作框架協(xié)議》,這標(biāo)志著中國與東盟的經(jīng)貿(mào)合作進(jìn)入了一個(gè)新的歷史階段。")
            text.CharacterFormat.FontName = "Arial Black"
            text.CharacterFormat.FontSize = 9
            text.CharacterFormat.TextColor = Color.DarkGray
            footnote.MarkerCharacterFormat.FontName = "Calibri"
            footnote.MarkerCharacterFormat.FontSize = 12
            footnote.MarkerCharacterFormat.Bold = True
            footnote.MarkerCharacterFormat.TextColor = Color.DarkGreen
            Dim paragraph3 As Paragraph = document.Sections(0).Paragraphs(4)
            Dim endnote As Footnote = paragraph3.AppendFootnote(FootnoteType.Endnote)
            Dim text2 As TextRange = endnote.TextBody.AddParagraph().AppendText("黨的十七大報(bào)告明確指出:“堅(jiān)持對外開放的基本國策,把‘引進(jìn)來’和‘走出去’更好地結(jié)合起來,擴(kuò)大開放領(lǐng)域,優(yōu)化開放結(jié)構(gòu),提高開放質(zhì)量,完善內(nèi)外聯(lián)動,互利共贏、安全高效的開放型經(jīng)濟(jì)體系,形成經(jīng)濟(jì)全球化條件下參與國際經(jīng)濟(jì)合作和競爭的新優(yōu)勢。")
            text2.CharacterFormat.FontName = "Arial Black"
            text2.CharacterFormat.FontSize = 9
            text2.CharacterFormat.TextColor = Color.Black
            endnote.MarkerCharacterFormat.FontName = "Calibri"
            endnote.MarkerCharacterFormat.FontSize = 12
            endnote.MarkerCharacterFormat.Bold = False
            endnote.MarkerCharacterFormat.TextColor = Color.DarkGreen
            document.SaveToFile("添加腳注尾注.docx", FileFormat.Docx2010)
            System.Diagnostics.Process.Start("添加腳注尾注.docx")
        End Sub
    End Class
End Namespace

第三步 讀取腳注尾注

【C#】

using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.IO;
using System.Text;

namespace ReadFootnote_Doc
{
    class Program
    {
        static void Main(string[] args)
        {
            //創(chuàng)建Document類對象,加載需要測試的文檔
            Document document = new Document();
            document.LoadFromFile("添加腳注尾注.docx");
            //獲取文檔第一個(gè)section
            Section section = document.Sections[0];

            //實(shí)例化StringBuilder類 
            StringBuilder sb = new StringBuilder();

            //遍歷文檔中所有段落
            foreach (Paragraph paragraph in section.Paragraphs)
            {
                for (int i = 0, cnt = paragraph.ChildObjects.Count; i < cnt; i++)
                {
                    ParagraphBase pBase = paragraph.ChildObjects[i] as ParagraphBase;
                    if (pBase is Footnote)
                    {
                        //若需要讀取尾注,將此處FootnoteType.Footnote改成 FootnoteType.Endnote即可
                        if ((pBase as Footnote).FootnoteType == FootnoteType.Footnote)
                        {
                            foreach (Paragraph footPara in (pBase as Footnote).TextBody.Paragraphs)
                            {
                                sb.Append(footPara.Text);
                            }
                        }
                    }
                }
            }
            //將讀取內(nèi)容寫入文本并保存
            File.WriteAllText("FootNotes.txt", sb.ToString());
            //打開文檔
            System.Diagnostics.Process.Start("FootNotes.txt");
        }
    }
}

讀取腳注:
C# /VB.NET添加、讀取Word腳注/尾注

讀取尾注:

C# /VB.NET添加、讀取Word腳注/尾注

【VB.NET】

Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields
Imports System.IO
Imports System.Text

Namespace ReadFootnote_Doc

    Class Program

        Private Shared Sub Main(ByVal args As String())
            Dim document As Document = New Document()
            document.LoadFromFile("添加腳注尾注.docx")
            Dim section As Section = document.Sections(0)
            Dim sb As StringBuilder = New StringBuilder()
            For Each paragraph As Paragraph In section.Paragraphs
                While i < cnt
                    Dim pBase As ParagraphBase = TryCast(paragraph.ChildObjects(i), ParagraphBase)
                    If TypeOf pBase Is Footnote Then
                        If(TryCast(pBase, Footnote)).FootnoteType = FootnoteType.Footnote Then
                            For Each footPara As Paragraph In(TryCast(pBase, Footnote)).TextBody.Paragraphs
                                sb.Append(footPara.Text)
                            Next
                        End If
                    End If

                    i += 1
                End While
            Next

            File.WriteAllText("FootNotes.txt", sb.ToString())
            System.Diagnostics.Process.Start("FootNotes.txt")
        End Sub
    End Class
End Namespace

《本文完》

網(wǎng)站欄目:C#/VB.NET添加、讀取Word腳注/尾注
轉(zhuǎn)載源于:http://jinyejixie.com/article0/gpegoo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站收錄網(wǎng)站設(shè)計(jì)、外貿(mào)建站響應(yīng)式網(wǎng)站、網(wǎng)站維護(hù)服務(wù)器托管

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

手機(jī)網(wǎng)站建設(shè)
肇源县| 于田县| 涞源县| 公安县| 奇台县| 清原| 巴东县| 剑阁县| 乌苏市| 乃东县| 西和县| 恩平市| 洞头县| 迁安市| 石嘴山市| 石河子市| 丹凤县| 永兴县| 铜鼓县| 南郑县| 诏安县| 雅安市| 当涂县| 三台县| 麻阳| 蛟河市| 祁阳县| 于田县| 微博| 临沭县| 两当县| 石楼县| 淮北市| 吉安县| 金乡县| 渝中区| 萨嘎县| 松原市| 阿拉善右旗| 剑河县| 新化县|