首页 | 源码下载 | 网站模板 | 网页特效 | 广告代码 | 网页素材 | 字体下载 | 书库 | 站长工具
会员投稿 投稿指南 RSS订阅
当前位置:主页>网络编程>java教程>资讯:Java调用com组件操作word使用总结(jacob)

Java调用com组件操作word使用总结(jacob)

www.jz123.cn  2010-01-05   来源:   中国建站    责任编辑(袁袁)    我要投递新闻


  /**
  * 在当前插入点插入字符串
  *
  * @param newText
  * 要插入的新字符串
  */
  public void insertText(String newText) {
  Dispatch.put(selection, "Text", newText);
  }
  /**
  *
  * @param toFindText
  * 要查找的字符串
  * @param imagePath
  * 图片路径
  * @return
  */
  public boolean replaceImage(String toFindText, String imagePath) {
  if (!find(toFindText))
  return false;
  Dispatch.call(Dispatch.get(selection, "InLineShapes").toDispatch(),
  "AddPicture", imagePath);
  return true;
  }
  /**
  * 全局替换图片
  *
  * @param toFindText
  * 查找字符串
  * @param imagePath
  * 图片路径
  */
  public void replaceAllImage(String toFindText, String imagePath) {
  while (find(toFindText)) {
  Dispatch.call(Dispatch.get(selection, "InLineShapes").toDispatch(),
  "AddPicture", imagePath);
  Dispatch.call(selection, "MoveRight");
  }
  }
  /**
  * 在当前插入点插入图片
  *
  * @param imagePath
  * 图片路径
  */
  public void insertImage(String imagePath) {
  Dispatch.call(Dispatch.get(selection, "InLineShapes").toDispatch(),
  "AddPicture", imagePath);
  }
  /**
  * 合并单元格
  *
  * @param tableIndex
  * @param fstCellRowIdx
  * @param fstCellColIdx
  * @param secCellRowIdx
  * @param secCellColIdx
  */
  public void mergeCell(int tableIndex, int fstCellRowIdx, int fstCellColIdx,
  int secCellRowIdx, int secCellColIdx) {
  // 所有表格
  Dispatch tables = Dispatch.get(doc, "Tables").toDispatch();
  // 要填充的表格
  Dispatch table = Dispatch.call(tables, "Item", new Variant(tableIndex))
  .toDispatch();
  Dispatch fstCell = Dispatch.call(table, "Cell",
  new Variant(fstCellRowIdx), new Variant(fstCellColIdx))
  .toDispatch();
  Dispatch secCell = Dispatch.call(table, "Cell",
  new Variant(secCellRowIdx), new Variant(secCellColIdx))
  .toDispatch();
  Dispatch.call(fstCell, "Merge", secCell);
  }
  /**
  * 在指定的单元格里填写数据
  *
  * @param tableIndex
  * @param cellRowIdx
  * @param cellColIdx
  * @param txt
  */

上一篇:Java通过jacob对excel,word进行打印等操作 下一篇:Java转义字符在正则表达式中的应用

评论总数:0 [ 查看全部 ] 网友评论


关于我们隐私版权广告服务友情链接联系我们网站地图