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;

转载于:https://www.cnblogs.com/yinshuo/p/4954020.html

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

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

    序  本文是对Word页眉页脚的操作方法的进一步的阐述.在"C# 添加Word页眉页脚.页码"一文中,介绍了添加简单页眉页脚的方法,该文中的方法可满足于大多数的页眉页脚添加要求,但 ...

  2. 【Word】页眉页脚的设置方法

    最近正在准备毕业论文,看着学校统一的.复杂的,所谓"论文规范"直发呆,突然发觉,原来word也是有应用技术的呃-         一番摸索,讲一个比较生疏的一个设置方法,以供分享学 ...

  3. word中整理疏忽的页眉页脚操作

    word中整理疏忽的页眉页脚操作 在需要开始页码地方->插入分页符:上一页的最底端停留光标 分隔符下一页   [页面布局]- [分隔符]- [下一页]::或在要分的那一整部分的末尾加 分隔符下一 ...

  4. Word的样式库在 选项卡中_“页眉页脚如何设置?”方法很多种,这种最简单|Word页眉页脚...

    在阅读书籍或杂志时,会看到这些纸质刊物上都有页眉和页脚 . 我们在编辑文档时为了突显品牌形象以及美观性通常也需要给文档添加页眉和页脚. 那么,页眉和页脚如何添加?如何设置才好看?公司LOGO如何插入? ...

  5. Python操作Word文档的节属性和页眉/页脚

    封面图片:<Python程序设计实验指导书>(ISBN:9787302525790),董付国,清华大学出版社 图书详情(京东): 可与董付国老师的<Python程序设计(第2版)&g ...

  6. word页眉页脚操作

    封面与目录不要页码,从第三页正文开始要页码的设置方法 1.鼠标放在正文页(即你的第三页)首行之前,点击"插入"-"分隔符",选"分节符类型" ...

  7. WORD页边距、行距、页码、页眉页脚

    页边距:上2.5cm,下2.5cm,左2.5cm,右2cm,页眉1.5cm,页脚1.75cm,左侧装订: 行距:1.5倍行距: 页码:底部居中,五号: 页边距及页眉.页脚,装订线位置设置在" ...

  8. word排版----分节、页眉页脚、页码、制作标题样式

    最近在用word写一些课程论文,被一些格式问题困扰许久,经过网上搜集资料加上自己的尝试,解决了部分问题,特此记录下. 标题样式的制作.略. 分节.主要涉及到分节符.附上一篇介绍分节符的文档. http ...

  9. python 页眉页脚_python自动化办公:玩转word之页眉页脚秘笈-阿里云开发者社区

    节将就python操作word的页眉页脚技巧做深入介绍. 使用页眉和页脚 python操作word的页眉页脚技巧做深入介绍 Word支持页眉和页脚.页眉是出现在每个页面的上边距区域中的文本,与文本主体 ...

  10. Word 注重页面细节才专业(添加页眉页脚,调整页边距,消灭孤行) | 职场人就应该这样用 Word

      本篇博文结合这两篇食用更佳(知识点遥相呼应,有共通之处,且大多结合使用,轻松举一反三) Excel 表格打印篇(批量添加标题,同页打印,打印logo与页码) Word 高效办公,三步搞定活动策划书 ...

最新文章

  1. YOLOV5 v6.1更新 | TensorRT+TPU+OpenVINO+TFJS+TFLite等平台一键导出和部署
  2. could not export python function call python_value. Remove calls to Python functions before export
  3. Flink Pre-defined Timestamp Extractors / Watermark Emitters(预定义的时间戳提取/水位线发射器)...
  4. Service概念及用途
  5. Transient关键字的使用
  6. libevent 1.4.13 / 源代码文件组织
  7. 用python做加法_Python不用加减乘除做加法
  8. 小程序获取列表的下标
  9. Android studio使用git切换分支开发的方法(图文教程)
  10. 铜陵高考2021年成绩查询,滁州高考成绩查询入口2021
  11. Windows Server 2012启用Windows功能NetFx3时出错解决方法
  12. matlab gui 保存文件,Matlab GUI的文件打開和保存uigetfile uigetdir
  13. 每日一算法:杨辉三角形
  14. java建立_java建立一个类
  15. 解决VMware下Win10主机和win7虚拟机实现文件共享问题
  16. PHP TP模板下的微博登录(wap)
  17. (SEED-Lab) Sniffing_Spoofing
  18. 微信开发 (四) 微信网页授权
  19. 优化了的过关键点的光滑曲线拟合算法
  20. table数据刷新;v-if刷新el-table表格

热门文章

  1. fdbus examples 分析-- fdb_test_server.cpp
  2. 鱼眼图像转换为全景图像_使用A框架创建3D全景图像
  3. 适合编程初学者的开源博客系统(Go语言版)
  4. 如何破解vba的工程密码
  5. excel2007如何筛选后复制粘贴
  6. Mac 查询是否支持VT(Intel的Vanderpool的虚拟技术)
  7. GitHub权限管理
  8. Mac 下截图聚焦、局部放大、按键 GIF 录屏的最佳实践
  9. 如何用Python进行屏幕录制?
  10. AEM:南林樊奔等-植物根际促生菌控制大豆疫病