Microsoft.Office.Interop.Word.Application wordApp = new ApplicationClass()

word对象

2、 Microsoft.Office.Interop.Word.Document wordDoc = wordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing) 文档对象

3、 Object Nothing = System.Reflection.Missing.Value 常用的一个参数

4、wordApp.ActiveWindow.ActivePane.View.SeekView = WdSeekView.

wdSeekCurrentPageHeader定位到页眉

5、 wordApp.Selection.ParagraphFormat. Borders[WdBorderType.wdBorderBottom]

.LineStyle = WdLineStyle.wdLineStyleNone去掉页眉线

6、wordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument跳出页眉

7、 wordApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.

wdAlignParagraphCenter对齐方式(此为居中)

8、 Microsoft.Office.Interop.Word.Table policyTab = wordDoc.Tables.Add

(wordApp.Selection.Range, 行数, 列, ref Nothing, ref Nothing);创建表格

9、 wordApp.Selection.GoTo(ref oGoToItem, ref oGoToLast, ref Nothing, ref Nothing);定位页面(此为将光标定位到内容的最后)

10、 wordApp.Selection.InsertBreak(ref Nothing);插入分节符

11、 wordApp.Selection.InsertFile(nofile, ref Nothing, ref contenFalse, ref contenFalse, ref contenFalse);插入文件

12、 wordApp.Selection.InlineShapes.AddPicture(picName, ref LinkToFile, ref SaveWithDocument, ref Nothing);插入图片

13、 wordApp.ActiveWindow.ActivePane.View.SeekView = WdSeekView.

wdSeekCurrentPageFooter;定位到页脚

14、 wordApp.Selection.TypeText("此处写需要在指定位置输出的文字");文本输入

15、 wordDoc.ComputeStatistics(WdStatistic.wdStatisticPages, ref Nothing);得到页码

16、 wordDoc.PrintOut(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,

ref Nothing, ref Nothing, ref Nothing);

调用打印机实现打印(调用的是默认打印机)

17、 wordDoc.Close(ref saveChanges, ref Nothing, ref Nothing);文档退出

18、 wordApp.Quit(ref Nothing, ref Nothing, ref Nothing);word程序退出

doc.pageSetip.OddAndEvenPagesHeaderFooter=-1;//奇偶页不同

//去掉页脚

doc.Sections[1].Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Text="";

doc.Sections[1].Footers[WdHeaderFooterIndex.wdHeaderFooterEvenPages].Range.Text="";

//页码

object leftAlign=WdPageNumberAlignment.wdAlignPageNumberInside;

object rightAlign=WdPageNumberAlignment.wdAlignPageNumberoutside;

doc.Sections[1].Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary].PageNumbers.Add(ref leftAlign);

doc.Sections[1].Footers[WdHeaderFooterIndex.wdHeaderFooterEvenpages].PageNumbers.Add(ref rightAlign);

// 页码样式“- 1 -”

doc.Sections[1].Footers[WdHeaderFooterIndex.wdHeaderFooterEvenpages].PageNumbers.NumberStyle=WdPageNumberStyle.wdPageNumberStyleNumberInDash;

//页码的字号字体颜色

doc.Sections[1].Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Font.Size=14;

doc.Sections[1].Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Font.Bold=0;

doc.Sections[1].Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Font.Color=Word.WdColor.wdColorBlack;

doc.Sections[1].Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Font.Name="宋体";

//去掉页眉横线

doc.Sections[1].Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Paragraphs[1].Format.Borders[WdBorderType.wdBorderBottom].Color=WdColor.wdColorBlack;

doc.Sections[1].Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Paragraphs[1].Format.Borders[WdBorderType.wdBorderBottom].LineStyle=WdLineStyle.wdLineStyleNone;

doc.Sections[1].Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Paragraphs[1].Format.Borders[WdBorderType.wdBorderBottom].LineWidth=WdLineWidth.wdLineWidth050pt;

