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 在医疗管理系统中为保存患者的体检和治疗记录,方便以后的医生或其他人查看.当把数据保存到数据库中,需要新建很 ...
随机推荐
- web.xml 配置介绍
这个不是原创,有点早了,具体从哪里来的已经记不得了.但是东西是实实在在的. 1.启动一个WEB项目的时候,WEB容器会去读取它的配置文件web.xml,读取<listener>和<c ...
- flappy pig小游戏源码分析(1)——主程序初探
闲逛github发现一个javascript原生实现的小游戏,源码写的很清晰,适合想提高水平的同学观摩学习.读通源码后,我决定写一系列的博客来分析源码,从整体架构到具体实现细节来帮助一些想提高水平的朋 ...
- WebApi参数传递
c# webapi的参数传递方式:1.查询字符串(query string):2.内容主体(content body) 当然也有cookie或url部分或头部信息(header)等其它传方式,这里仅讨 ...
- linux中的配置文件
/etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行.并从/etc/profile.d目录的配置文件中搜集shell的设置. /etc/bashrc:为每一个 ...
- mongodb使用中遇到的问题汇总
1. 每次重新打开mongo,都会显示:forked process:xxxx ,然后用 find -name mongod.lock 进行搜索,发现在 ./var/lib/mongodb/ 目录下又 ...
- Compiling Xen-4.4 From Source And Installing It On Ubuntu Server (Amd-64)
First of all, you should install a clean Ubuntu Server (Amd-64) on your server. (Version 14.04 is st ...
- ipc.Client: Retrying connect to server: h1/192.168.1.61:9000. Already tried 0 time(s);解决方法
1.检查namenode服务器的是否运行正常,我的问题是没有开启hadoop集群出现的. 2.检查namenode服务器的防火墙是否开放的响应端口,一般内网建议关闭.
- Linux下动态库生成和使用
Linux下动态库生成和使用 一.动态库的基本概念 1.动态链接库是程序运行时加载的库,当动态链接库正确安装后,所有的程序都可以使用动态库来运行程序.动态链接库是目标文件的集合,目标文件在动态链接库中 ...
- 2 weekend110的HDFS的JAVA客户端编写 + filesystem设计思想总结
HDFS的JAVA客户端编写 现在,我们来玩玩,在linux系统里,玩eclipse 或者, 即,更改图标,成功 这个,别慌.重新换个版本就好,有错误出错是好事. http://www.eclips ...
- 個人最近做的最多的重複工作就是excel导出
//导出事件,这个是有合并动态列的 double num1 = 0, num2 = 0, num3 = 0; protected void btnExcel_Click(object sender, ...