Java로 Word 문서에 문서 속성 추가
I’m happy to translate the article for you, but I need the full text you’d like translated. Could you please paste the content (excluding the source line you already provided) here? Once I have the text, I’ll translate it into Korean while preserving the original formatting, markdown syntax, and technical terms.
왜 Java용 Spire.Doc을 사용해야 할까요?
Spire.Doc for Java는 전문 API로, 서버에 Microsoft Word를 설치하지 않고 Word 문서를 생성, 편집, 변환 및 인쇄할 수 있습니다. 기능 세트에는 다음이 포함됩니다:
- 텍스트 조작
- 표 처리
- 이미지 처리
- 문서 속성 관리
사용이 간편하고 포괄적인 기능 덕분에 Java에서 Word‑문서 작업을 자동화하기 위한 훌륭한 선택입니다.
프로젝트에 Spire.Doc 추가하기
Maven을 사용하는 경우, 리포지토리와 의존성을 pom.xml에 추가하십시오:
<repositories>
<repository>
<id>e-iceblue</id>
<url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.doc</artifactId>
<version>13.12.2</version>
</dependency>
</dependencies>
내장 문서 속성
내장 속성은 모든 Word 문서에 미리 정의된 필드입니다. 표준 메타데이터를 제공하여 문서를 분류, 검색 및 관리하기 쉽게 합니다. 일반적인 내장 속성에는 다음이 포함됩니다:
| 속성 | 설명 |
|---|---|
| Title | 문서의 주요 제목 |
| Author | 문서 작성자 |
| Subject | 내용에 대한 간략한 설명 |
| Keywords | 검색을 위한 중요한 용어 |
| Company | 문서와 관련된 조직 |
| Manager | 문서 담당 관리자 |
| Category | 문서가 속한 카테고리 |
| Comments | 일반적인 비고 또는 메모 |
Spire.Doc을 사용한 내장 속성 설정
import com.spire.doc.BuiltinDocumentProperties;
import com.spire.doc.Document;
import com.spire.doc.FileFormat;
public class AddBuiltinDocumentProperties {
public static void main(String[] args) throws Exception {
// Create a Document instance and load a Word file
Document document = new Document();
document.loadFromFile("Sample.docx");
// Access the built‑in document properties
BuiltinDocumentProperties props = document.getBuiltinDocumentProperties();
// Set property values
props.setTitle("Add Document Properties");
props.setSubject("Java Example");
props.setAuthor("James");
props.setCompany("Eiceblue");
props.setManager("Michael");
props.setCategory("Document Manipulation");
props.setKeywords("Java, Word, Document Properties");
props.setComments("This article shows how to add document properties");
// Save the updated document
document.saveToFile("AddStandardDocumentProperties.docx",
FileFormat.Docx_2013);
}
}
이 예제에서:
Document객체를 생성하고 Word 파일을 로드합니다.getBuiltinDocumentProperties()는BuiltinDocumentProperties컬렉션을 반환합니다.- Setter 메서드(예:
setTitle(),setAuthor())가 값을 할당합니다. - 문서를 새로운 메타데이터와 함께 저장합니다.
사용자 정의 문서 속성
내장 속성은 일반적인 메타데이터를 다루지만, 많은 경우 조직이나 프로젝트에 특화된 사용자 정의 속성이 필요합니다. 사용자 정의 속성을 사용하면 원하는 이름을 정의하고 텍스트, 숫자, 불리언, 날짜 등 다양한 데이터 유형의 값을 저장할 수 있습니다.
일반적인 사용 사례
- 프로젝트 관리 – 프로젝트 ID, 버전 번호, 클라이언트 이름
- 문서 워크플로 – 승인 상태, 검토자, 마지막 수정자
- 내부 분류 – 부서, 보안 수준, 보존 정책
- 자동 처리 – 다른 시스템의 트리거로 사용되는 속성
Spire.Doc으로 사용자 정의 속성 추가하기
import com.spire.doc.CustomDocumentProperties;
import com.spire.doc.Document;
import com.spire.doc.FileFormat;
import java.util.Date;
public class AddCustomDocumentProperties {
public static void main(String[] args) throws Exception {
// Create a Document instance and load a Word file
Document document = new Document();
document.loadFromFile("Sample.docx");
// Access the custom document properties collection
CustomDocumentProperties customProps = document.getCustomDocumentProperties();
// Add custom properties with different data types
customProps.add("Document ID", 1); // Integer
customProps.add("Authorized", true); // Boolean
customProps.add("Authorized By", "John Smith"); // String
customProps.add("Authorized Date", new Date()); // Date
// Save the updated document
document.saveToFile("AddCustomDocumentProperties.docx",
FileFormat.Docx_2013);
}
}
코드 설명
- Initialize
Document객체를 생성하고 기존 Word 파일을 로드합니다. getCustomDocumentProperties()를 통해CustomDocumentProperties컬렉션을 가져옵니다.add(propertyName, value)를 사용해 다양한 유형의 속성을 삽입합니다.- 이제 사용자 정의 메타데이터가 포함된 문서를 저장합니다.
요약
- Built‑in properties는 표준 메타데이터(제목, 저자 등)를 제공합니다.
- Custom properties를 사용하면 필요한 추가 정보를 유연한 데이터 유형으로 저장할 수 있습니다.
- Spire.Doc for Java API는 두 종류의 속성을 읽고, 수정하고, 저장할 수 있는 간단하고 유창한 메서드를 제공합니다.
이러한 기술을 Java 애플리케이션에 적용하면 문서 분류를 자동화하고, 검색 가능성을 향상시키며, Word 파일을 다른 비즈니스 프로세스와 보다 긴밀하게 통합할 수 있습니다. 즐거운 코딩 되세요!
사용자 정의 문서 속성 추가
stomDocumentProperties()
add() 메서드를 사용하여 새 사용자 정의 속성을 만들고, 속성 이름과 값을 지정합니다. Spire.Doc은 기본 데이터 유형 변환을 자동으로 처리합니다.
Viewing the Added Properties
After running these examples, you can open the generated Word document and navigate to:
- File → Info → Properties → Advanced Properties
- Click the Custom tab to see your added custom properties.
- Use the Summary or Statistics tabs to view built‑in properties.
왜 이것이 중요한가
Java와 Spire.Doc for Java를 사용하여 Word 파일에 문서 속성을 추가하는 기술을 마스터하는 것은 문서 자동화에 관여하는 모든 개발자에게 귀중한 기술입니다.
- 표준 내장 속성은 일반 메타데이터를 제공합니다.
- 사용자 정의 속성을 사용하면 유연하고 애플리케이션 중심의 정보를 저장할 수 있습니다.
이 메타데이터를 삽입하면 Word 문서의 검색 가능성, 조직화 및 전반적인 활용도가 크게 향상됩니다. 이러한 기능은 현대 문서 관리 시스템에서 매우 중요하며, 다음을 가능하게 합니다:
- 강력한 검색 기능
- 자동화된 워크플로
- 효율적인 정보 검색
Spire.Doc for Java를 더욱 실험해 보시고, Java 애플리케이션에서 그 방대한 잠재력을 탐구해 보시길 권장합니다.
코딩 즐겁게!