利用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: Strobogrammatic Number III
A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside ...
- zabbix监控路由器所有接口信息
zabbix监控路由器所有接口信息 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 1.首先在服务器端安装snmp工具 [root@bogon yinzhengjie]# yum - ...
- 设置 BitmapData 没填充部分为透明色
默认 BitmapData 是以白色填充的 在初始化时,设定上每3,4个参数即可透明: new BitmapData(w,h,true,0) 第4个参数要为0
- 使用PHP发送邮件
使用封装SMTP协议的邮件类 使用PEAR扩展中的Mail类,功能强大:可以支持纯文本.HTML格式的邮件:各字段都可设置编码,正确配置不会出现中文乱码情况:可以支持附件等等. 在服务器可以使用 pe ...
- paper 54 :图像频率的理解
我一直在思考一个问题,图像增强以后,哪些方面的特征最为显著,思来想去,无果而终!翻看了一篇知网的paper,基于保真度(VIF)的增强图像质量评价,文章中指出无参考质量评价,可以从三个方面考虑:平均梯 ...
- paper 44 :颜色矩和颜色相关图(color correlogram)
- XMLHttpRequest Level2实现跨域
Html5提供的XMLHttpRequest Level2已经实现的跨域访问以及一些新功能 1.ie10以下版本不支持 2.在服务器端做一些小改动即可: header("Access-Con ...
- mongo自带测试
benchrun > res = benchRun({ ops:[{ ns:"test.foo", op:"insert", doc:{y:{,]}} } ...
- (第九周)视频发布及git统计报告
项目名:食物链教学工具 组名:奋斗吧兄弟 组长:黄兴 组员:李俞寰.杜桥.栾骄阳.王东涵 代码地址:HTTPS: https://git.coding.net/li_yuhuan/FoodChain. ...
- Headless MSBuild Support for SSDT (*.sqlproj) Projects
http://sqlproj.com/index.php/2012/03/headless-msbuild-support-for-ssdt-sqlproj-projects/ Update: bre ...