Chinaunix首页 | 论坛 | 博客
  • 博客访问: 549169
  • 博文数量: 298
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 3077
  • 用 户 组: 普通用户
  • 注册时间: 2019-06-17 10:57
文章分类

全部博文(298)

文章存档

2022年(96)

2021年(201)

2019年(1)

我的朋友

分类: Java

2021-05-12 11:43:01


点击(此处)折叠或打开

  1. import com.spire.doc.*;
  2. import com.spire.doc.documents.DocumentObjectType;
  3. import com.spire.doc.documents.Paragraph;
  4. import com.spire.doc.fields.DocPicture;

  5. //java项目www fhadmin org
  6. public class GetCoordinatesOfPicture {
  7.     public static void main(String[] args) {
  8.         //加载Word测试文档
  9.         Document doc = new Document();
  10.         doc.loadFromFile("input.docx");

  11.         //遍历section
  12.         for (int a = 0; a<doc.getSections().getCount();a++)
  13.         {
  14.             Section section = doc.getSections().get(a);

  15.             //遍历paragraph段落
  16.             for (int b =0 ;b<section.getParagraphs().getCount();b++)
  17.             {
  18.                 Paragraph paragraph = section.getParagraphs().get(b);

  19.                 //遍历段落中的对象
  20.                 for (int i = 0; i < paragraph.getChildObjects().getCount(); i++)
  21.                 {
  22.                     DocumentObject docobj = paragraph.getChildObjects().get(i);

  23.                     //判断对象是否为图片
  24.                     if (docobj.getDocumentObjectType()== DocumentObjectType.Picture)
  25.                     {
  26.                         DocPicture picture = (DocPicture) docobj ;

  27.                         if (picture.getTitle().equals("图片4"))//定位标题为“图片4”的图片
  28.                         {
  29.                             //获取图片坐标位置
  30.                             float x = picture.getHorizontalPosition();
  31.                             float y = picture.getVerticalPosition();
  32.                             System.out.println("坐标位置为:\n X=" + x + " Y=" + y);
  33.                         }
  34.                     }
  35.                 }
  36.             }
  37.         }

  38.     }
  39. }

阅读(1625) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~