Excel 통합 문서에서 민감한 데이터를 숨기는 것은 내부 또는 파트너와 보고서를 공유하는 기업에게 일반적인 요구 사항입니다. GroupDocs.Merger Cloud SDK for Java은 개발자가 간단한 REST API를 통해 XLSX 파일에 비밀번호 보호를 추가할 수 있게 합니다. 이 가이드에서는 REST를 사용한 Java에서 Excel 비밀번호 보호 구현 방법을 배우고, 완전한 Java 예제를 확인하며, 클라우드 통합을 위한 동등한 cURL 명령을 실행하는 방법을 다룹니다.
필수 조건 및 설정
시작하기 전에 다음 항목을 확인하십시오:
- Java 8 이상이 설치되어 있어야 합니다.
- 의존성 관리를 위한 Maven 또는 Gradle.
- client ID 및 client secret이 포함된 GroupDocs Cloud 계정.
- Excel 파일이 저장될 클라우드 스토리지에 대한 액세스.
Maven 종속성을 pom.xml에 추가하세요 (또는 해당하는 Gradle 스니펫):
<dependency>
<groupId>com.groupdocs</groupId>
<artifactId>groupdocs-merger-cloud</artifactId>
<version>25.11</version>
</dependency>
최신 JAR 파일은 다운로드 페이지에서 다운로드할 수 있습니다. 종속성을 추가한 후, 자격 증명을 사용하여 구성 객체를 생성합니다:
String clientId = "YOUR_CLIENT_ID";
String clientSecret = "YOUR_CLIENT_SECRET";
Configuration config = new Configuration(clientId, clientSecret);
MergerApi mergerApi = new MergerApi(config);
클라이언트를 준비했으면 실제 비밀번호 보호 워크플로우로 진행할 수 있습니다.
REST를 사용한 Java에서 Excel 암호 보호: 단계별 안내
1단계: 원본 문서 로드
클라우드 스토리지 내에서 원본 XLSX 파일의 위치를 정의합니다.
FileInfo inputFile = new FileInfo();
inputFile.setFilePath("input.xlsx"); // source Excel file
2단계: 대상 경로 설정
보호된 워크북이 저장될 위치를 지정합니다.
String outputPath = "output_protected.xlsx"; // destination file
3단계: 비밀번호 보호 옵션 구성
ProtectOptions 객체를 생성하고 파일 정보, 출력 경로 및 원하는 비밀번호를 첨부합니다.
ProtectOptions protectOptions = new ProtectOptions();
protectOptions.setFileInfo(inputFile);
protectOptions.setOutputPath(outputPath);
protectOptions.setPassword("MySecretPassword"); // desired password
단계 4: 보호 문서 요청 만들기
옵션을 ProtectDocumentRequest에 래핑합니다.
ProtectDocumentRequest request = new ProtectDocumentRequest(protectOptions);
5단계: 요청 실행 및 응답 처리
API 메서드를 호출하고 오류를 처리합니다.
try {
mergerApi.protectDocument(request);
System.out.println("Excel file has been password protected successfully.");
System.out.println("Protected file stored at: " + outputPath);
} catch (ApiException e) {
System.err.println("Error while protecting the Excel file:");
System.err.println("Status Code: " + e.getCode());
System.err.println("Message: " + e.getMessage());
}
각 클래스에 대한 자세한 내용은 API reference를 참조하십시오.
REST를 통해 Java에서 Excel 암호 보호를 위한 전체 작업 예제
다음 코드는 시작부터 끝까지 전체 프로세스를 보여줍니다.
import com.groupdocs.merger.cloud.ApiException;
import com.groupdocs.merger.cloud.Configuration;
import com.groupdocs.merger.cloud.api.MergerApi;
import com.groupdocs.merger.cloud.model.FileInfo;
import com.groupdocs.merger.cloud.model.ProtectOptions;
import com.groupdocs.merger.cloud.model.requests.ProtectDocumentRequest;
public class ProtectExcelExample {
public static void main(String[] args) {
// Replace with your actual client credentials
String clientId = "YOUR_CLIENT_ID";
String clientSecret = "YOUR_CLIENT_SECRET";
// Initialize the API configuration
Configuration config = new Configuration(clientId, clientSecret);
MergerApi mergerApi = new MergerApi(config);
// Define input and output file locations (relative to the storage root)
FileInfo inputFile = new FileInfo();
inputFile.setFilePath("input.xlsx"); // source Excel file
String outputPath = "output_protected.xlsx"; // destination file
// Set password protection options
ProtectOptions protectOptions = new ProtectOptions();
protectOptions.setFileInfo(inputFile);
protectOptions.setOutputPath(outputPath);
protectOptions.setPassword("MySecretPassword"); // desired password
// Build the request
ProtectDocumentRequest request = new ProtectDocumentRequest(protectOptions);
try {
// Execute the password protection operation
mergerApi.protectDocument(request);
System.out.println("Excel file has been password protected successfully.");
System.out.println("Protected file stored at: " + outputPath);
} catch (ApiException e) {
System.err.println("Error while protecting the Excel file:");
System.err.println("Status Code: " + e.getCode());
System.err.println("Message: " + e.getMessage());
}
}
}
Note: 이 코드 예제는 핵심 기능을 보여줍니다. 프로젝트에서 사용하기 전에 파일 경로(
input.xlsx,output_protected.xlsx)를 실제 파일 위치에 맞게 업데이트하고, 모든 필수 종속성이 올바르게 설치되었는지 확인한 뒤 개발 환경에서 충분히 테스트하십시오. 문제가 발생하면 공식 문서를 참조하거나 지원 팀에 문의하십시오.
cURL을 사용한 REST API로 Excel 워크북 보호
아래는 REST 엔드포인트에 직접 대해 동일한 비밀번호 보호 작업을 수행하는 cURL 명령 집합입니다.
1. 인증하고 액세스 토큰을 얻으세요
curl -X POST "https://api.groupdocs.cloud/v2.0/auth/token" \
-H "Content-Type: application/json" \
-d '{
"client_id": "YOUR_CLIENT_ID",
"client_secret": "YOUR_CLIENT_SECRET"
}'
응답에는 이후 호출에서 사용할 access_token이 포함되어 있습니다.
2. 소스 XLSX 파일 업로드
curl -X PUT "https://api.groupdocs.cloud/v2.0/storage/file/input.xlsx" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/octet-stream" \
--data-binary @input.xlsx
3. 비밀번호 보호 요청
curl -X POST "https://api.groupdocs.cloud/v2.0/merger/protect" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"fileInfo": { "filePath": "input.xlsx" },
"outputPath": "output_protected.xlsx",
"password": "MySecretPassword"
}'
4. 보호된 워크북 다운로드
curl -X GET "https://api.groupdocs.cloud/v2.0/storage/file/output_protected.xlsx" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-o output_protected.xlsx
이 명령을 사용하면 보호 워크플로를 스크립트나 CI 파이프라인에 통합할 수 있습니다. 자세한 내용은 공식 API 문서를 참조하세요.
결론
REST를 사용한 Java에서 Excel 비밀번호 보호 구현은 GroupDocs.Merger Cloud SDK for Java를 사용하면 간단합니다. 위 단계들을 따라 하면 Excel 워크북을 보호하고, 서버‑사이드 애플리케이션에서 프로세스를 자동화하며, 민감한 데이터를 안전하게 유지할 수 있습니다. 프로덕션 사용을 위해 적절한 라이선스를 확보하는 것을 기억하세요; 가격 정보는 제품 페이지에서 확인할 수 있으며, 라이브러리를 평가하기 위해 temporary license를 시작할 수 있습니다. 즐거운 코딩 되세요!
자주 묻는 질문
Java에서 REST를 통해 Excel에 비밀번호 보호를 적용하는 것이 로컬 암호화와 어떻게 다릅니까?
클라우드 API는 서버에서 암호화를 수행하므로 로컬에서 암호화 라이브러리를 관리할 필요가 없습니다. SDK는 요청 구성 및 응답 구문 분석을 처리하여 통합을 단순화합니다.추가 보호 옵션(예: 읽기 전용 모드)을 설정할 수 있나요?
현재ProtectOptions클래스는 비밀번호 보호에 중점을 두고 있습니다. 보다 고급 보안 기능에 대해서는 최신 매개변수가 있는지 API reference를 확인하십시오.비밀번호 보호를 지원하는 파일 형식은 무엇인가요?
Merger API는 현재 암호화를 위해 XLSX, DOCX, PPTX, 및 PDF를 지원합니다. 전체 목록은 공식 문서를 참조하십시오.개발 환경에서 예제를 실행하려면 라이선스가 필요합니까?
개발 및 테스트는 임시 라이선스로 수행할 수 있습니다. 프로덕션 배포에는 유료 라이선스가 필요하며, 제품 페이지를 통해 구매할 수 있습니다.
