利用Spire for .NET实现办公自动化——Spire.Doc

今天研究了一下E-ICEBLUE公司的Spire for .NET系列产品。我们可以通过利用这个系列的dll库文件轻松的实现办公自动化的需求,而且不需要安装相应的办公软件。有关于Spire .NET系列产品的介绍戳这里可以看到。下面我以Spire.Doc这个dll库为例,写一下它的使用过程(我的虚拟机上没有下载与安装Windows Office之类的办公软件):

1、下载Spire.Doc.Dll文件(下载地址):

2、将上面五个文件copy到项目的debug路径下:

2、这里我在VS中新建一个控制台类型的project并命名为SpireDocUse,右键项目->Add->Reference->Browse->选择Spire.Doc.dll文件,完成引用:

3、在项目中using这个dll库:

using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;

4、接下来就可以参考官网上的教程来操作了,这里举个例子。创建一个word文档->写入一些内容->设置一下样式,然后保存:

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

namespace SpireDocUse
{
    class Program
    {
        static void Main(string[] args)
        {
            //Configure path.
            string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            string filePath = desktopPath + @"\test.docx";
            string picPath = desktopPath + @"\wang.jpg";
            //Create a word document.
            Document doc = new Document();
            //Add a section.
            Section section = doc.AddSection();
            //Add a paragraph.
            Paragraph paragraph = section.AddParagraph();
            paragraph.AppendText("Spire is me.");
            //Add a comment.
            string content = "CNblog:http://www.cnblogs.com/LanTianYou/";
            Comment comment = paragraph.AppendComment(content);
            comment.Format.Author = "Tylan";
            //Set font style for the paragraph.
            ParagraphStyle style = new ParagraphStyle(doc);
            style.Name = "TylanFontStyle";
            style.CharacterFormat.FontName = "Batang";
            style.CharacterFormat.FontSize = 36;
            style.CharacterFormat.TextColor = Color.Green;
            doc.Styles.Add(style);
            paragraph.ApplyStyle(style.Name);
            //Insert a picture.
            DocPicture pic = paragraph.AppendPicture(Image.FromFile(picPath));
            pic.Width = 500;
            pic.Height = 500;
            //Add header.
            HeaderFooter header = doc.Sections[0].HeadersFooters.Header;
            Paragraph headerParagraph = header.AddParagraph();
            TextRange headerText = headerParagraph.AppendText("Spire header");
            headerText.CharacterFormat.FontSize = 18;
            headerText.CharacterFormat.TextColor = Color.Tomato;
            headerParagraph.Format.Borders.Bottom.BorderType = BorderStyle.ThinThinSmallGap;
            headerParagraph.Format.Borders.Bottom.Space = 0.15f;
            headerParagraph.Format.Borders.Color = Color.DarkGray;
            //Add footer.
            HeaderFooter footer = doc.Sections[0].HeadersFooters.Footer;
            Paragraph footerParagraph = footer.AddParagraph();
            TextRange footerText = footerParagraph.AppendText("Spire footer");
            footerText.CharacterFormat.FontSize = 18;
            footerText.CharacterFormat.TextColor = Color.Tomato;
            footerParagraph.Format.Borders.Top.BorderType = BorderStyle.ThinThinSmallGap;
            footerParagraph.Format.Borders.Top.Space = 0.15f;
            footerParagraph.Format.Borders.Color = Color.DarkGray;
            //Save the file.
            doc.SaveToFile(filePath, FileFormat.Docx);
        }
    }
}

运行结果(在桌面生成一个word文档):

在安有word的办公机打开这个文件:

通过以上的例子,我们实现了在无Office的环境下实现办公的需求。通过Spire.NET可以对word文档实现一系列的操作。除了Spire.Doc库还有很多的.NET组件我们都可以选择使用,可以在官网首页的.NET模块中看到:

 

在日常的工作中,我们可以像上述过程一样,对Spire.Doc库中封装好的API进行一次再封装,以满足我们的自动化需求。具体可以根据自己的需求来引用相应的Spire .NET组件进行完成。

转载于:https://www.cnblogs.com/LanTianYou/p/5070213.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spire.BarCode for .Net 是一款专业的免费条形码组件,专为.Net(C#, VB.NET, ASP.NET)开发人员设计,用于生成和读取一维和二维条形码。使用Spire.BarCode,开发编程人员可以迅速轻松地为.Net应用软件(ASP.NET, WinForms and Web Service)嵌入企业级的条形码功能。 Spire.BarCode提供了一个非常简单的方法来集成条形码处理功能。一行代码就可以生成、读取一维和二维条形码。Spire.BarCode支持包括Bitmap, JPG, PNG, EMF, TIFF, GIF and WMF等众多常用的图片格式。 主要功能: 1.强大的一维、二维条形码识别和生成功能 支持常用的线性条形码,二维条形码,邮政条形码,能从任何方向检测这些条形码。 2.高效生成和读取条形码图像 开发人员可根据需求创建Bitmap, JPG, PNG, EMF, TIFF, GIF and WMF等格式的条形码图像。 3.支持读取和编辑条形码,性能优越 开发人员可轻松地设置条形码图像的边框类型,边框颜色,样式,边距和宽度。同时,可以按任何角度旋转并生成高质量的条形码图像。 4.整合便捷 Spire.BarCode for .Net 可以被集成到任何.Net应用程序中,操作简单。有两种集成模式:API模式和组件模式  1) API模式仅使用一行代码即可创建和识别条形码  2) 组件模式使用可视化方式来创建条形码,随后将Spire.BarCode组件拖入.Net Windows或 ASP.NET Form中。 无需其他代码。 5.支持30多种不同类型的条形码。 友情提示:Spire.BarCode本身免费,如需商用或需去除E-iceblue的logo,请至http://www.e-iceblue.com/Download/download-barcode-for-net-now.html查看获得Key的方式

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值