几种常见C#操作Word表格操作有哪些呢?让我们来看看具体的实例演示:

  1. bool saveChange = false;
  2. //C#操作Word表格操作
  3. object missing = System.Reflection.Missing.Value;
  4. object template = (object)templateFilePath;
  5. object filename = (object)saveFilePath;
  6. object isVisible = missing;
  7. object readOnly = missing;
  8. object breakType = Word.WdBreakType.wdSectionBreakNextPage;
  9. object isSaveChange = (object)saveChange;
  10. Word.Document doc = null;
  11. //定义一个Word.Application 对象
  12. Word.Application WordApp = new Word.ApplicationClass();
  13. //C#操作Word表格操作之打开文档
  14. doc = WordApp.Documents.Open(ref template,
  15. ref missing,ref readOnly,ref missing,
  16. ref missing, ref missing, ref missing,
  17. ref missing, ref missing,ref missing,
  18. ref missing, ref isVisible, ref missing,
  19. ref missing, ref missing, ref missing);
  20. //C#操作Word表格操作之设置页眉文本
  21. WordApp.ActiveWindow.ActivePane.View.SeekView =
  22. Word.WdSeekView.wdSeekCurrentPageHeader;
  23. WordApp.Selection.WholeStory();
  24. WordApp.Selection.TypeText( this.m_titleText );
  25. WordApp.ActiveWindow.ActivePane.View.SeekView =
  26. Word.WdSeekView.wdSeekMainDocument;
  27. //页面设置,设置页面为纵向布局,设置纸张类型为A4纸
  28. doc.PageSetup.Orientation = Word.WdOrientation.wdOrientLandscape;
  29. doc.PageSetup.PageWidth = WordApp.CentimetersToPoints(29.7F);
  30. doc.PageSetup.PageHeight = WordApp.CentimetersToPoints(21F);
  31. //C#操作Word表格操作之创建表格及设置表格和单元格属性
  32. object autoFitBehavior = Word.WdAutoFitBehavior.wdAutoFitWindow;
  33. doc.Content.Tables.Add(
  34. WordApp.Selection.Range, totalCount + 1,
  35. totalField - keyCount_1, ref missing,
  36. ref autoFitBehavior);
  37. //C#操作Word表格操作之合并单元隔
  38. doc.Content.Tables[1].Cell(i+1,j).Select();
  39. object moveUnit = Word.WdUnits.wdLine;
  40. object moveCount = 1;
  41. object moveExtend = Word.WdMovementType.wdExtend;
  42. WordApp.Selection.MoveUp(ref moveUnit,
  43. ref moveCount, ref moveExtend);
  44. WordApp.Selection.Cells.Merge();
  45. WordApp.Selection.Cells.VerticalAlignment =
  46. Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
  47. doc.Content.Tables[1].Cell(i+1,1).Range.Text = “单元格内容填充”
  48. //添加表格行
  49. doc.Content.Tables[0].Rows.Add(ref beforeRow);
  50. //C#操作Word表格操作之添加表格列
  51. doc.Content.Tables[0].Columns.Add(ref beforeColumn);
  52. //文本居中
  53. WordApp.Selection.ParagraphFormat.Alignment =
  54. Word.WdParagraphAlignment.wdAlignParagraphCenter;
  55. WordApp.Selection.Cells.VerticalAlignment =
  56. Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
  57. //C#操作Word表格操作之选中单元格文字垂直居中
  58. oDoc.Tables.Add(tableLocation, 3, 4, ref oMissing, ref oMissing);
  59. Word.Table newTable = oDoc.Tables[1];
  60. object beforeRow = newTable.Rows[1];
  61. newTable.Rows.Add(ref beforeRow);
  62. Word.Cell cell = newTable.Cell(1, 1);
  63. cell.Merge(newTable.Cell(1, 2));

