java操作word-需要导入一个包jacob-1.15-M4.doc

java操作word-需要导入一个包jacob-1.15-M4.doc

ID:57650200

大小:46.50 KB

页数:5页

时间:2020-08-30

java操作word-需要导入一个包jacob-1.15-M4.doc_第1页
java操作word-需要导入一个包jacob-1.15-M4.doc_第2页
java操作word-需要导入一个包jacob-1.15-M4.doc_第3页
java操作word-需要导入一个包jacob-1.15-M4.doc_第4页
java操作word-需要导入一个包jacob-1.15-M4.doc_第5页
资源描述:

《java操作word-需要导入一个包jacob-1.15-M4.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、packagescau.action;importcom.jacob.activeX.ActiveXComponent;importcom.jacob.com.Dispatch;importcom.jacob.com.Variant;publicclassCreatWordDemo{publicstaticvoidmain(Stringargs[]){ActiveXComponentwordApp=newActiveXComponent("Word.Application");//启动wordDispatch.put(wordApp,"Visible",newVariant(

2、true));//设置word可见Dispatchdocs=wordApp.getProperty("Documents").toDispatch();//StringinFile="d:\test.doc";//Dispatchdoc=Dispatch.invoke(docs,"Open",Dispatch.Method,//newObject[]{inFile,newVariant(false),newVariant(false)},//参数3,false:可写,true:只读//newint[1]).toDispatch();//打开文档Dispatchdocumen

3、t=Dispatch.call(docs,"Add").toDispatch();//createnewdocumentStringuserName=wordApp.getPropertyAsString("Username");//显示用户信息//System.out.println("用户名:"+userName);//文档对齐,字体设置Dispatchselection=Dispatch.get(wordApp,"Selection").toDispatch();Dispatchalign=Dispatch.get(selection,"ParagraphFormat"

4、).toDispatch();//行列格式化需要的对象Dispatchfont=Dispatch.get(selection,"Font").toDispatch();//字型格式化需要的对象//标题处理////////////////////////Dispatch.put(align,"Alignment","1");//1:置中2:靠右3:靠左Dispatch.put(font,"Bold","1");//字型租体Dispatch.put(font,"Color","1,6,0,0");//字型颜色红色Dispatch.call(selection,"TypeText"

5、,"Word文档处理");//写入标题内容Dispatch.call(selection,"TypeParagraph");//空一行段落Dispatch.put(align,"Alignment","3");//1:置中2:靠右3:靠左Dispatch.put(selection,"Text","");Dispatch.call(selection,"MoveDown");//光标标往下一行//表格处理////////////////////////Dispatchtables=Dispatch.get(document,"Tables").toDispatch();Dis

6、patchrange=Dispatch.get(selection,"Range").toDispatch();Dispatchtable1=Dispatch.call(tables,"Add",range,newVariant(3),newVariant(3),newVariant(1)).toDispatch();//设置行数,列数,表格外框宽度//所有表格VarianttableAmount=Dispatch.get(tables,"count");//System.out.println(tableAmount);//要填充的表格Dispatcht1=Dispatch

7、.call(tables,"Item",newVariant(1)).toDispatch();Dispatcht1_row=Dispatch.get(t1,"rows").toDispatch();//所有行intt1_rowNum=Dispatch.get(t1_row,"count").getInt();//得到行数Dispatch.call(Dispatch.get(t1,"columns").toDispatch(),"AutoFit");//自动调整intt1_colNum=Dispatch

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。