C#添加、隐藏Word段落_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > C#添加、隐藏Word段落

C#添加、隐藏Word段落

 2017/11/29 16:04:48  Miaonly  程序员俱乐部  我要评论(0)
  • 摘要:通过C#我们可以向Word文档添加新的段落或者隐藏段落。需要使用FreeSpire.Docfor.NET。这里使用的这个组件给程序员提供多种操作Word文档的方法。下面将具体介绍如何来添加和隐藏段落。本文转载自https://i.cnblogs.com/EditPosts.aspx?postid=67578841.添加段落效果对比:前:后:2.隐藏段落前后对比前:后:下面是全部代码:usingSpire.Doc;usingSpire.Doc.Documents;usingSpire.Doc
  • 标签:C#

通过C#我们可以向Word文档添加新的段落或者隐藏段落。需要使用Free Spire.Doc for .NET。这里使用的这个组件给程序员提供多种操作Word文档的方法。下面将具体介绍如何来添加和隐藏段落。本文转载自https://i.cnblogs.com/EditPosts.aspx?postid=6757884

?

1.添加段落效果对比:

前:


后:



?
?2.隐藏段落前后对比

前:



?后:



?下面是全部代码:

class="c#" name="code">using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

namespace insert_new_paragraph_and_hide
{
    class Program
    {
        static void Main(string[] args)
        {   //该部分为插入新段落的代码
            Document document = new Document();
            document.LoadFromFile(@"C:\Users\Administrator\Desktop\向日葵.docx", FileFormat.Docx);

            Paragraph paraInserted = document.Sections[0].AddParagraph();
            TextRange textRange1 = paraInserted.AppendText("向日葵的花语是——太阳、光辉、高傲、忠诚、爱慕、沉默的爱。向日葵又叫望日莲,一个很美的名字");
            textRange1.CharacterFormat.TextColor = Color.Blue;
            textRange1.CharacterFormat.FontSize = 15;
            textRange1.CharacterFormat.UnderlineStyle = UnderlineStyle.Dash;
            document.SaveToFile("result.docx", FileFormat.Docx);


            //该部分为隐藏段落的代码
            Document doc = new Document();
            doc.LoadFromFile(@"C:\Users\Administrator\Desktop\雏菊.docx", FileFormat.Docx);
            Section sec = doc.Sections[0];
            Paragraph para = sec.Paragraphs[sec.Paragraphs.Count - 1];
            for (int i = 0; i < para.ChildObjects.Count;i++)
            {
                (para.ChildObjects[i] as TextRange).CharacterFormat.Hidden = true;

            }

            doc.SaveToFile("result1.docx", FileFormat.Docx);

        }
    }
}

?

  • 大小: 177.1 KB
  • 大小: 184 KB
  • 大小: 180.1 KB
  • 大小: 178.9 KB
  • 查看图片附件
上一篇: 丁香园创始人李天天:影像与病理医生或将被取代 下一篇: 没有下一篇了!
发表评论
用户名: 匿名