亚洲精品久久久久久第一页-人妻少妇精彩视品一区二区三区-91国产自拍免费视频-免费一级a在线播放视频正片-少妇天天日天天射天天爽-国产大屁股喷水视频在线观看-操美女骚穴抽插性爱视频-亚洲 欧美 中文字幕 丝袜-成人免费无码片在线观看

java中設(shè)置圖片位置 Java 獲取Word中指定圖片的坐標(biāo)位置

1. 指定文件路徑 , 本次測(cè)試代碼路徑為項(xiàng)目文件夾路徑 。即在IDEA項(xiàng)目文件下存入用于測(cè)試的Word文檔 , 如:C:\Users\Administrator\IdeaProjects\Picture_Doc\input.docx 。文件路徑也可自定義為其他路徑 。
2. 在程序中引入jar文件 , 如下圖:

java中設(shè)置圖片位置 Java 獲取Word中指定圖片的坐標(biāo)位置

文章插圖
Java程序代碼:
import com.spire.doc.*;
import com.spire.doc.documents.DocumentObjectType;
import com.spire.doc.documents.Paragraph;
import com.spire.doc.fields.DocPicture;

public class GetCoordinatesOfPicture {
public static void main(String[] args) {
//加載Word測(cè)試文檔
Document doc = new Document();
doc.loadFromFile("input.docx");

//遍歷section
for (int a = 0; a<doc.getSections().getCount();a++)
{
Section section = doc.getSections().get(a);

//遍歷paragraph段落
for (int b =0 ;b<section.getParagraphs().getCount();b++)
{
Paragraph paragraph = section.getParagraphs().get(b);

//遍歷段落中的對(duì)象
for (int i = 0; i < paragraph.getChildObjects().getCount(); i++)
{
DocumentObject docobj = paragraph.getChildObjects().get(i);

//判斷對(duì)象是否為圖片
if (docobj.getDocumentObjectType()== DocumentObjectType.Picture)
{
DocPicture picture = (DocPicture) docobj ;

if (picture.getTitle().equals("圖片4"))//定位標(biāo)題為“圖片4”的圖片
{
//獲取圖片坐標(biāo)位置
float x = picture.getHorizontalPosition();
float y = picture.getVerticalPosition();
System.out.println("坐標(biāo)位置為:\n X=" + x + " Y=" + y);
}
}
}
}
}

}
}
坐標(biāo)獲取結(jié)果:
java中設(shè)置圖片位置 Java 獲取Word中指定圖片的坐標(biāo)位置

文章插圖
java中設(shè)置圖片位置 Java 獲取Word中指定圖片的坐標(biāo)位置

文章插圖


    以上關(guān)于本文的內(nèi)容,僅作參考!溫馨提示:如遇健康、疾病相關(guān)的問(wèn)題,請(qǐng)您及時(shí)就醫(yī)或請(qǐng)專業(yè)人士給予相關(guān)指導(dǎo)!

    「愛(ài)刨根生活網(wǎng)」www.malaban59.cn小編還為您精選了以下內(nèi)容,希望對(duì)您有所幫助: