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文档中,最后在输出来. ...
随机推荐
- 配置Apacheserver
配置Apacheserver 一.目的 能够有一个測试的server,不是全部的特殊网络服务都能找到免费得! 二.为什么我们要用"Apache"? Apache是眼下使用最广的we ...
- POJ - 2828 Buy Tickets (段树单点更新)
Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must get ...
- 使用requirejs实现模块化编程
> 序言 - -# 公司大了,业务多了,前端代码量也逐渐增大,我们渐渐的依赖js实现的交互越来越多,长期以来会导致我们的代码维护越来越困难,所以依赖的插件也越来越多..比如这样页面中有大量的js ...
- 配置主机路由表(route)(两)
我们谈到了路由在互联网为基础的时间问题,必须有一个路径之间的两个主机可通信 TCP/IP 合约,否则就不能是有线啊! 一般来说.只要有一个网络接口,的接口将产生的路由.例如,在哥斯达黎加的内部主机鸟有 ...
- MVC客户管理(添加、修改、查询、分页)
ASP.NET MVC搭建项目后台UI框架—6.客户管理(添加.修改.查询.分页) 目录 ASP.NET MVC搭建项目后台UI框架—1.后台主框架 ASP.NET MVC搭建项目后台UI框架—2 ...
- C# 使用 Code Snippet 简化 Coding
在开发的项目的时候,你是否经常遇到需要重复编写一些类似的代码,比如是否经常会使用 for.foreach ? 在编写这两个循环语句的时候,你是一个字符一个字符敲还是使用 Visual Studio 提 ...
- hdu More is better
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1856 题意:王老师要找一些男生帮助他完成一项工程.要求最后挑选出的男生之间都是朋友关系,可以说直接的, ...
- BZOJ 1004 HNOI2008 Cards Burnside引理
标题效果:特定n张卡m换人,编号寻求等价类 数据保证这m换人加上置换群置换后本身构成 BZOJ坑爹0.0 条件不那么重要出来尼玛怎么做 Burnside引理--昨晚为了做这题硬啃了一晚上白书0.0 都 ...
- iOS开发分析"秘密"App内容页面的效果(两)
@我前几天写的"秘密"的Cell制品的效果,想要的效果还是有差距,并且扩展性非常不好,于是重写封装,把总体视图都放到scrollView中,基本是和secret app 一模一样的 ...
- java_前端_autocomplete_搜索框自动匹配提示
效果图: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> < ...