把数据存放在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的更多相关文章

  1. 关于DOM的操作以及性能优化问题-重绘重排

     写在前面: 大家都知道DOM的操作很昂贵. 然后贵在什么地方呢? 一.访问DOM元素 二.修改DOM引起的重绘重排 一.访问DOM 像书上的比喻:把DOM和JavaScript(这里指ECMScri ...

  2. Sql Server系列:分区表操作

    1. 分区表简介 分区表在逻辑上是一个表,而物理上是多个表.从用户角度来看,分区表和普通表是一样的.使用分区表的主要目的是为改善大型表以及具有多个访问模式的表的可伸缩性和可管理性. 分区表是把数据按设 ...

  3. C# ini文件操作【源码下载】

    介绍C#如何对ini文件进行读写操作,C#可以通过调用[kernel32.dll]文件中的 WritePrivateProfileString()和GetPrivateProfileString()函 ...

  4. js学习笔记:操作iframe

    iframe可以说是比较老得话题了,而且网上也基本上在说少用iframe,其原因大致为:堵塞页面加载.安全问题.兼容性问题.搜索引擎抓取不到等等,不过相对于这些缺点,iframe的优点更牛,跨域请求. ...

  5. jquery和Js的区别和基础操作

    jqery的语法和js的语法一样,算是把js升级了一下,这两种语法可以一起使用,只不过是用jqery更加方便 一个页面想要使用jqery的话,先要引入一下jqery包,jqery包从网上下一个就可以, ...

  6. ASP.NET Aries 入门开发教程7:DataGrid的行操作(主键操作区)

    前言: 抓紧勤奋,再接再励,预计共10篇来结束这个系列. 上一篇介绍:ASP.NET Aries 入门开发教程6:列表数据表格的格式化处理及行内编辑 本篇介绍主键操作区相关内容. 1:什么时候有默认的 ...

  7. 如何在高并发环境下设计出无锁的数据库操作(Java版本)

    一个在线2k的游戏,每秒钟并发都吓死人.传统的hibernate直接插库基本上是不可行的.我就一步步推导出一个无锁的数据库操作. 1. 并发中如何无锁. 一个很简单的思路,把并发转化成为单线程.Jav ...

  8. 【翻译】MongoDB指南/CRUD操作(四)

    [原文地址]https://docs.mongodb.com/manual/ CRUD操作(四) 1 查询方案(Query Plans) MongoDB 查询优化程序处理查询并且针对给定可利用的索引选 ...

  9. 【翻译】MongoDB指南/CRUD操作(三)

    [原文地址]https://docs.mongodb.com/manual/ CRUD操作(三) 主要内容: 原子性和事务(Atomicity and Transactions),读隔离.一致性和新近 ...

  10. 【翻译】MongoDB指南/CRUD操作(二)

    [原文地址]https://docs.mongodb.com/manual/ MongoDB CRUD操作(二) 主要内容: 更新文档,删除文档,批量写操作,SQL与MongoDB映射图,读隔离(读关 ...

随机推荐

  1. 【转】移动端viewport的使用

    web端网站转移至移动端页面,注意点如下: 1.首先引入viewport调整页面宽度 <meta name="viewport" content="width=de ...

  2. 用dom4j解析xml 报java.lang.NoClassDefFoundError:org/jaxen/JaxenException

    转自:http://www.myexception.cn/java%20exception/95.html 源码如下: import java.io.File; import java.util.Li ...

  3. php url rewrite

    1.检测Apache是否支持mod_rewrite 通过php提供的phpinfo()函数查看环境配置,通过Ctrl+F查找到“Loaded Modules”,其中列出了所有apache2handle ...

  4. Dynamic CRM 2013学习笔记(四十二)流程5 - 实时/同步工作流(Workflow)用法图解

    实时工作流跟插件一样,也是用事件执行管道来执行,能在pre,post或核心操作中执行.跟插件一样,不能在创建之前和删除之后执行.如果执行过程中有异常发生,会取消并回滚整个操作.实时工作流里所有的活动和 ...

  5. UML中依赖(Dependency)和关联(Association)之间的区别

    一般情况下,使用关联(association)来表示像类中的字段等.这个关系是始终存在的,因此你可以随时针对关联项进行访问调用,例如可以始终从 Customer 对象获取 Order 对象.但事实上它 ...

  6. [学习笔记] Dispose模式

    Dispose模式是.NET中很基础也很重要的一个模式,今天重新复习一下相关的东西并记录下来. 什么是Dispose模式? 什么时候我们该为一个类型实现Dispose模式 使用Dispose模式时应该 ...

  7. [ACM_图论] 棋盘问题 (棋盘上放棋子的方案数)

    不能同行同列,给定形状和大小的棋盘,求摆放k个棋子的可行方案 Input 2表示是2X2的棋盘,1表示k,#表示可放,点不可放(-1 -1 结束) Output 输出摆放的方案数目C Sample I ...

  8. 分布式icinga2安装与使用

    目标 配置分布式的icinga2监控系统.分布式监控适用于服务器遍布在多个区域,且需要一个master做统一管理. 搭建环境 服务器 系统: ubuntu 15.04/ubuntu 14.04 ici ...

  9. cookie and session

    Session is used to save the message for the hole period of user dialogue in web service.Such as the ...

  10. AVL树(三)之 Java的实现

    概要 前面分别介绍了AVL树"C语言版本"和"C++版本",本章介绍AVL树的Java实现版本,它的算法与C语言和C++版本一样.内容包括:1. AVL树的介绍 ...