关于 c# 操作 world
把数据存放在datatable 中并循环取出来数据然后再保存在world中
protected void ExportToWord(DataSet Ads)
{
try
{ Object Nothing = System.Reflection.Missing.Value;
//Directory.CreateDirectory("C:/CNSI"); //创建文件所在目录
//string name = "CNSI_" + "53asdf" + ".doc";
//object filename = "C://CNSI//" + name; //文件保存路径
//创建Word文档
Word.Application WordApp = new Word.ApplicationClass();
Word.Document WordDoc = WordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);
WordApp.Selection.ParagraphFormat.LineSpacing = 15f;//设置文档的行间距 int k = ; //文档中创建表格
for (int i = ; i < ; i++)
{ //表头
Word.Table newTableH = WordDoc.Tables.Add(WordApp.Selection.Range, , , ref Nothing, ref Nothing);
newTableH.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleNone;
newTableH.Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleNone;
//填充表格内容
newTableH.Cell(, ).Range.Text = "班组交接记录表";
newTableH.Cell(, ).Range.Bold = ;//设置单元格中字体为粗体
WordApp.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;//水平居中
k += ;
object countH = (object)k;
object WdLineH = Word.WdUnits.wdLine;//换一行;
WordApp.Selection.MoveDown(ref WdLineH, ref countH, ref Nothing);//移动焦点
WordApp.Selection.TypeParagraph();//插入段落 //时间
Word.Table newTableT = WordDoc.Tables.Add(WordApp.Selection.Range, , , ref Nothing, ref Nothing);
newTableT.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleNone;
newTableT.Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleNone;
WordApp.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight;//水平居中
//填充表格内容
newTableT.Cell(, ).Range.Text = "2013年3月1日";
newTableT.Cell(, ).Range.Bold = ;//设置单元格中字体为粗体
k += ;
object countT = (object)k;
object WdLineT = Word.WdUnits.wdLine;//换一行;
WordApp.Selection.MoveDown(ref WdLineT, ref countT, ref Nothing);//移动焦点
WordApp.Selection.TypeParagraph();//插入段落 //主界面
Word.Table newTable = WordDoc.Tables.Add(WordApp.Selection.Range, , , ref Nothing, ref Nothing);
newTable.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleSingle;
newTable.Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleDot;
WordApp.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft;//水平居中
//填充表格内容
newTable.Cell(, ).Range.Text = "岗位人员:";
newTable.Cell(, ).Range.Bold = ;//设置单元格中字体为粗体 newTable.Cell(, ).Range.Text = "岗位班前交接内容:";
newTable.Cell(, ).Range.Bold = ;//设置单元格中字体为粗体 newTable.Cell(, ).Range.Text = "本班生产运行情况:";
newTable.Cell(, ).Range.Bold = ;//设置单元格中字体为粗体 newTable.Cell(, ).Range.Text = "上级工作指令:";
newTable.Cell(, ).Range.Bold = ;//设置单元格中字体为粗体 newTable.Cell(, ).Range.Text = "横向联系记录:";
newTable.Cell(, ).Range.Bold = ;//设置单元格中字体为粗体 newTable.Cell(, ).Range.Text = "存在的问题及处理情况:";
newTable.Cell(, ).Range.Bold = ;//设置单元格中字体为粗体 newTable.Cell(, ).Range.Text = "下班注意事项:";
newTable.Cell(, ).Range.Bold = ;//设置单元格中字体为粗体 newTable.Cell(, ).Range.Text = "班后交接内容:";
newTable.Cell(, ).Range.Bold = ;//设置单元格中字体为粗体 newTable.Cell(, ).Range.Text = "工具用具是否完好、齐全:";
newTable.Cell(, ).Range.Bold = ;//设置单元格中字体为粗体 newTable.Cell(, ).Range.Text = "岗位卫生情况是否合格:";
newTable.Cell(, ).Range.Bold = ;//设置单元格中字体为粗体 newTable.Cell(, ).Range.Text = "岗位防护用品是否完好:";
newTable.Cell(, ).Range.Bold = ;//设置单元格中字体为粗体 newTable.Cell(, ).Range.Text = "消防器材及设施是否完好:";
newTable.Cell(, ).Range.Bold = ;//设置单元格中字体为粗体 newTable.Cell(, ).Range.Text = "交班签名:" + "****" + "接班签名" + "***";
newTable.Cell(, ).Range.Bold = ;//设置单元格中字体为粗体 k += ;
object count = (object)k;
object WdLine = Word.WdUnits.wdLine;//换一行;
WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点
WordApp.Selection.TypeParagraph();//插入段落
object breakPage = Microsoft.Office.Interop.Word.WdBreakType.wdPageBreak;
WordApp.Selection.InsertBreak(ref breakPage); } //文件保存
//WordDoc.SaveAs(ref filename, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);
WordDoc.Close(ref Nothing, ref Nothing, ref Nothing);//保存
WordApp.Quit(ref Nothing, ref Nothing, ref Nothing);//结束进程 }
catch (Exception ex)
{
StreamOperate.StreamWrite("交接班记录查询", "ExportToWord", ex.Message, ex.StackTrace);
} }
Ads 为从数据库中取出来的数据,我这里用了10个班组记录做的例子。只需赋值就可以。 参考网址:http://hi.baidu.com/ishlzjpduibcuyd/item/8637d50e428d4ceb359902b7 http://m.blog.csdn.net/blog/huguoqun/9332177
http://www.cnblogs.com/koolay/articles/1398110.html
关于 c# 操作 world的更多相关文章
- 关于DOM的操作以及性能优化问题-重绘重排
写在前面: 大家都知道DOM的操作很昂贵. 然后贵在什么地方呢? 一.访问DOM元素 二.修改DOM引起的重绘重排 一.访问DOM 像书上的比喻:把DOM和JavaScript(这里指ECMScri ...
- Sql Server系列:分区表操作
1. 分区表简介 分区表在逻辑上是一个表,而物理上是多个表.从用户角度来看,分区表和普通表是一样的.使用分区表的主要目的是为改善大型表以及具有多个访问模式的表的可伸缩性和可管理性. 分区表是把数据按设 ...
- C# ini文件操作【源码下载】
介绍C#如何对ini文件进行读写操作,C#可以通过调用[kernel32.dll]文件中的 WritePrivateProfileString()和GetPrivateProfileString()函 ...
- js学习笔记:操作iframe
iframe可以说是比较老得话题了,而且网上也基本上在说少用iframe,其原因大致为:堵塞页面加载.安全问题.兼容性问题.搜索引擎抓取不到等等,不过相对于这些缺点,iframe的优点更牛,跨域请求. ...
- jquery和Js的区别和基础操作
jqery的语法和js的语法一样,算是把js升级了一下,这两种语法可以一起使用,只不过是用jqery更加方便 一个页面想要使用jqery的话,先要引入一下jqery包,jqery包从网上下一个就可以, ...
- ASP.NET Aries 入门开发教程7:DataGrid的行操作(主键操作区)
前言: 抓紧勤奋,再接再励,预计共10篇来结束这个系列. 上一篇介绍:ASP.NET Aries 入门开发教程6:列表数据表格的格式化处理及行内编辑 本篇介绍主键操作区相关内容. 1:什么时候有默认的 ...
- 如何在高并发环境下设计出无锁的数据库操作(Java版本)
一个在线2k的游戏,每秒钟并发都吓死人.传统的hibernate直接插库基本上是不可行的.我就一步步推导出一个无锁的数据库操作. 1. 并发中如何无锁. 一个很简单的思路,把并发转化成为单线程.Jav ...
- 【翻译】MongoDB指南/CRUD操作(四)
[原文地址]https://docs.mongodb.com/manual/ CRUD操作(四) 1 查询方案(Query Plans) MongoDB 查询优化程序处理查询并且针对给定可利用的索引选 ...
- 【翻译】MongoDB指南/CRUD操作(三)
[原文地址]https://docs.mongodb.com/manual/ CRUD操作(三) 主要内容: 原子性和事务(Atomicity and Transactions),读隔离.一致性和新近 ...
- 【翻译】MongoDB指南/CRUD操作(二)
[原文地址]https://docs.mongodb.com/manual/ MongoDB CRUD操作(二) 主要内容: 更新文档,删除文档,批量写操作,SQL与MongoDB映射图,读隔离(读关 ...
随机推荐
- nginx 版本介绍
Nginx官网提供了三个类型的版本Mainline version:Mainline 是 Nginx 目前主力在做的版本,可以说是开发版Stable version:最新稳定版,生产环境上建议使用的版 ...
- java中的内部类小结
内部类不是很好理解,但说白了其实也就是一个类中还包含着另外一个类.如同一个人是由大脑.肢体.器官等身体结果组成,而内部类相当于其中的某个器官之一,例如心脏:它也有自己的属性和行为(血液.跳动).显然, ...
- Win7(32/64)VS2010配置编译GDAL环境(图文教程+亲测可用!)
最近的一个VS2010的项目中用到了GDAL,关于GDAL这个库的说明与赞美,这里就不赘述了,下面是在VS2010中配置GDAL的详细过程. 系统说明 Win7(32位/64位),VS2010,GDA ...
- SpringMVC中使用DWR
SpringMVC中使用DWR重点在其配置当中. 1. web.xml文件的配置 在DispatcherServlet中增加dwr的拦截来取代DwrServlet. 更改配置如下: <serv ...
- Divide Two Integers leetcode
题目:Divide Two Integers Divide two integers without using multiplication, division and mod operator. ...
- Poj-2250-Compromise
题意是找两篇文章中的最长子单词序列 能得出个数,但不知如何输出,找不到路径 看了别人的dfs,有所领悟: 若输入s1:ab,bd,fk,ce,ak,bt,cv s2: ab,fk,ce,tt,ak,b ...
- hdu 4648 - Magic Pen 6(“水”题)
摘自题解: 题意转化一下就是: 给出一列数a[1]...a[n],求长度最长的一段连续的数,使得这些数的和能被M整除. 分析: 设这列数前i项和为s[i], 则一段连续的数的和 a[i]+a[i+1] ...
- Vmware Vsphere WebService SDK开发(第一讲)-基本知识学习
刚开始这方面开发的时候,不知道如何下手,能够查到的资料特别少,而且看到很多网友和我一样也在找这方面的资料.接下来的一段时间我就结合自己所参与的项目,完成关于Vmware Vsphere WebServ ...
- 从分析SQLSERVER ERRORLOG查找错误折射出的工作效率问题
从分析SQLSERVER ERRORLOG查找错误折射出的工作效率问题 前几天,在备份某一台服务器上的某一个库的时候遇到问题,数据库80G+,在完整备份的时候,SQLSERVER报错 消息 ,级别 , ...
- Linux下oracle11gR2系统安装到数据库建立配置及最后oracle的dmp文件导入一站式操作记录
简介 之前也在linux下安装过oralce,可每次都是迷迷糊糊的,因为大脑一片空白,网上随便看见一个文档就直接复制,最后搞了乱七八糟,虽然装上了,却乱得很,现在记录下来,希望能给其他网上朋友遇到问题 ...