亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

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

瀏覽:107日期:2022-05-27 10:22:26

Spire.Cloud.SDK for Java提供了TextRangesApi接口可通過addTextRange()添加文本、deleteTextRange()刪除文本、updateTextRangeText()替換文本、updateTextRangeFormat()格式化文本等。本文將從以上方法介紹如何來實現對文本的操作。可參考以下步驟進行準備:

一、導入jar文件

創建Maven項目程序,通過maven倉庫下載導入。以IDEA為例,新建Maven項目,在pom.xml文件中配置maven倉庫路徑,并指定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>

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

導入結果:

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

二、登錄冰藍云賬號,創建文件夾,上傳文檔

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

三、創建應用程序,獲取App ID及App Key

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

完成以上步驟后,可參考以下代碼,進行文檔操作。

用于測試的Word源文檔如下:

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

1. 添加文本到Word

import spire.cloud.word.sdk.client.ApiException;import spire.cloud.word.sdk.client.Configuration;import spire.cloud.word.sdk.client.api.TextRangesApi;public class AddTextRange { //配置App賬號信息 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 TextRangesApi textRangesApi = new TextRangesApi(wordConfiguration); public static void main(String[] args) throws ApiException { String name = 'testfile.docx';//用于測試的Word源文檔 String paragraphPath = 'Section/0/Body/0/Paragraph/0';//獲取文檔中的段落 Integer indexInParagraph = 0; String text = '新添加的文本內容!';//指定需要添加的文本內容 String folder = 'input';//源文檔所在的云端文件夾 String storage = null;//冰藍云存儲空間 String password = null;//源文檔密碼 String destFilePath = 'output/AddTextRange.docx';//結果文檔路徑 //調用方法添加文本內容到Word段落 textRangesApi.addTextRange(name, paragraphPath, text, destFilePath, folder, storage, indexInParagraph, password); }}

文本添加效果:

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

2. 刪除Word中的文本

import spire.cloud.word.sdk.client.ApiException;import spire.cloud.word.sdk.client.Configuration;import spire.cloud.word.sdk.client.api.TextRangesApi;public class DeleteTextRange { //配置App賬號信息 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 TextRangesApi textRangesApi = new TextRangesApi(wordConfiguration); public static void main(String[] args) throws ApiException { String name = 'testfile.docx';//源文檔 String paragraphPath = 'Section/0/Body/0/Paragraph/0';//獲取段落 Integer index = 0; String folder = 'input';//源文檔所在文件夾 String storage = null;//冰藍云存儲空間 String password = null;//源文檔密碼 String destFilePath = 'output/DeleteTextRange.docx';//結果文檔路徑 //調用方法刪除Word第一段文本 textRangesApi.deleteTextRange(name, paragraphPath, index, destFilePath,folder, storage, password); }}

文本刪除效果:

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

3. 替換Word中的文本

import spire.cloud.word.sdk.client.ApiException;import spire.cloud.word.sdk.client.Configuration;import spire.cloud.word.sdk.client.api.TextRangesApi;public class UpdateTextRange { //配置App賬號信息 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 TextRangesApi textRangesApi = new TextRangesApi(wordConfiguration); public static void main(String[] args) throws ApiException { String name = 'testfile.docx';//源文檔 String paragraphPath = 'Section/0/Body/0/Paragraph/0';//獲取段落 Integer index = 0; String text = '新替換文本';//指定新文本 String folder = 'input';//源文檔所在文件夾 String storage = null; String password = null; String destFilePath = 'output/UpdateTextRangeText.docx';//結果文檔路徑 //調用方法更新(替換)原有的文本 textRangesApi.updateTextRangeText(name, paragraphPath, index, text, destFilePath, folder, storage, password); }}

文本替換效果:

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

4. 格式化Word中的文本

import spire.cloud.word.sdk.client.ApiException;import spire.cloud.word.sdk.client.Configuration;import spire.cloud.word.sdk.client.api.TextRangesApi;import spire.cloud.word.sdk.client.model.Color;import spire.cloud.word.sdk.client.model.Font;import spire.cloud.word.sdk.client.model.TextRangeFormat;public class UpdateTextRangeFormat { //配置App賬號信息 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 TextRangesApi textRangesApi = new TextRangesApi(wordConfiguration); public static void main(String[] args) throws ApiException { String name = 'testfile.docx';//源文檔 String paragraphPath = 'Section/0/Body/0/Paragraph/0';//獲取段落 Integer index = 0; //創建文本樣式,指定字體、顏色、字號,并應用到文本 TextRangeFormat format = new TextRangeFormat(); Color color = new Color(34,139,34); Font font = new Font('宋體', 20f, color); format.setFont(font); TextRangeFormat textRange = format; String folder = 'input';//源文檔所在文件夾 String storage = null; String password = null; String destFilePath = 'output/UpdateTextRangeFormat.docx';//結果文檔路徑 //調用方法更新(應用)文本樣式 textRangesApi.updateTextRangeFormat(name, paragraphPath, index, textRange, destFilePath, folder, storage, password); }}

文本格式設置效果:

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

到此這篇關于Java 添加、刪除、替換、格式化Word中的文本的步驟詳解(基于Spire.Cloud.SDK for Java)的文章就介紹到這了,更多相關Java 添加、刪除、替換、格式化Word中的文本內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: word
相關文章:
主站蜘蛛池模板: 中文字幕不卡免费视频 | 亚洲精品一区二区三区美女 | 91国内在线视频 | 一级做a爱片久久毛片 | 国产精品99久久久久久宅男 | 中文字幕综合在线 | 欧美精品一区二区久久 | 色婷婷丁香六月 | 成年视频xxxxx在线入口 | 免费a级毛片无码 | 播放毛片 | 成人看免费一级毛片 | 免费一级特黄特色大片在线观看看 | 亚洲第一区精品观看 | 免费的黄色小视频 | 亚洲第一页综合 | 日本免费黄色片 | 日韩精品免费一级视频 | 中国xxxx视频播放 | 欧美国产一区二区二区 | 精品一区二区三区在线成人 | 亚洲第一免费播放区 | 黄色一级视频免费看 | 国产精品免费看香蕉 | 国产一区二区免费视频 | 国产视频国产 | 国产一国产一级毛片视频 | 久久久国产99久久国产一 | 国产亚洲精品97在线观看 | 美女黄网站人色视频免费国产 | 国产三级一区 | 久久99国产精品久久99软件 | 日本黄色毛片 | 久久精品国产400部免费看 | 一区二区三区在线播放 | 晚上睡不着偷偷看b站免费是视频 | 欧美色图一区二区 | 国产精品成人久久久久 | 亚洲制服丝袜第一页 | 91av一区| 欧美三级毛片 |