欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Java 添加、刪除、格式化Word中的圖片步驟詳解( 基于Spire.Cloud.SDK for Java )

 更新時(shí)間:2020年08月03日 10:17:50   作者:E-iceblue  
這篇文章主要介紹了Java 添加、刪除、格式化Word中的圖片( 基于Spire.Cloud.SDK for Java ),本文分步驟通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

本文介紹使用Spire.Cloud.SDK for Java提供的ImagesApi接口來(lái)操作Word中的圖片。具體可通過(guò)addImage()方法添加圖片、deleteImage()方法刪除圖片、updateImageFormat()格式化Word中的圖片以及getImageFormat()獲取Word中的圖片格式等。操作方法和代碼示例可參考下文中的步驟。

步驟1:導(dǎo)入jar文件

創(chuàng)建Maven項(xiàng)目程序,通過(guò)maven倉(cāng)庫(kù)下載導(dǎo)入。以IDEA為例,新建Maven項(xiàng)目,在pom.xml文件中配置maven倉(cāng)庫(kù)路徑,并指定spire.cloud.sdk的依賴,如下:

<repositories>
 <repository>
 <id>com.e-iceblue</id>
 <name>cloud</name>
 <url>http://repo.e-iceblue.cn/repository/maven-public/</url>
 </repository>
</repositories>

<dependencies>
 <dependency>
 <groupId> cloud </groupId>
 <artifactId>spire.cloud.sdk</artifactId>
 <version>3.5.0</version>
 </dependency>

 <dependency>
 <groupId> com.google.code.gson</groupId>
 <artifactId>gson</artifactId>
 <version>2.8.1</version>
 </dependency>

 <dependency>
 <groupId> com.squareup.okhttp</groupId>
 <artifactId>logging-interceptor</artifactId>
 <version>2.7.5</version>
 </dependency>

 <dependency>
 <groupId> com.squareup.okhttp </groupId>
 <artifactId>okhttp</artifactId>
 <version>2.7.5</version>
 </dependency>

 <dependency>
 <groupId> com.squareup.okio </groupId>
 <artifactId>okio</artifactId>
 <version>1.6.0</version>
 </dependency>

 <dependency>
 <groupId> io.gsonfire</groupId>
 <artifactId>gson-fire</artifactId>
 <version>1.8.0</version>
 </dependency>

 <dependency>
 <groupId>io.swagger</groupId>
 <artifactId>swagger-annotations</artifactId>
 <version>1.5.18</version>
 </dependency>

 <dependency>
 <groupId> org.threeten </groupId>
 <artifactId>threetenbp</artifactId>
 <version>1.3.5</version>
 </dependency>
</dependencies>

完成配置后,點(diǎn)擊“Import Changes” 即可導(dǎo)入所有需要的jar文件。如果使用的是Eclipse,可參考這里的導(dǎo)入方法。

導(dǎo)入結(jié)果:

步驟2:登錄冰藍(lán)云賬號(hào),創(chuàng)建文件夾,上傳用于測(cè)試的源文檔

步驟3:創(chuàng)建應(yīng)用程序,獲取App ID及App Key

完成以上步驟后,接下來(lái)可參考Java示例代碼進(jìn)行Word文檔操作

示例1—添加圖片到Word

注:添加圖片時(shí),可以將云端文件夾中的圖片添加到Word,也可以將本地路徑中的圖片添加到Word。

import spire.cloud.word.sdk.client.*;
import spire.cloud.word.sdk.client.api.ImagesApi;

import java.io.File;

public class AddImage {
 static String appId = "App ID";
 static String appKey = "App Key";
 static String baseUrl = "https://api.e-iceblue.cn";
 static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
 static ImagesApi imagesApi = new ImagesApi(wordConfiguration);

