word模板中添加图片
来源:互联网 发布:怎样在淘宝买到好衣服 编辑:程序博客网 时间:2024/05/07 18:43
http://www.iteye.com/problems/72865
1.打开word文件
- /**
- * 打开一个已存在的文档
- *
- * @param docPath
- */
- public void openDocument(String docPath)
- {
- doc = Dispatch.call(documents, "Open", docPath).toDispatch();
- selection = Dispatch.get(word, "Selection").toDispatch();
- System.out.println("open a word file!!");
- }
2.在指定位置插入图片(a.通过在要添加图片的位置设置书签 b.在光标位置插入图片)
a方法
- /**
- * 在指定书签的添加图片
- *
- * @param bookMarkKey
- * 书签名
- * @param imagePath
- * 图片路径
- */
- public void addImageAtBookMark(String bookMarkKey, String imagePath)
- {
- Dispatch activeDocument = word.getProperty("ActiveDocument")
- .toDispatch();
- // 得到文档所有的书签
- Dispatch bookMarks = word.call(activeDocument, "Bookmarks")
- .toDispatch();
- // 获得指定的书签
- boolean bookMarkExist1 = Dispatch
- .call(bookMarks, "Exists", bookMarkKey).toBoolean();
- if (bookMarkExist1 == true)
- {
- System.out.println("已找到书签 " + bookMarkKey);
- Dispatch rangeItem = Dispatch.call(bookMarks, "Item", bookMarkKey)
- .toDispatch();
- Dispatch range = Dispatch.call(rangeItem, "Range").toDispatch();
- // 在书签选中范围内插入图片
- Dispatch.call(Dispatch.get(range, "InLineShapes").toDispatch(),
- "AddPicture", imagePath);
- }
- else
- {
- System.out.println("指定的书签不存在 " + bookMarkKey);
- }
- }
b方法
- /**
- * 在当前插入点插入图片
- *
- * @param imagePath
- * 图片路径
- */
- public void insertImage(String imagePath)
- {
- Dispatch.call(Dispatch.get(selection, "InLineShapes").toDispatch(),
- "AddPicture", imagePath);
- }
b方法徐结合光标的移动
- /**
- * 把选定的内容或插入点向上移动
- *
- * @param pos
- * 移动的距离
- */
- public void moveUp(int pos)
- {
- if (selection == null)
- selection = Dispatch.get(word, "Selection").toDispatch();
- for (int i = 0; i < pos; i++)
- Dispatch.call(selection, "MoveUp");
- }
- /**
- * 把选定的内容或者插入点向下移动
- *
- * @param pos
- * 移动的距离
- */
- public void moveDown(int pos)
- {
- if (selection == null)
- selection = Dispatch.get(word, "Selection").toDispatch();
- for (int i = 0; i < pos; i++)
- Dispatch.call(selection, "MoveDown");
- }
- /**
- * 把选定的内容或者插入点向左移动
- *
- * @param pos
- * 移动的距离
- */
- public void moveLeft(int pos)
- {
- if (selection == null)
- selection = Dispatch.get(word, "Selection").toDispatch();
- for (int i = 0; i < pos; i++)
- {
- Dispatch.call(selection, "MoveLeft");
- }
- }
- /**
- * 把选定的内容或者插入点向右移动
- *
- * @param pos
- * 移动的距离
- */
- public void moveRight(int pos)
- {
- if (selection == null)
- selection = Dispatch.get(word, "Selection").toDispatch();
- for (int i = 0; i < pos; i++)
- Dispatch.call(selection, "MoveRight");
- }
- /**
- * 把插入点移动到文件首位置
- *
- */
- public void moveStart()
- {
- if (selection == null)
- selection = Dispatch.get(word, "Selection").toDispatch();
- Dispatch.call(selection, "HomeKey", new Variant(6));
- }
- public void moveEnd()
- {
- if (selection == null)
- selection = Dispatch.get(word, "Selection").toDispatch();
- Dispatch.call(selection, "EndKey", new Variant(6));
- }
3.关闭word
- /**
- * 文件保存或另存为
- *
- * @param savePath
- * 保存或另存为路径
- */
- public void save(String savePath)
- {
- Dispatch.call(
- (Dispatch) Dispatch.call(word, "WordBasic").getDispatch(),
- "FileSaveAs", savePath);
- }
- /**
- * 关闭当前word文档
- *
- */
- public void closeDocument()
- {
- if (doc != null)
- {
- Dispatch.call(doc, "Save");
- Dispatch.call(doc, "Close", new Variant(saveOnExit));
- doc = null;
- System.out.println("close a word file!!");
- }
- }
- /**
- * 关闭全部应用
- *
- */
- public void closeWord()
- {
- if (word != null)
- {
- Dispatch.call(word, "Quit", new Variant(false));
- word = null;
- }
- selection = null;
- documents = null;
- }
0 0
- word模板中添加图片
- freemarker+poi 模板生成 word添加图片
- VBscript在word中添加图片!!!
- C#word模板添加多个表格,添加图片程序案例
- 使用POI向word中添加图片的问题
- word模板插入文字、图片
- iText 添加图片到word
- word中添加菜单栏
- Word中添加目录
- Word中添加参考文献
- 提取word中图片
- java中word模板导出
- POI word模板 文字 图片替换
- POI Word 模板 文字 图片 替换
- 含图片的word模板导出
- poi使用模板导出word带图片
- Java操作word模板插入图片
- POI Word 模板 文字 图片 替换
- C++面向对象类的实例题目十一
- php 中soapclient的使用
- 苹果 App 转移图文详解
- 从 Java 应用程序动态生成 PDF 文件
- SBT - Library Dependencies
- word模板中添加图片
- 字符串专题
- Spread Studio for .NET使用教程:添加工作表
- ZF2(Zend framework 2)启动流程和框架配置分析
- spring security登陆失败处理流程
- ArcGISJavaScript自动提示插件
- ztree树节点名称太长怎么办
- 采集阿里妈妈商品发布到ecshop
- Eclipse打开DDMS无响应