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. UVALive 7147 World Cup(数学+贪心)(2014 Asia Shanghai Regional Contest)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=6 ...

  2. 谁也无法挡住我访问Google---使用Nginx反向代理攻略

    展示最终成果: 浏览器打开​ http://www.manda13.com/(慢搭搜索)这个是自己搭建的百度网盘搜索,欢迎测试 点击右上角“原版Google”,就可以访问Google. 是不是很方便. ...

  3. 1.<%@Page%>中的Codebehind、AutoEventWireup、Inherits有何作用?

    AutoEventWireup --- 指示是否自动启用页事件. Codebehind --- 指示后台代码文件. Inherits --- 继承类. AutoEventWireup:指示该页的事件是 ...

  4. 开源镜像源(转自[tanghuimin0713的博客])

    参考: http://blog.csdn.net/longerzone/article/details/8437871 http://www.douban.com/note/375227086/ 1. ...

  5. C/C++二维数组的用法

    二维数组在存储时按行优先连续存储,数组名是一个二维指针,如 int a[3][2] 中,a 是一个二维指针,而a[0],a[1],a[2]都相当于普通的一位数组的数组名,是一个固定值的指针. 二维数组 ...

  6. Qt qml 单例模式

    Qt qml 单例模式,没什么好说的,看代码吧.单例模式很适合做全局的配置文件. [示例下载] http://download.csdn.net/detail/surfsky/8539313 [以下是 ...

  7. Java 邮件发送

    <dependency> <groupId>javax.mail</groupId> <artifactId>mail</artifactId&g ...

  8. Tween.js的使用示例

    可参考:http://www.htmleaf.com/jQuery/Layout-Interface/201501271284.html 官方文档:https://github.com/tweenjs ...

  9. svn版本搭建

    安装步骤如下: 1.yum install subversion   2.输入rpm -ql subversion查看安装位置,如下图:   我们知道svn在bin目录下生成了几个二进制文件. 输入 ...

  10. 108 vpn iptables

    [root@fge108 webapps]# iptables -t nat -A POSTROUTING -s 192.168.10.0/24 -j SNAT --to-source 47.88.1 ...