c#生成word文档
参考:http://blog.163.com/zhouchunping_99/blog/static/7837998820085114394716/
- 生成word文档
生成word文档
view plaincopy to clipboardprint?
- public class BiultReportForm
- {
- /// <SUMMARY></SUMMARY>
- /// word 应用对象
- ///
- private Microsoft.Office.Interop.Word.Application _wordApplication;
- /// <SUMMARY></SUMMARY>
- /// word 文件对象
- ///
- private Microsoft.Office.Interop.Word.Document _wordDocument;
- /// <SUMMARY></SUMMARY>
- /// 创建文档
- ///
- public void CreateAWord()
- {
- //实例化word应用对象
- this._wordApplication = new Microsoft.Office.Interop.Word.ApplicationClass();
- Object myNothing = System.Reflection.Missing.Value;
- this._wordDocument = this._wordApplication.Documents.Add(ref myNothing, ref myNothing, ref myNothing, ref myNothing);
- }
- /// <SUMMARY></SUMMARY>
- /// 添加页眉
- ///
- /// <PARAM name="pPageHeader" />
- public void SetPageHeader(string pPageHeader)
- {
- //添加页眉
- this._wordApplication.ActiveWindow.View.Type =Microsoft .Office .Interop .Word.WdViewType.wdOutlineView;
- this._wordApplication.ActiveWindow.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekPrimaryHeader;
- this._wordApplication.ActiveWindow.ActivePane.Selection.InsertAfter(pPageHeader);
- //设置中间对齐
- this._wordApplication.Selection.ParagraphFormat.Alignment =Microsoft .Office .Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
- //跳出页眉设置
- this._wordApplication.ActiveWindow.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekMainDocument;
- }
- /// <SUMMARY></SUMMARY>
- /// 插入文字
- ///
- /// <PARAM name="pText" />文本信息
- /// <PARAM name="pFontSize" />字体打小
- /// <PARAM name="pFontColor" />字体颜色
- /// <PARAM name="pFontBold" />字体粗体
- /// <PARAM name="ptextAlignment" />方向
- public void InsertText(string pText, int pFontSize, Microsoft.Office.Interop.Word.WdColor pFontColor, int pFontBold, Microsoft.Office.Interop.Word.WdParagraphAlignment ptextAlignment)
- {
- //设置字体样式以及方向
- this._wordApplication.Application.Selection.Font.Size = pFontSize;
- this._wordApplication.Application.Selection.Font.Bold = pFontBold;
- this._wordApplication.Application.Selection.Font.Color= pFontColor;
- this._wordApplication.Application.Selection.ParagraphFormat.Alignment = ptextAlignment;
- this._wordApplication.Application.Selection.TypeText(pText);
- }
- /// <SUMMARY></SUMMARY>
- /// 换行
- ///
- public void NewLine()
- {
- //换行
- this._wordApplication.Application.Selection.TypeParagraph();
- }
- /// <SUMMARY></SUMMARY>
- /// 插入一个图片
- ///
- /// <PARAM name="pPictureFileName" />
- public void InsertPicture(string pPictureFileName)
- {
- object myNothing = System.Reflection.Missing.Value;
- //图片居中显示
- this._wordApplication.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
- this._wordApplication.Application.Selection.InlineShapes.AddPicture(pPictureFileName, ref myNothing, ref myNothing, ref myNothing);
- }
- /// <SUMMARY></SUMMARY>
- /// 保存文件
- ///
- /// <PARAM name="pFileName" />保存的文件名
- public void SaveWord(string pFileName)
- {
- object myNothing = System.Reflection.Missing.Value;
- object myFileName = pFileName;
- object myWordFormatDocument =Microsoft .Office .Interop .Word.WdSaveFormat.wdFormatDocument;
- object myLockd = false;
- object myPassword = "";
- object myAddto = true;
- try
- {
- this._wordDocument.SaveAs(ref myFileName, ref myWordFormatDocument, ref myLockd, ref myPassword, ref myAddto, ref myPassword,
- ref myLockd, ref myLockd, ref myLockd, ref myLockd, ref myNothing, ref myNothing, ref myNothing,
- ref myNothing, ref myNothing, ref myNothing);
- }
- catch
- {
- throw new Exception("导出word文档失败!");
- }
- }
- }
c#生成word文档的更多相关文章
- Aspose.Words简单生成word文档
Aspose.Words简单生成word文档 Aspose.Words.Document doc = new Aspose.Words.Document(); Aspose.Words.Documen ...
- ASP.NET生成WORD文档,服务器部署注意事项
网上转的,留查备用,我服务器装的office2007所以修改的是Microsoft Office word97 - 2003 文档这一个. ASP.NET生成WORD文档服务器部署注意事项 1.Asp ...
- POI生成WORD文档
h2:first-child, body>h1:first-child, body>h1:first-child+h2, body>h3:first-child, body>h ...
- PowerDesigner将PDM导出生成WORD文档
PowerDesigner将PDM导出生成WORD文档 环境 PowerDesigner15 1.点击Report Temlates 制作模板 2.如果没有模板,单击New图标创建.有直接双击进入. ...
- velocity模板技术生成word文档
本文介绍採用velocity技术在Java中生成word文档的方法. 1.新建一个word文档,编辑内容例如以下: 2.将上述word文档另存为htm格式的文件 3.新建一个Java Project项 ...
- 使用C#动态生成Word文档/Excel文档的程序测试通过后,部署到IIS服务器上,不能正常使用的问题解决方案
使用C#动态生成Word文档/Excel文档的程序功能调试.测试通过后,部署到服务器上,不能正常使用的问题解决方案: 原因: 可能asp.net程序或iis访问excel组件时权限不够(Ps:Syst ...
- 用php生成word文档
一.用windows里面自带的com,然后用php生成word文档 <?php $word= new COM("word.application") or die(" ...
- 将HTML导出生成word文档
前言: 项目开发中遇到了需要将HTML页面的内容导出为一个word文档,所以有了这边随笔. 当然,项目开发又时间有点紧迫,第一时间想到的是用插件,所以百度了下.下面就介绍两个导出word文档的方法. ...
- POI生成word文档完整案例及讲解
一,网上的API讲解 其实POI的生成Word文档的规则就是先把获取到的数据转成xml格式的数据,然后通过xpath解析表单式的应用取值,判断等等,然后在把取到的值放到word文档中,最后在输出来. ...
随机推荐
- EL表达式语言
EL (Expression Language) 目的:为了使JSP写起来更加简单.表达式语言的灵感来自于 ECMAScript 和 XPath 表达式语言,它提供了在 JSP 中简化表达式的方法. ...
- Linux经常使用的命令-权利管理命令-权利管理命令chmod
指令名字:chmod 命令英语的意图:change the permissions mode of a file 凡路径命令:/bin/chmod 语法:chmod [{ugoa}{+-=}{rwx} ...
- LESS使用介绍
使用: 在客户端使用 引入你的 .less 样式文件的时候要设置 rel 属性值为 "stylesheet/less": <link rel="stylesheet ...
- easyUI 插件写法 ---Validatebox 插件为例
easyui 的每个组件都有属性.方法和事件.用户可以很容易地对这些组件进行扩展. js地址:jquery-easyui-1.3.3/jeasyui-extensions/jeasyui.extens ...
- SQL Server---触发
今天的第一次SQL Server触发感觉很方便,本文将向您介绍一个简单的SQL Server触发器和简单的使用. 我将确定其.原理.使用细节都是关于. 定义 触发器(trigger)是个特殊的存储过程 ...
- 一个数据表对象(NSManagedObject)加入排序
eg:数据库表对象 @interface Meditation : NSManagedObject @property (nonatomic, retain) NSString * order;//用 ...
- asp.net 百度编辑器 UEditor 上传图片 图片上传配置 编辑器配置 网络连接错误,请检查配置后重试
1.配置ueditor/editor_config.js文件,将 //图片上传配置区 ,imageUrl:URL+"net/imageUp.ashx" //图片上传提交地址 ,im ...
- 读取xml文件"分析 EntityName 时出错"的解决方案
在涉及到xml与xslt编程的过程中,经常会碰到"分析 EntityName 时出错"的提示,这个不是程序错误,是因为xml文件中使用了一些特殊符号导致的. XML 节点中不 ...
- jquery 访问控制菜单
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaHpqOTExOA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA ...
- 聊聊单元測试(一)——EasyMock
一.单元測试是保证软件质量的重要方法. 单元測试是对系统中某个模块功能的验证,但我们总会遇到这样那样的问题,导致測试代码非常难编写.最直接的一个原因便是强耦合关系,被測试者依赖一些不easy构造,比較 ...