利用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 = ;
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 = ;
pic.Height = ;
//Add header.
HeaderFooter header = doc.Sections[].HeadersFooters.Header;
Paragraph headerParagraph = header.AddParagraph();
TextRange headerText = headerParagraph.AppendText("Spire header");
headerText.CharacterFormat.FontSize = ;
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[].HeadersFooters.Footer;
Paragraph footerParagraph = footer.AddParagraph();
TextRange footerText = footerParagraph.AppendText("Spire footer");
footerText.CharacterFormat.FontSize = ;
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组件进行完成。
利用Spire for .NET实现办公自动化——Spire.Doc的更多相关文章
- 利用pdfbox和poi抽取pdf、doc以及docx格式的内容
使用pdfbox1.5.0抽取pdf格式文档内容,使用poi3.7抽取doc及docx文档内容: /** * Created by yan.shi on 2017/9/25. */ import or ...
- Spire.Doc组件
使用Spire.Doc组件利用模板导出Word文档 以前一直是用Office的组件实现Word文档导出,但是让客户在服务器安装Office,涉及到版权:而且Office安装,包括权限配置也是比较麻烦. ...
- 使用Spire.Doc来转换文本
使用Spire.Doc来转换文本 前段时间,我为不熟悉这个产品的读者们写了一篇关于我对 Spire.Doc的初识印象.Spire.Doc是一个专业的Word .NET库,它是专门为开发人员设计的用来快 ...
- C# 利用itextsharp、Spire配合使用为pdf文档每页添加水印
下载类库: 直接下载 引入类库 功能实现 using iTextSharp.text.pdf; using Spire.Pdf; using Spire.Pdf.Graphics; using Sys ...
- 使用Spire组件抛出异常The type initializer for 'spr857' threw an exception
使用Spire组件抛出异常The type initializer for 'spr857' threw an exception 我使用免费的Spire.Xls组件尝试去转换Excel文档到PDF文 ...
- 【原创】.NET读写Excel工具Spire.Xls使用(1)入门介绍
在.NET平台,操作Excel文件是一个非常常用的需求,目前比较常规的方法有以下几种: 1.Office Com组件的方式:这个方式非常累人,微软的东西总是这么的复杂,使用起来可能非常不便,需要安装E ...
- 【好文翻译】测试必看:使用Spire.XLS来生成自动化报表!
Download C# project - 7.1 KB 介绍 在我的编程博客中,我经常会比较不同算法或原理的性能特征.我常常会把性能日志(如花费时间)输出到控制台或者文本文件,然后复制到电子表格中 ...
- .NET读写Excel工具Spire.Xls使用(1)入门介绍
原文:[原创].NET读写Excel工具Spire.Xls使用(1)入门介绍 在.NET平台,操作Excel文件是一个非常常用的需求,目前比较常规的方法有以下几种: 1.Office Com组件的方式 ...
- 教程:关于如何通过Maven仓库安装Spire系列的 Java产品
Spire系列库中已发布的Java产品目前有三个,即Spire.PDF for Java.Spire.Presentation for Java.Spire.Barcode for Java.使用该J ...
随机推荐
- Leetcode: Convert a Number to Hexadecimal
Given an integer, write an algorithm to convert it to hexadecimal. For negative integer, two's compl ...
- html a标签链接使用action 参数传递中文乱码
<a href="queryByType?ptype=鼠标"> 在后台变量ptype接收的值为乱码 解决方法: 在tomcat的server.xml文件中添加 URIE ...
- ofbiz进击 第四节。 我的form之旅
一般使用ofbiz做后台管理的时候,多数会使用ofbiz的form去做后台.下面我就总结下我在使用form的时候的一些总结与问题吧. 1.首先,我们看如何使用最简单form去查询某个单个的对象,并对其 ...
- sqlserver 存储过程 以及统计整个数据库数据
drop proc test 删除存储过程 go 用于在 SSMS 和 SQLCMD 中将其之前的 T-SQL 语句作为一个批处理提交给 SQL Server 实例.GO 不是 T-SQL 语句,只 ...
- 。。。Hibernate中mappedBy属性。。。
今天在学习Hibernate中,感觉这个mappedBy这个注解属性有点小难度.不过理解之后,还是阔以的! 首先,mappedBy这个注解只能够用在@OntToOne,@OneToMany,@many ...
- linux tomcat 配置
http://www.cnblogs.com/xdp-gacl/p/4097608.html
- ArcGIS Engine中加载数据
ArcGIS Engine中加载数据 http://blog.csdn.net/gisstar/article/details/4206822 分类: AE开发积累2009-05-21 16:49 ...
- mysql取出现在的时间戳和时间时间戳转成人类看得懂的时间
mysql取出现在的时间戳和时间时间戳转成人类看得懂的时间,我们在mysql里面他封装了一个内置的时间戳转化的函数,比如我们现在的时间戳是:1458536709 ,"%Y-%m-%d&quo ...
- PTPX中的activity文件以及mapping文件
在不同的simulation中的capturing switching activity: SAIF:Switching Activity Interface Format,包含toggle coun ...
- zw·准专利·高保真二值图细部切分算法
zw·准专利·高保真二值图细部切分算法 高保真二值图细部切分算法,是中国字体协会项目的衍生作品. 说准专利算法,是因为对于图像算法的标准不了解,虽然报过专利,但不是这方面的,需要咨询专 ...