C#操作word的一些基本方法(word打印,插入文件,插入图片,定位页眉页脚,去掉横线)的更多相关文章

  1. C# 操作Word页眉页脚——奇偶页/首页不同、不连续设置页码、复制页眉页脚、锁定页眉页脚、删除页眉页脚

    前言 本文是对Word页眉页脚的操作方法的进一步的阐述.在“C# 添加Word页眉页脚.页码”一文中,介绍了添加简单页眉页脚的方法,该文中的方法可满足于大多数的页眉页脚添加要求,但是对于比较复杂一点的 ...

  2. C#word(2007)操作类--新建文档、添加页眉页脚、设置格式、添加文本和超链接、添加图片、表格处理、文档格式转化

    转:http://www.cnblogs.com/lantionzy/archive/2009/10/23/1588511.html 1.新建Word文档 #region 新建Word文档/// &l ...

  3. 使用C#在word中插入页眉页脚

    //插入页脚 public void InsertFooter(string footer) { if (ActiveWindow.ActivePane.View.Type == WdViewType ...

  4. 在C#中实现Word页眉页脚的全部功能

    页眉页脚经常使用于文章排版,在Word工具栏里.我们能够加入页眉,页脚,页码,日期和时间.图片等信息和内容.页眉/页脚有两个额外选项:首页不同,奇偶页不同.有时在不同的节(section)里插入不同的 ...

  5. Office WORD如何为每一页设置不同的页眉页脚

    如下图所示,我想要为封面和目录,摘要等等设置不同的页眉页脚(一般封面和目录不需要页脚)   而从正文开始,套用相同的页眉和以页数作为页脚(注意"第一章 绪论"不是这个文档的第一页) ...

  6. 用什么方法给PDF添加页眉页脚

    我们所看到的书本中都会设置好有页眉页脚,那么电子书想要添加页眉页脚要怎么操作呢,用什么方法可以在PDF中添加页眉页脚呢,今天就为大家分享一下,如何在电子文件中添加页眉页脚,想知道的小伙伴们就一起来看看 ...

  7. PDF怎么去除页眉页脚,PDF页眉页脚编辑方法

    我们在使用文件的时候需要编辑页眉页脚的时候,这个时候我们应该怎么做呢,相信别的文件大家都知道怎么编辑了,PDF文件大家都知道吗,最开始接触这个文件的时候小编觉得很难,之后找到技巧之后也并没有很难,今天 ...

  8. IE浏览器打印的页眉页脚设置解决方法

    首先说明问题: 默认情况下,通过IE的打印对话框,打印出来的内容都有页眉和页脚的. 查看ie的页面设置发现如右图中,页眉页脚 下面先说明&w&bPage&p of &P ...

  9. ASP导出Word带页眉页脚,中文不乱码

    关键代码: <% Response.Clear() Response.CodePage= Response.Charset="UTF-8" Response.ContentT ...

随机推荐

  1. TIJ——Chapter Eight:Polymorphism

    The twist |_Method-call binding Connecting a method call to a method body is called binding. When bi ...

  2. [转]彻底征服 Spring AOP 之 理论篇

    基本知识 其实, 接触了这么久的 AOP, 我感觉, AOP 给人难以理解的一个关键点是它的概念比较多, 而且坑爹的是, 这些概念经过了中文翻译后, 变得面目全非, 相同的一个术语, 在不同的翻译下, ...

  3. hibernate的映射类型

    hibernate的映射类型 hibernate MySQL映射类型 1.Hibernate的映射类型 hibernate mysql映射类型 Hibernate 映射类型 Java 类型 标准 SQ ...

  4. vsftpd.conf

    引用:http://www.linuxidc.com/Linux/2012-08/67389.htm 研究嵌入式开发,开始使用的是Linux平台,用的是Ubuntu环境,但是发现Ubuntu的图形界面 ...

  5. Ubuntu/linux 有关权限修改的命令

    chmod更改文件权限命令 最常用的基础命令chmod chmod 777  目录名(路径名) 777 三位数字分别代表 user.group.others 的权限,可读(r).可写(w).可执行(x ...

  6. iOS多线程同步锁

    在iOS中有几种方法来解决多线程访问同一个内存地址的互斥同步问题: 方法一,@synchronized(id anObject),(最简单的方法)会自动对参数对象加锁,保证临界区内的代码线程安全 @s ...

  7. yii2框架增删改查案例

    //解除绑定蓝牙 //http://www.520m.com.cn/api/pet/remove-binding?healthy_id=72&pet_id=100477&access- ...

  8. kafka常用命令

    以下是kafka常用命令行总结: 0.查看有哪些主题: ./kafka-topics.sh --list --zookeeper 192.168.0.201:12181 1.查看topic的详细信息 ...

  9. vue路由的使用

    ue-router是Vue.js官方的路由插件,它和vue.js是深度集成的,适合用于构建单页面应用.vue的单页面应用是基于路由和组件的,路由用于设定访问路径,并将路径和组件映射起来.传统的页面应用 ...

  10. centos中基于随机数,再加入班级学生姓名

    这只需要在上一篇的随机数中加入数值就可以了 代码如下 #!/bin/bash num=$(date +%N); c=(wanghao xieyunsheng) a=`expr $num % 39 ` ...