C#操作word的一些基本方法(word打印,插入文件,插入图片,定位页眉页脚,去掉横线)
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打印,插入文件,插入图片,定位页眉页脚,去掉横线)的更多相关文章
- C# 操作Word页眉页脚——奇偶页/首页不同、不连续设置页码、复制页眉页脚、锁定页眉页脚、删除页眉页脚
前言 本文是对Word页眉页脚的操作方法的进一步的阐述.在“C# 添加Word页眉页脚.页码”一文中,介绍了添加简单页眉页脚的方法,该文中的方法可满足于大多数的页眉页脚添加要求,但是对于比较复杂一点的 ...
- C#word(2007)操作类--新建文档、添加页眉页脚、设置格式、添加文本和超链接、添加图片、表格处理、文档格式转化
转:http://www.cnblogs.com/lantionzy/archive/2009/10/23/1588511.html 1.新建Word文档 #region 新建Word文档/// &l ...
- 使用C#在word中插入页眉页脚
//插入页脚 public void InsertFooter(string footer) { if (ActiveWindow.ActivePane.View.Type == WdViewType ...
- 在C#中实现Word页眉页脚的全部功能
页眉页脚经常使用于文章排版,在Word工具栏里.我们能够加入页眉,页脚,页码,日期和时间.图片等信息和内容.页眉/页脚有两个额外选项:首页不同,奇偶页不同.有时在不同的节(section)里插入不同的 ...
- Office WORD如何为每一页设置不同的页眉页脚
如下图所示,我想要为封面和目录,摘要等等设置不同的页眉页脚(一般封面和目录不需要页脚) 而从正文开始,套用相同的页眉和以页数作为页脚(注意"第一章 绪论"不是这个文档的第一页) ...
- 用什么方法给PDF添加页眉页脚
我们所看到的书本中都会设置好有页眉页脚,那么电子书想要添加页眉页脚要怎么操作呢,用什么方法可以在PDF中添加页眉页脚呢,今天就为大家分享一下,如何在电子文件中添加页眉页脚,想知道的小伙伴们就一起来看看 ...
- PDF怎么去除页眉页脚,PDF页眉页脚编辑方法
我们在使用文件的时候需要编辑页眉页脚的时候,这个时候我们应该怎么做呢,相信别的文件大家都知道怎么编辑了,PDF文件大家都知道吗,最开始接触这个文件的时候小编觉得很难,之后找到技巧之后也并没有很难,今天 ...
- IE浏览器打印的页眉页脚设置解决方法
首先说明问题: 默认情况下,通过IE的打印对话框,打印出来的内容都有页眉和页脚的. 查看ie的页面设置发现如右图中,页眉页脚 下面先说明&w&bPage&p of &P ...
- ASP导出Word带页眉页脚,中文不乱码
关键代码: <% Response.Clear() Response.CodePage= Response.Charset="UTF-8" Response.ContentT ...
随机推荐
- chattr的常用参数详解
chattr的常用参数详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 在实际生产环境中,有的运维工程师不得不和开发和测试打交道,在我们公司最常见的就是部署接口.每天每个人部署的 ...
- 关于baseflight cleanflight naze32不能解锁的办法
需要修改源代码,重新编译.. mcfg.mincheck = 1150; mcfg.maxcheck = 1850; 当然,这是笨方法.还有个办法设置解锁检查的最大最小油门 在控制台,也就是 CLI那 ...
- python3爬取网页
爬虫 python3爬取网页资源方式(1.最简单: import'http://www.baidu.com/'print2.通过request import'http://www.baidu.com' ...
- jquery note--czx
-------------------------------------------------------+++------------------------------------------ ...
- C++之路进阶——codevs2306(晨跑)
2306 晨跑 2009年省队选拔赛山东 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 大师 Master 题目描述 Description Elaxia最近迷恋 ...
- Java多线程开发系列之番外篇:事件派发线程---EventDispatchThread
事件派发线程是java Swing开发中重要的知识点,在安卓app开发中,也是非常重要的一点.今天我们在多线程开发中,穿插进来这个线程.分别从线程的来由.原理和使用方法三个方面来学习事件派发线程. 一 ...
- 浅谈php中使用websocket
在PHP中,开发者需要考虑的东西比较多,从socket的连接.建立.绑定.监听等都需要开发者自己去操作完成,对于初学者来说,难度方面也挺大的,所以本文的思路如下: 1.socket协议的简介 2.介绍 ...
- 用 WEKA 进行数据挖掘,第 1 部分: 简介和回归(转)
http://www.ibm.com/developerworks/cn/opensource/os-weka1/index.html 简介 什么是 数据挖掘?您会不时地问自己这个问题,因为这个主题越 ...
- PHP 生成验证码
//加载 vendor目录的phpqrcode.类文件 $a = vendor("phpqrcode.qrlib");// 创建目录 echo mkdir(__ROOT__.'/U ...
- 【转】PowerShell入门(十二):编写PowerShell管理单元和二进制模块
转至:http://www.cnblogs.com/ceachy/archive/2013/03/13/PowerShell_SnapIn.html PowerShell一开始就提出利用管理单元来实现 ...