 public static void main(String[] args) throws ApiException {
 String name = "testfile.docx";//源文檔
 String imagePath = "input/Javalogo.png";//云端文件夾下的圖片
 //File inputImage = new File("C:/Users/Administrator/Desktop/images/logo/Javalogo.png");//本地圖片
 String paragraphPath = "Section/0/Body/0/Paragraph/0";//指定段落
 String folder = "input";//源文檔和圖片所在的云端文件夾
 String storage = null;
 String password = null;
 Integer indexInParagraph = 1;
 String destFilePath = "output/AddImageToWord.docx";

 //調(diào)用方法將云端圖片添加到Word
 imagesApi.addImage(name, imagePath, paragraphPath, destFilePath, folder, storage, password, indexInParagraph);

 //調(diào)用方法將本地圖片添加到Word
 //imagesApi.addImageInRequest(name,inputImage,paragraphPath,destFilePath,folder,storage,password,indexInParagraph);
 }
}

圖片添加效果:

示例2—?jiǎng)h除Word中的圖片

import spire.cloud.word.sdk.client.ApiException;
import spire.cloud.word.sdk.client.Configuration;
import spire.cloud.word.sdk.client.api.ImagesApi;

public class DeleteImage {
 static String appId = "App ID";
 static String appKey = "App Key";
 static String baseUrl = "https://api.e-iceblue.cn";
 static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
 static ImagesApi imagesApi = new ImagesApi(wordConfiguration);

 public static void main(String[] args) throws ApiException {
 String name = "Sample.docx";//包含圖片的Word源文檔
 String paragraphPath = "Section/0/Body/0/Paragraph/2";//指定段落
 Integer index = 0;
 String folder = "input";//源文檔所在文件
 String storage = null;
 String password = null;
 String destFilePath = "output/DeleteImageInWord.docx";//結(jié)果文檔路徑

 //調(diào)用方法刪除掉段落中的圖片
 imagesApi.deleteImage(name, paragraphPath, index, destFilePath, folder, storage, password);
 }
}

圖片刪除效果:

示例3—設(shè)置Word中的圖片格式

import spire.cloud.word.sdk.client.ApiException;
import spire.cloud.word.sdk.client.Configuration;
import spire.cloud.word.sdk.client.api.ImagesApi;
import spire.cloud.word.sdk.client.model.ImageFormat;

public class UpdateImageFormat {
 static String appId = "App ID";
 static String appKey = "App Key";
 static String baseUrl = "https://api.e-iceblue.cn";
 static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);

 static ImagesApi imagesApi = new ImagesApi(wordConfiguration);
 public static void main(String[] args) throws ApiException {
 String name = "Sample.docx";//源文檔
 String paragraphPath = "Section/0/Body/0/Paragraph/2";
 Integer index = 0;
 
 //格式化圖片,設(shè)置高度、寬度、旋轉(zhuǎn)角度、坐標(biāo)位置等
 ImageFormat format = new ImageFormat();
 format.setWidth(200);
 format.setHeight(150);
 format.setRotation(15);
 format.setVerticalPosition(50);
 format.setHorizontalPosition(350);
 
 String folder = "input";//源文檔所在文件夾
 String storage = null;
 String password = null;
 String destFilePath = "output/UpdateImageFormat.docx";

 //調(diào)用方法格式化圖片
 imagesApi.updateImageFormat(name, paragraphPath, index, destFilePath, format, password, folder, storage);
 }
}

圖片格式化效果:

示例4—獲取Word中的圖片格式

import spire.cloud.word.sdk.client.ApiException;
import spire.cloud.word.sdk.client.Configuration;
import spire.cloud.word.sdk.client.api.ImagesApi;

public class GetImageFormat {
 static String appId = "App ID";
 static String appKey = "App Key";
 static String baseUrl = "https://api.e-iceblue.cn";
 static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
 static ImagesApi imagesApi = new ImagesApi(wordConfiguration);

