前言:
Spire.Cloud 在線編輯器是一款基于網頁的 Office 檔案編輯工具,支持在網頁中打開、編輯、列印 Word、Excel、PPT 檔案,支持將檔案保存到私有云盤,支持 IE、Chrome、FireFox、搜狗、遨游、360 等常見瀏覽器,Spire.Cloud Web API 能幫助開發人員能在任何時間、任何地點直接呼叫 SDK 介面對 Word、Excel、PPT、PDF 檔案進行操作,Spire.Cloud 支持 .NET、Java、PHP、Python、JavaScript 等多種編程語言,并提供了 1 萬次的免費呼叫次數及 2G 檔案記憶體,
本文將通過實體闡述如何通過Spire.Cloud.Word API給開發人員提供的EncryptApi介面,來加密保護Word檔案以及使用在線編輯器查看生成檔案,
詳細步驟:
1、通過冰藍云官網(https://cloud.e-iceblue.cn/)注冊賬號并登陸,在“我的應用”版塊創建應用程式,獲得App ID及App Key,

2、上傳Word檔案至冰藍云官網的“檔案管理”版塊,為了便于檔案管理,您也可以先創建檔案夾“input”和“output”,然后將需要編輯的Word檔案上傳至input檔案夾下,output檔案夾用于存放生成的檔案,

3、創建Maven應用程式,通過Maven倉庫安裝Spire.Cloud.SDK jar包及依賴,詳細步驟參考文章 ,
<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>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.5.18</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<artifactId>okhttp</artifactId>
<version>2.7.5</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<artifactId>logging-interceptor</artifactId>
<version>2.7.5</version>
</dependency>
<dependency>
<groupId> com.squareup.okio </groupId>
<artifactId>okio</artifactId>
<version>1.6.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId>io.gsonfire</groupId>
<artifactId>gson-fire</artifactId>
<version>1.8.0</version>
</dependency>
<dependency>
<groupId>org.threeten</groupId>
<artifactId>threetenbp</artifactId>
<version>1.3.5</version>
</dependency>
</dependencies>
4、新建Java class,呼叫Spire.Cloud.Word API為input檔案夾下的示例檔案設定密碼,
Java代碼:
import spire.cloud.word.sdk.client.*; import spire.cloud.word.sdk.client.api.EncryptApi; public class EncryptWord { static String appId = "App ID"; static String appKey = "App Key"; static String baseUrl = "https://api.e-iceblue.cn"; //配置App ID和App Key static Configuration wordConfiguration = new Configuration(appId, appKey); //創建EncryptApi實體 static EncryptApi encryptApi = new EncryptApi(wordConfiguration); public static void main(String[] args) throws ApiException { //原檔案名稱 String name = "test.docx"; //存放原檔案的檔案夾,沒有則為null String folder = "input"; //原檔案密碼,沒有則為null String oldPassword = null; //輸入新密碼加密保護檔案 String newPassword = "123456"; //使用冰藍云配置的2G空間存貯檔案,可設定為null String storage = null; //指定生成檔案的存放路徑 String destFilePath = "output/encryptWord.docx"; //呼叫encryptDocument方法對檔案進行加密 encryptApi.encryptDocument(name, destFilePath, folder, storage, oldPassword, newPassword); } }
使用Spire.Cloud在線編輯打開加密后的Word檔案效果圖:

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/122649.html
標籤:Java
