C#操作Word生成目录
- OperateWord ow = new OperateWord();
- Microsoft.Office.Interop.Word.ApplicationClass ss = ow.WordApplication;
- AddContent(ref ss);
- void AddContent(ref Microsoft.Office.Interop.Word.ApplicationClass app)
- {
- Object oMissing = System.Reflection.Missing.Value;
- Object oTrue = true;
- Object oFalse = false;
- Object oUpperHeadingLevel = "1";
- Object oLowerHeadingLevel = "3";
- Object oTOCTableID = "TableOfContents";
- app.Selection.Start = 0;
- app.Selection.End = 0;//将光标移动到文档开始位置
- object beginLevel = 2;//目录开始深度
- object endLevel = 2;//目录结束深度
- object rightAlignPageNumber = true;// 指定页码右对其
- /*
- * Range
- * UserHeadingStyles 使用heading风格
- * UpperHeadingLevel 增加heading级别
- * LowerHeadingLevel 减小heading级别
- * UserFields 使用fields
- * Tableid tableid
- * RightAlignPageNumbers 右对齐页数
- * IncludePageNumbers 包含页数
- * Addedstyles 添加风格
- * UserHyperlinks 使用超链接
- * HidePageNumbersInweb 隐藏页数
- * UseOutLineLevels 使用提纲级别
- * TableOfContents 内容表
- */
- app.Application.ActiveDocument.TablesOfContents.Add(app.Selection.Range, ref oTrue, ref oUpperHeadingLevel,
- ref oLowerHeadingLevel, ref oMissing, ref oTOCTableID, ref oTrue,
- ref oTrue, ref oMissing, ref oTrue, ref oTrue, ref oTrue);//添加目录
- //写入目录
- }
参考1:
- private void button1_Click(object sender, EventArgs e)
- {
- Object oMissing = System.Reflection.Missing.Value;
- Object oTrue = true;
- Object oFalse = false;
- Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
- Microsoft.Office.Interop.Word.Document doc = new Microsoft.Office.Interop.Word.Document();
- oWord.Visible = true;
- object fileName = this.textBox1.Text;
- doc = oWord.Documents.Open(ref fileName,
- ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
- ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
- ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
- //---------------------------------------------------------------------------------------------------------------------
- oWord.Selection.Paragraphs.OutlineLevel = WdOutlineLevel.wdOutlineLevel2;
- oWord.Selection.Paragraphs.OutlineLevel = WdOutlineLevel.wdOutlineLevel3;
- oWord.Selection.Paragraphs.OutlineLevel = WdOutlineLevel.wdOutlineLevelBodyText;
- object x = 0;
- Range myRange = doc.Range(ref x, ref x);
- Object oUpperHeadingLevel = "1";
- Object oLowerHeadingLevel = "3";
- Object oTOCTableID = "TableOfContents";
- doc.TablesOfContents.Add(myRange, ref oTrue, ref oUpperHeadingLevel,
- ref oLowerHeadingLevel, ref oMissing, ref oTOCTableID, ref oTrue,
- ref oTrue, ref oMissing, ref oTrue, ref oTrue, ref oTrue);
- //---------------------------------------------------------------------------------------------------------------------
- //Object oSaveAsFile = fileName;
- //doc.SaveAs(ref oSaveAsFile, ref oMissing, ref oMissing, ref oMissing,
- // ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
- // ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
- // ref oMissing, ref oMissing);
- }
- private void button2_Click(object sender, EventArgs e)
- {
- OpenFileDialog fd = new OpenFileDialog();
- if (fd.ShowDialog() == DialogResult.OK)
- {
- this.textBox1.Text = fd.FileName;
- }
- }
参考2:
- void AddContent(ref Word.Appliction app)
- {
- app.Selection.Start=0;
- app.Selection.End=0;//将光标移动到文档开始位置
- object beginLevel=2;//目录开始深度
- object endLevel=2;//目录结束深度
- object rightAlignPageNumber=true;// 指定页码右对其
- app.ActiveDocument.TablesOfContents.Add(app.Selection.Range,ref miss,rightAlignPageNumber,ref miss,
- ref miss,ref miss,ref miss,ref miss);//写入目录
C#操作Word生成目录的更多相关文章
- Aspose.Words操作word生成PDF文档
Aspose.Words操作word生成PDF文档 using Aspose.Words; using System; using System.Collections.Generic; using ...
- VBA操作word生成sql语句
项目开始一般都是用word保存下数据库的文档 但是从表单一个一个的建表实在是很困难乏味,查查资料 1.可以生成一个html或者xml,检索结构生成sql.但是这个方式也蛮麻烦 2.查到vba可以操作w ...
- DocX操作word生成报表
1.DocX简介 1.1 简介 DocX是一个在不需要安装word的情况下对word进行操作的开源轻量级.net组件,是由爱尔兰的一个叫Cathal Coffey的博士生开发出来的.DocX使得操作w ...
- word生成目录的pdf
在很多情况下,需要将Word转换为带目录书签的PDF,方便pdf阅读,所以可以使用word自带的pdf转换,在转换时设置相关即可 注意:待转换Word中应该有目录,可以用Word中的标题来自动生成目录 ...
- word 生成目录
生成目录: (1)Ctrl+End,到达文档的最后一页: (2)"插入"菜单--引用--索引和目录(此时出现索引和目录对话框): (3)单击"目录"选项卡 a. ...
- [转载]java操作word生成水印
应用场景 为了保护版权或辨别文件的真伪,有时需要在生成的Word文件中动态添加水印,PageOffice组件的WaterMark类就封装了给在线编辑的Word文件添加水印这一功能,调用接口非常简单. ...
- [原创]java操作word生成水印
应用场景 为了保护版权或辨别文件的真伪,有时需要在生成的Word文件中动态添加水印,PageOffice组件的WaterMark类就封装了给在线编辑的Word文件添加水印这一功能,调用接口非常简单. ...
- c# 操作Word总结(车)
在医疗管理系统中为保存患者的体检和治疗记录,方便以后的医生或其他人查看.当把数据保存到数据库中,需要新建很多的字段,而且操作很繁琐,于是想到网页的信息创建到一个word文本中,在显示的时,可以在线打开 ...
- c# 操作Word总结【转】
http://www.cnblogs.com/eye-like/p/4121219.html 在医疗管理系统中为保存患者的体检和治疗记录,方便以后的医生或其他人查看.当把数据保存到数据库中,需要新建很 ...
随机推荐
- 成功BOSS的六大秘诀
1.信念力 一个没有坚定信念的人,是不可能成为伟大企业家的.如果你认为自己行,你就一定行:如果你都认为自己不行了,那你就注定不行.在成功这条道路上,要勇敢地自我肯定和鼓励,这样才能带来巨大的创造力并最 ...
- C ~ C语言字节对齐
1. 什么是对齐? 现代计算机中内存空间都是按照字节(byte)划分的,从理论上讲似乎对任何类型的变量的访问可以从任何地址开始,但实际情况是在访问特定变量的时候经常在特定的内存地址访问,这就需要各类型 ...
- 【LeetCode】111 - Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...
- Unable to find vcvarsall.bat解决方法
今天在安装scikit-learn时出现了 error: Unable to find vcvarsall.bat 在安装一些Python模块时,大部分是cpython写的模块时会发生如下错误 err ...
- junit4新框架hamcrest
Hamcrest是一个书写匹配器对象时允许直接定义匹配规则的框架.有大量的匹配器是侵入式的,例如UI验证或者数据过滤,但是匹配对象在书写灵活的测试是最常用.本教程将告诉你如何使用Hamcrest进行单 ...
- hadoop 伪分布模式的配置
转自 http://blog.csdn.net/zhaogezhuoyuezhao/article/details/7328313 centos系统自带ssh,版本为openssh4.3 免密码ssh ...
- 设置TabBarItem选中时的图片及文字颜色
TabBarItem选中时,默认文字和图片都变为蓝色.使用以下代码可以进行修改. MainViewController *mainVC = [[MainViewController alloc] in ...
- 多台服务器最好加上相同的machineKey
<machineKey validationKey="6E993A81CF4BDCA1C1031528F55DADBB8AF1772A" decryptionKey=&q ...
- Represent nil with NSNull
[Represent nil with NSNull] It’s not possible to add nil to the collection classes described in this ...
- BootCamp支持软件4/5
按 Mac 机型列出的 Boot Camp 要求 不同的 Mac 电脑适用不同版本的 Windows.如果您不知道您拥有的 Mac 是什么机型,请从 Apple 菜单中选取“关于本机”. 每个表格条目 ...