黄聪:C#操作Word表格的常见操作(转)的更多相关文章

  1. 转发:VB程序操作word表格(文字、图片)

    很多人都知道,用vb操作excel的表格非常简单,但是偏偏项目中碰到了VB操作word表格的部分,google.baidu搜爆了,都没有找到我需要的东西.到是搜索到了很多问这个问题的记录.没办法,索性 ...

  2. Java 操作Word表格——创建嵌套表格、添加/复制表格行或列、设置表格是否禁止跨页断行

    本文将对如何在Java程序中操作Word表格作进一步介绍.操作要点包括 如何在Word中创建嵌套表格. 对已有表格添加行或者列 复制已有表格中的指定行或者列 对跨页的表格可设置是否禁止跨页断行 创建表 ...

  3. Java 操作Word表格

    本文将对如何在Java程序中操作Word表格作进一步介绍.操作要点包括 如何在Word中创建嵌套表格. 对已有表格添加行或者列 复制已有表格中的指定行或者列 对跨页的表格可设置是否禁止跨页断行 创建表 ...

  4. c#操作word表格

    http://www.webshu.net/jiaocheng/programme/ASPNET/200804/6499.html <% if request("infoid" ...

  5. Delphi 操作word 表格

    var wordApp, WordDoc, WrdSelection, wrdtable: variant; strAdd: string; wdPar,wdRange:OleVariant; iCo ...

  6. Aspose.Word 操作word表格的行 插入行 添加行

    rows.insert或rows.add前row必须有单元格cell private void button3_Click(object sender, EventArgs e) {         ...

  7. Aspose.Words.Tables.Row类操作word表格行

    http://www.aspose.com/docs/display/wordsnet/Aspose.Words.Tables.Row+Class Retrieves the index of a r ...

  8. 黄聪:jquery.bootgrid表格插件有的属性(visibleInSelection、cssClass、headerCssClass、headerAlign)不能识别的解决办法

    主要是属性大小写问题,修改jquery.bootgrid.js文件,在function loadColumns()方法里面添加下面的语句就好了 data.headerAlign = data.head ...

  9. poi操作word文档文件操作

    import org.apache.poi.POITextExtractor; import org.apache.poi.hwpf.extractor.WordExtractor; //得到.doc ...

随机推荐

  1. OC语言description方法和sel

    OC语言description方法和sel 一.description方法 Description方法包括类方法和对象方法.(NSObject类所包含) (一)基本知识 -description(对象 ...

  2. ZJOI2015 一试。

    虽然早就知道会是这个结果,但是看到的成绩时候还是有些忧伤,奇迹果然还是没有发生. 想了想还是应该写篇博文 纪念一下这段经历. Day0: 报道之后直接去了宾馆,然后意外的发现冬令营时候的室友wxh就住 ...

  3. Rhel6-mpich2 hpc集群配置文档

    系统环境: rhel6 x86_64 iptables and selinux disabled 主机: 192.168.122.121 server21.example.com 192.168.12 ...

  4. JVM-类加载机制

    虚拟机类加载机制  虚拟机把描述的类的数据从class文件加载到内存后,并对数据进行校验,转换解析和初始化,最终形成可以被虚拟机直接使用的Java类型,这就是虚拟机的类加载机制.  类加载的时机 类被 ...

  5. int a

    系统编译之后所有的变量都存储到符号表中,并且每个表项被分配一个符号ID,一般也是数字的,可以根据该符号的ID直接访问符号的值内存中的数据都是二进制的,没有ASCII值ASCII只在为便于人的理解,对二 ...

  6. 关于VS中文件属性的解释

    生成操作(BuildAction) 属性:BuildAction 属性指示 Visual Studio .NET 在执行生成时对文件执行的操作.BuildAction 可以具有以下几个值之一: 无(N ...

  7. Android启动模式(三种)

    1,标准启动模式 通过任务栈,每点一次button,将每一个实例都压入,然后点返回键时候,就弹出之前压入的实例. 每一次的地址都是不同的 测试代码:通过创建一个button和textView来显示本身 ...

  8. C语言程序设计第一次作业

    同学们,我们已经留了两次实验了,请大家将这两次的实验课内容写成实验报告在截止日期前进行提交. 截止日期:2016-10-7 23:00 实验一: 编程打印5行的倒三角形,第一行打印9个*,第二行7个* ...

  9. css实现微信信息背景qq聊天气泡

    用css实现一个椭圆形状的背景框很好实现 css: div{ width:200px; height:80px; background-color: #78DDF8; border-radius:10 ...

  10. Maven工程中的右键team

    与资源库同步(S):在需要合并版本时使用 提交(C):本地代码写入源码库 更新(U):本地代码升级到服务器端版本 在点击更新时,请注意: 如果当前项目有改动(甚至是比原来多了一个空格),则此时无法更新 ...