jacod操作手册

2020-03-03 03:34:36 来源:范文大全收藏下载本文

Jacod是用来操作windows组件

目前能进行操作的工具有PPT,Excel,word, Windows Media Player…

当前介绍的是使用jacod操作word文档

首先是jacod操作word文档的几种方式

1,使用段落搜索

2,使用书签搜索

3,使用word本身的查找功能搜索

4,复制功能

5,粘贴功能

6,操作word文档中表格的功能

以上都是经常用到的一些功能还有更多功能请继续更新该文档

使用这些功能之前要开启word

下面的指定的字符串都是vbs里的常量 比如

Word.Application

//开始之前还要打开COM通道WordBean.openCOM();ActiveXComponent wordApp = new wordApp.setProperty(\"Visible\", new Variant(true));//配置启动ActiveXComponent(\"Word.Application\");// 初始化word应用程序

word时是显示执行还是隐式执行true为显示执行false为隐式

获得所有文档对象

Dispatch documents =

wordApp.getProperty(\"Documents\").toDispatch();

添加一个文档

Dispatch d = Dispatch.call(documents, \"Add\").toDispatch();打开一个存在的文档

Dispatch d = Dispatch.call(documents, \"Open\",

docName).toDispatch();//docName要打开的文档的详细地址

Dispatch selection = Dispatch.get(wordApp,

\"Selection\").toDispatch();

//获得该文档对象

1.根据段落操作

Dispatch wordContent = Dispatch.get(selection, \"Content\").toDispatch();

//根据文档对象 得到文档内容

Dispatch.call(wordContent, \"InsertAfter\", \"这里是一个段落的内容\");

//插入一个段落

设置刚插入的段落的文字格式

Dispatch paragraphs = Dispatch.get(wordContent, \"Paragraphs\").toDispatch(); //

所有段落

int paragraphCount = Dispatch.get(paragraphs, \"Count\").toInt(); // 一共的段落数

// 找到刚输入的段落,设置格式

Dispatch lastParagraph = Dispatch.call(paragraphs, \"Item\", new

Variant(paragraphCount)).toDispatch(); // 最后一段

Dispatch lastParagraphRange = Dispatch.get(lastParagraph, \"Range\").

toDispatch();

Dispatch font = Dispatch.get(lastParagraphRange, \"Font\").toDispatch();//对最

后一段文本进行字体设置

Dispatch.put(font, \"Bold\", new Variant(true)); // 设置为黑体

Dispatch.put(font, \"Italic\", new Variant(true)); // 设置为斜体

Dispatch.put(font, \"Name\", new Variant(\"宋体\")); //

Dispatch.put(font, \"Size\", new Variant(12)); //小四

Dispatch.call(document, \"SaveAs\", new Variant(\"C: /abc.doc\"));保存到一个新

的文档

2.根据书签操作

Dispatchdoc=Dispatch.call(documents,\"Open \",inFile).toDispatch();

//打开一个word文档@param String inFile要打开的文档地址

DispatchactiveDocument=app.getProperty( \"ActiveDocument \").toDispatch();

//获得该文档对象

DispatchbookMarks=app.call(activeDocument,\"Bookmarks \").toDispatch();//获得书签对象

booleanbookMarkExist1=Dispatch.call(bookMarks,\"Exists

\",bookMarkKey).toBoolean();//判断是否存在书签

Dispatch.put(range, \"Bookmarks \", \"LB_001 \");//在range插入点里加一个名字叫

LB_001的书签

DispatchrangeItem=Dispatch.call(bookMarks,\"Item

\",bookMarkKey).toDispatch();// 查找该标签返回一个标签对象@param

String bookMarkKey 标签名字

Dispatchrange=Dispatch.call(rangeItem,\"Range \").toDispatch();//根

据标签来找到该标签的范围

StringbookMarkValue=Dispatch.get(range,\"Text \").toString();//根

据范围来返回该标签里的内容.

3.根据word本身自带的查找功能查找

ActiveXComponent wordApp = new

ActiveXComponent(\"Word.Application\");// 初始化word应用程序

wordApp.setProperty(\"Visible\", new Variant(true));//配置启动word时是显示执行还是隐式执行true为显示执行false为隐式

Dispatch d = Dispatch.call(documents, \"Open\",

docName).toDispatch();//docName要打开的文档的详细地址

Dispatch selection = Dispatch.get(wordApp,

\"Selection\").toDispatch();//获得该文档对象

Dispatch find = wordApp.call(selection, \"Find\").toDispatch();

//打开word自带的搜索功能并在下面定义参数

//搜索的变量 Dispatch.put(find, \"Text\", toFindText);//@param String//查找下一个匹配的 Dispatch.put(find, \"Forward\", \"True\");//格式 Dispatch.put(find, \"Format\", \"True\");//该值指示搜索是否区分大小写。Dispatch.put(find, \"MatchCase\", \"True\");//该值指示是否执行全字匹配搜索。Dispatch.put(find, \"MatchWholeWord\", \"True\");//是否使用通配符比如* Dispatch.put(find, \"MatchWildcards\", \"True\");////开始查找并选定查找的项

Dispatch.call(find, \"Execute\")

//查询条件过多就不一一举例了.更多功能请上MSDN里

http://msdn.microsoft.com/zh-cn/library/envdte.find.matchcase.

aspx查看和搜索

toFindText 要查找的字符串 可以带通配符

4.复制功能

find(toCopyText, selection)//根据查询条件和查询范围选定查询

的文本@method find(String findText,Dispatch selection) 在楼上查看该方法

Dispatch textRange = Dispatch.get(selection, \"Range\").toDispatch();//得到选的的文本的对象

Dispatch.call(textRange, \"Copy\");//对选定的文本进行复制

5.粘贴功能

Dispatch.call(selection, \"Paste\");//对插入点进行粘贴动作@param Dispatch selection插入点

6.根据word操作表格

public void insertTable(String tableTitle, int row, intDispatch selection = Dispatch.get(MsWordApp,Dispatch.call(selection, \"TypeText\", tableTitle); // 写入标题Dispatch.call(selection, \"TypeParagraph\"); // 空一行段落Dispatch.call(selection, \"TypeParagraph\"); // 空一行段落Dispatch.call(selection, \"MoveDown\"); // 游标往下一行// 建立表格Dispatch tables = Dispatch.get(document,Dispatch range = Dispatch.get(selection, column,List list) { \"Selection\").toDispatch(); // 输入内容需要的对象 内容 // 标题格行}//插入内容public void insertText(String textToInsert) {Dispatch selection = Dispatch.get(MsWordApp,Dispatch.put(selection, \"Text\", textToInsert);//关闭wordpublic void closeWord() {Dispatch.call(MsWordApp, \"Quit\");MsWordApp = null;document = null;}\"Selection\").toDispatch(); \"Tables\").toDispatch();

\"Range\").toDispatch();// /当前光标位置或者选中的区域

Dispatch newTable = Dispatch.call(tables, \"Add\", range,

new Variant(row), new Variant(column), new Variant(1)).toDispatch(); // 设置row,column,表格外框宽度Dispatch cols = Dispatch.get(newTable,

\"Columns\").toDispatch(); // 此表的所有列,

int colCount = Dispatch.get(cols, \"Count\").changeType(Variant.VariantInt).getInt();// 一共有多少列 实际上这个数==column

int tmp_i = 0;

for (int i = 1; i

\"Cells\").toDispatch();// 当前列中单元格

int cellCount = Dispatch.get(cells, \"Count\").changeType(Variant.VariantInt).getInt();// 当前列中单元格数 实际上这个数等于row

int tmp_i2 = tmp_i;

/*** 在指定的单元格里填写数据** @param tableIndex* @param cellRowIdx* @param cellColIdx* @param txt*/public void putTxtToCell(Dispatch table, int cellRowIdx, intString txt) {Dispatch cell = Dispatch.call(table, \"Cell\", newnew Variant(cellColIdx)).toDispatch();}}for (int j = 1; j

Dispatch.call(cell, \"Select\");

//Dispatch selection = Dispatch.get(MsWordApp, \"Selection\").toDispatch(); // 输入内容需要的对象

//Dispatch.put(selection, \"Text\", txt);

}

//表格一块是复制张强的

//保存文件public void saveFileAs(String filename) {Dispatch.call(document, \"SaveAs\", filename);insertText(txt);}

操作手册

操作手册

操作手册

店长操作手册

销售业务操作手册

员工操作手册

仓管员操作手册_

淘宝操作手册

技术部操作手册

操作手册11.4

《jacod操作手册.doc》
jacod操作手册
将本文的Word文档下载到电脑,方便收藏和打印
推荐度:
点击下载文档
下载全文