利用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: Combination Sum IV && Summary: The Key to Solve DP
Given an integer array with all positive numbers and no duplicates, find the number of possible comb ...
- MST之kruskal算法
一.普里姆(Prim)算法 1.基本思想:设G=(V, E)是具有n个顶点的连通网,T=(U, TE)是G的最小生成树, T的初始状态为U={u0}(u0∈V),TE={},重复执行下述操作:在所有u ...
- ofbiz进击 。 ofbiz 退货流程(包含获取可退货项流程分析 以及 取消退货项的过程分析)
根据订单获取可退货项流程分析 退货的时候,调用 services_return.xml 中的获取可进行退货的退货项 getReturnableItems ,该服务调用了Java类 org.ofbi ...
- SQL中索引的原理
(一)深入浅出理解索引结构 实际上,您可以把索引理解为一种特殊的目录.微软的SQL SERVER提供了两种索引:聚集索引(clustered index,也称聚类索引.簇集索引 ...
- android EditText长按屏蔽ActionMode context菜单但保留选择工具功能
最近项目要求屏蔽EditText 长按出来的ActionMode菜单,但是要保留选择文本功能.这个屏蔽百度会出现各种方法,这里说一下我的思路: 1.屏蔽百度可知setCustomSelectionAc ...
- YbRapidSolution.Mvc判断不同用户登录不同页面
AccountController.cs using System; using System.Collections.Generic; using System.Linq; using System ...
- Oracle重置序列(不删除重建方式)
Oracle中一般将自增sequence重置为初始1时,都是删除再重建,这种方式有很多弊端,依赖它的函数和存储过程将失效,需要重新编译. 不过还有种巧妙的方式,不用删除,利用步长参数,先查出seque ...
- scan design flow(二)
在scan stitch之后,scan synthesis就已经完成, Scan extraction主要用来从scan design中extracing所有的instance,来保证scan cha ...
- jQuery基础之让出$,与其他库共存
在某些情况下,可能有必要在同一个页面中使用多个JS库,由于很多库都使用$标识符(因为他简短方便),因此就需要一种方式来避免名称冲突. 为解决这个问题,jQuery提供了一个名叫.noConflict( ...
- php 缓存加速器软件
Xcache 和 memcached 是两个不同层面的缓存,不存在可比性.Xcache 是 php 底层的缓存,它将PHP程式编译成字节码(byte code),再透过服务器上安装对应的程式来执行PH ...