java - jacob - 操作word - 文档,进行写操作(5)
Dispatch documents = Dispatch.get(MsWordApp, \ // Call the Add method of the Documents collection to create // a new document to edit
document = Dispatch.call(documents, \ }
// 打开一个存在的word文档,并用document 引用 引用它 public void openFile(String wordFilePath) {
// Find the Documents collection object maintained by Word
// documents表示word的所有文档窗口,(word是多文档应用程序) Dispatch documents = Dispatch.get(MsWordApp, \ document = Dispatch.call(documents, \ new Variant(true)/* 是否进行转换ConfirmConversions */, new Variant(false)/* 是否只读 */).toDispatch();
// document = Dispatch.invoke(documents, \ // new Object[] { wordFilePath, new Variant(true), // new Variant(false) // }, new int[1]).toDispatch(); }
// 向 document 中插入文本内容
public void insertText(String textToInsert) {
// Get the current selection within Word at the moment. // a new document has just been created then this will be at
// the top of the new doc 获得选 中的内容,如果是一个新创建的文件,因里面无内容,则光标应处于文件开头处
Dispatch selection = Dispatch.get(MsWordApp, \ // 取消选中,应该就是移动光标 ,否则 新添加的内容会覆盖选中的内容 Dispatch.call(selection, \ // Put the specified text at the insertion point Dispatch.put(selection, \
// 取消选中,应该就是移动光标
Dispatch.call(selection, \ }
// 向文档中添加 一个图片,
public void insertJpeg(String jpegFilePath) {
Dispatch selection = Dispatch.get(MsWordApp, \ Dispatch image = Dispatch.get(selection, \
Dispatch.call(image, \ }
// 段落的处理,插入格式化的文本 public void insertFormatStr(String text) {
Dispatch wordContent = Dispatch.get(document, \取得word文件的内容
Dispatch.call(wordContent, \插入一个段落到最后
Dispatch paragraphs = Dispatch.get(wordContent, \ .toDispatch(); // 所有段落
int paragraphCount = Dispatch.get(paragraphs, \ Variant.VariantInt).getInt();// 一共的段落数
// 找到刚输入的段落,设置格式
Dispatch lastParagraph = Dispatch.call(paragraphs, \
new Variant(paragraphCount)).toDispatch(); // 最后一段(也就是刚插入的) // Range 对象表示文档中的一个连续范围,由一个起始字符位置和一个终止字符位置定义
Dispatch lastParagraphRange = Dispatch.get(lastParagraph, \ .toDispatch();
Dispatch font = Dispatch.get(lastParagraphRange, \ Dispatch.put(font, \设置为黑体 Dispatch.put(font, \设置为斜体 Dispatch.put(font, \宋体\ Dispatch.put(font, \小四
Dispatch selection = Dispatch.get(MsWordApp, \ Dispatch.call(selection, \插入一个空行 Dispatch alignment = Dispatch.get(selection, \ .toDispatch();// 段落格式 …… 此处隐藏:290字,全部文档内容请下载后查看。喜欢就下载吧 ……
相关推荐:
- [高等教育]公司协助某村精准扶贫工作总结.doc
- [高等教育]高二生物知识点总结(全)
- [高等教育]苏教版数学三年级下册《解决问题的策略
- [高等教育]仪器分析课程学习心得
- [高等教育]2017年五邑大学数学与计算科学学院333
- [高等教育]人教版七年级下册语文第四单元测试题(
- [高等教育]2018年秋七年级英语上册Unit7Howmuchar
- [高等教育]2017年八年级下数学教学工作小结
- [高等教育]湖南省怀化市2019届高三统一模拟考试(
- [高等教育]四年级下册科学_基础训练及答案教材
- [高等教育]城郊煤矿西风井管路伸缩器更换施工安全
- [高等教育]昆八中20182019学年度上学期期末考试
- [高等教育]项目部各类人员任命书
- [高等教育]上市公司经营水务产业的模式
- [高等教育]人教版高二化学第一学期第三章水溶液中
- [高等教育]【中考物理第一轮复习资料】四.压强与
- [高等教育]金坑水电站报废改建工程机电设备更新改
- [高等教育]高中生物教学工作计划简易版
- [高等教育]2017年西华大学攀枝花学院(联合办学)44
- [高等教育]最新整理超短爆笑英文小笑话大全
- 优秀教师继续教育学习心得体会
- 阳历到阴历的转换
- 留守儿童教育案例分析
- 华师17春秋学期《玩教具制作与环境布置
- 测速传感器新型安装装置的现场应用
- 人教版小学数学三年级下册第四单元
- 创业个人意向书
- 山东省潍坊市2012年高考仿真试题(三)
- [恒心][好卷速递]四川省成都外国语学校
- 多少人错把好转反应当成了病情加重处理
- 中外广播电视史复习资料整理
- 江苏省扬州市江都区宜陵镇中学2014-201
- 工程造价专业毕业实习报告
- 广西师范学院心理与教育统计
- aympkrq基于 - asp的博客网站设计与开
- 建筑业外出经营相关流程操作(营改增后
- 人治 德治 法治
- [精华篇]常识判断专项训练题库
- 中国共产党为什么要实行民主集中
- 小学数学第三册第一单元试卷(A、B、C