 public static void main(String[] args) throws ApiException {
 String name = "Sample.docx";
 String paragraphPath = "Section/0/Body/0/Paragraph/2";
 Integer index = 0;
 String folder = "input";
 String storage = null;
 String password = null;
 System.out.println(imagesApi.getImageFormat(name, paragraphPath, index, password, folder, storage));
 }
}

:Java 操作Word中的文本可參考這篇文章。

到此這篇關(guān)于Java 添加、刪除、格式化Word中的圖片步驟詳解( 基于Spire.Cloud.SDK for Java )的文章就介紹到這了,更多相關(guān)Java 添加、刪除、格式化Word中的圖片內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 淺談同步監(jiān)視器之同步代碼塊、同步方法

    淺談同步監(jiān)視器之同步代碼塊、同步方法

    下面小編就為大家?guī)?lái)一篇淺談同步監(jiān)視器之同步代碼塊、同步方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-08-08
  • 初識(shí)JAVA數(shù)組

    初識(shí)JAVA數(shù)組

    java語(yǔ)言中,數(shù)組是一種最簡(jiǎn)單的復(fù)合數(shù)據(jù)類型。數(shù)組是有序數(shù)據(jù)的集合,數(shù)組中的每個(gè)元素具有相同的數(shù)據(jù)類型,可以用一個(gè)統(tǒng)一的數(shù)組名和下標(biāo)來(lái)唯一地確定數(shù)組中的元素。數(shù)組有一維數(shù)組和多維數(shù)組。
    2014-08-08
  • Java如何防止JS腳本注入代碼實(shí)例

    Java如何防止JS腳本注入代碼實(shí)例

    這篇文章主要介紹了Java如何防止JS腳本注入代碼實(shí)例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-09-09
  • Spring Cloud 服務(wù)網(wǎng)關(guān)Zuul的實(shí)現(xiàn)

    Spring Cloud 服務(wù)網(wǎng)關(guān)Zuul的實(shí)現(xiàn)

    這篇文章主要介紹了Spring Cloud 服務(wù)網(wǎng)關(guān)Zuul的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-07-07
  • JSON各種轉(zhuǎn)換問(wèn)題(json轉(zhuǎn)List,json轉(zhuǎn)對(duì)象等)

    JSON各種轉(zhuǎn)換問(wèn)題(json轉(zhuǎn)List,json轉(zhuǎn)對(duì)象等)

    這篇文章主要介紹了JSON各種轉(zhuǎn)換問(wèn)題(json轉(zhuǎn)List,json轉(zhuǎn)對(duì)象等),本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-03-03
  • idea perttier的使用和縮進(jìn)改為4不成功問(wèn)題及解決

    idea perttier的使用和縮進(jìn)改為4不成功問(wèn)題及解決

    這篇文章主要介紹了idea perttier的使用和縮進(jìn)改為4不成功問(wèn)題及解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-05-05
  • 詳解Java的Spring框架中的注解的用法

    詳解Java的Spring框架中的注解的用法

    這篇文章主要介紹了Java的Spring框架中的注解的用法,包括對(duì)Java bean的定義的作用介紹,需要的朋友可以參考下
    2015-11-11
  • mybatis if標(biāo)簽判斷不生效的解決方法

    mybatis if標(biāo)簽判斷不生效的解決方法

    這篇文章主要介紹了mybatis if標(biāo)簽判斷不生效的解決方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2021-02-02
  • java中Sources目錄Resources目錄的區(qū)別解讀

    java中Sources目錄Resources目錄的區(qū)別解讀

    這篇文章主要介紹了java中Sources目錄Resources目錄的區(qū)別解讀,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-12-12
  • IDEA一鍵部署SpringBoot項(xiàng)目到服務(wù)器的教程圖解

    IDEA一鍵部署SpringBoot項(xiàng)目到服務(wù)器的教程圖解

    本文通過(guò)圖文并茂的形式給大家介紹IDEA一鍵部署SpringBoot項(xiàng)目到服務(wù)器的教程,非常不錯(cuò),給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧
    2022-02-02

最新評(píng)論