Java와 GroupDocs.Editor를 사용한 docx를 docm으로 변환

현대 기업 워크플로우에서는 convert docx to docm을 프로그래밍 방식으로 수행하여 보고서 생성, 계약 맞춤화 및 템플릿 기반 커뮤니케이션을 자동화할 수 있습니다. GroupDocs.Editor for Java를 사용하면 서버에 Microsoft Office를 설치할 필요가 없으며 레이아웃 정확성을 유지하고, docx에서 텍스트를 교체하거나 word를 txt로 내보내거나 word를 rtf로 변환하는 기능을 단일 경량 API에서 제공받을 수 있습니다. 이 가이드는 DOCX 파일을 로드하고, 필요에 따라 HTML을 편집한 뒤 결과를 DOCM 또는 다른 인기 포맷으로 저장하는 과정을 안내합니다.

빠른 답변

  • Java에서 Word 문서를 편집할 수 있게 해주는 라이브러리는 무엇인가요? GroupDocs.Editor for Java.
  • 텍스트를 자동으로 교체할 수 있나요? 예 – HTML 마크업 API를 사용하면 문서 전체에서 문자열을 검색하고 교체할 수 있습니다.
  • 어떤 포맷으로 내보낼 수 있나요? DOCM, RTF, plain‑text (TXT), 등.
  • 개발에 라이선스가 필요합니까? 무료 체험판으로 테스트가 가능하며, 운영 환경에서는 상용 라이선스가 필요합니다.
  • Maven 프로젝트와 호환되나요? 물론입니다 – 저장소와 의존성을 추가하기만 하면 됩니다.

“edit word document java”란 무엇인가요?

메모리로 .docx 파일을 로드하고, API를 통해 내용(텍스트, 이미지, 표, 매크로)을 수정한 뒤, 업데이트된 파일을 디스크나 스트림에 다시 쓰는 것이 “edit word document java”가 의미하는 바입니다. GroupDocs.Editor는 Office Open XML 형식을 추상화하고 간단한 HTML 기반 편집 모델을 제공하여 문서를 웹 페이지처럼 다룰 수 있게 합니다.

Word 문서 편집을 위해 GroupDocs.Editor를 사용하는 이유

GroupDocs.Editor를 사용하면 convert docx to docm을 수행하고 Microsoft Office를 설치하지 않고도 대량 작업을 할 수 있습니다. 30개 이상의 입력 및 출력 포맷을 지원하며, 수백 페이지 파일을 200 MB 미만의 힙 메모리로 처리하고, 일반적인 8코어 서버에서 분당 150 문서의 batch process word docs 속도로 처리할 수 있습니다. 이 라이브러리는 DOCM 파일의 매크로를 보존하고 원래 스타일을 유지하며, 모든 Java 호환 플랫폼에서 실행됩니다.

전제 조건

  • Java 8 이상 및 빌드 도구(Maven 또는 Gradle).
  • GroupDocs.Editor for Java 라이브러리(버전 25.3 이상) 접근 권한.
  • Java와 Maven 의존성 관리에 대한 기본 지식.

GroupDocs.Editor for Java 설정

Maven을 통한 설치

Add the GroupDocs repository and dependency to your pom.xml:

<repositories>
    <repository>
        <id>repository.groupdocs.com</id>
        <name>GroupDocs Repository</name>
        <url>https://releases.groupdocs.com/editor/java/</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>com.groupdocs</groupId>
        <artifactId>groupdocs-editor</artifactId>
        <version>25.3</version>
    </dependency>
</dependencies>

직접 다운로드

Alternatively, download the latest JAR from the GroupDocs.Editor for Java releases page.

라이선스 획득

Start with a free trial to explore the API. For production workloads, obtain a temporary or full license from the GroupDocs portal.

기본 초기화 및 설정

Editor is the core class that provides loading, editing, and saving capabilities for Word documents. Create an Editor instance that points to your source DOCX file:

import com.groupdocs.editor.Editor;
import com.groupdocs.editor.options.WordProcessingLoadOptions;

String inputFilePath = "YOUR_DOCUMENT_DIRECTORY/sample.docx";
Editor editor = new Editor(inputFilePath, new WordProcessingLoadOptions());

Now you’re ready to load, edit, and save documents.

GroupDocs.Editor를 사용하여 docx를 docm으로 변환하는 방법

Load the DOCX, optionally modify its HTML, and then save the result as a DOCM file. The conversion requires only three API calls: instantiate Editor, load the document into an EditableDocument, and invoke save with Docm options. After saving, you can further process the DOCM, such as uploading it to a document management system or attaching it to an email, without losing any embedded macros or formatting.

단계 1: 문서 로드

EditableDocument represents a Word file that can be edited as HTML. Loading returns this object, which you can then manipulate.

import com.groupdocs.editor.Editor;
import com.groupdocs.editor.EditableDocument;
String inputFilePath = "YOUR_DOCUMENT_DIRECTORY/sample.docx";
Editor editor = new Editor(inputFilePath, new WordProcessingLoadOptions());
EditableDocument defaultWordProcessingDoc = editor.edit();

단계 2: (옵션) 내용 편집

If you need to replace placeholders, update the embedded HTML using standard string‑replace or regex techniques.

String allEmbeddedInsideString = defaultWordProcessingDoc.getEmbeddedHtml();
String modifiedContent = allEmbeddedInsideString.replace("Subtitle", "Edited subtitle");

단계 3: DOCM으로 저장

Configure the save options for the DOCM format and write the result to a file or a stream.

import com.groupdocs.editor.options.WordProcessingSaveOptions;
import com.groupdocs.editor.formats.WordProcessingFormats;

WordProcessingSaveOptions docmSaveOptions = new WordProcessingSaveOptions(WordProcessingFormats.Docm);
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;

String outputDocmPath = "YOUR_OUTPUT_DIRECTORY/editedDoc.docm";
try (OutputStream outputStream = new ByteArrayOutputStream()) {
    // Create a new EditableDocument from the (possibly) modified HTML
    EditableDocument editedDocDocm = EditableDocument.fromMarkup(modifiedContent, null);
    editor.save(editedDocDocm, outputStream, docmSaveOptions);
    // If you need a physical file, write the stream to disk here
}

Pro tip: Dispose of EditableDocument and Editor objects as soon as you’re done to free native resources and keep memory usage low.

문서를 RTF로 저장

Exporting to Rich Text Format is useful when downstream systems only understand RTF. The same EditableDocument can be saved with RTF options.

import com.groupdocs.editor.options.WordProcessingSaveOptions;
import com.groupdocs.editor.formats.WordProcessingFormats;

String outputRtfPath = "YOUR_OUTPUT_DIRECTORY/editedDoc.rtf";
WordProcessingSaveOptions rtfSaveOptions = new WordProcessingSaveOptions(WordProcessingFormats.Rtf);
EditableDocument editedDocRtf = EditableDocument.fromMarkup(modifiedContent, null);
editor.save(editedDocRtf, outputRtfPath, rtfSaveOptions);
editedDocRtf.dispose();
editor.dispose();

문서를 일반 텍스트로 저장

Plain‑text output is ideal for indexing, analytics, or feeding content into search engines.

import com.groupdocs.editor.options.TextSaveOptions;
import java.nio.charset.StandardCharsets;

TextSaveOptions textSaveOptions = new TextSaveOptions();
textSaveOptions.setEncoding(StandardCharsets.UTF_8);
textSaveOptions.setPreserveTableLayout(true);
String outputTxtPath = "YOUR_OUTPUT_DIRECTORY/editedDoc.txt";
editor.save(editedDocTxt, outputTxtPath, textSaveOptions);

실용적인 적용 사례

  1. 보고서 자동 생성 – 데이터베이스에서 데이터를 가져와 플레이스홀더를 교체하고 정교한 DOCX, DOCM 또는 RTF 보고서를 출력합니다.
  2. Word 템플릿 맞춤화 – 사용자 입력에 따라 마케팅 또는 법률 템플릿을 동적으로 채웁니다.
  3. Word를 txt로 내보내기 – 검색 인덱싱, 분석 또는 추가 처리를 위해 원시 텍스트를 추출합니다.
  4. docx에서 텍스트 교체 – HTML 마크업 API를 사용해 단일 배치 작업에서 다수 문서에 대해 대량 찾기‑교체를 수행합니다.

성능 고려 사항

  • Dispose of EditableDocument and Editor objects promptly to free native resources.
  • For very large files, process sections in chunks or use streaming APIs to keep memory usage under 250 MB.
  • Prefer StringBuilder or compiled regular expressions when performing bulk text replacements to minimise CPU overhead.

일반적인 문제와 해결책

The License class applies your GroupDocs.Editor license file to enable full functionality.

IssueSolution
File not found / access deniedVerify the absolute path and ensure the Java process has read/write permissions.
Out‑of‑memory errors on big docsIncrease JVM heap (-Xmx2g) or split the document into smaller parts before editing.
Formatting lost after replaceUse the HTML markup API carefully; avoid replacing markup tags themselves.
License not appliedCall License license = new License(); license.setLicense("path/to/license.file"); before creating Editor.

자주 묻는 질문

Q: 비밀번호로 보호된 Word 파일을 편집할 수 있나요?
A: Yes. Load the document with WordProcessingLoadOptions that include the password, then proceed as usual.

Q: GroupDocs.Editor가 DOCM 파일의 매크로를 지원하나요?
A: The library preserves macros but does not execute them. You can save a DOCM file with existing macros intact.

Q: 문서에 포함된 이미지는 어떻게 처리하나요?
A: Images are kept as part of the HTML markup. Replace the <img> tags or add new ones using standard HTML.

Q: PDF로 직접 변환할 수 있나요?
A: GroupDocs.Editor focuses on editing; for PDF conversion, combine it with GroupDocs.Conversion after saving the edited DOCX.

Q: 지원되는 Java 버전은 무엇인가요?
A: Java 8 and newer are fully supported.

결론

You now have a complete, end‑to‑end workflow to convert docx to docm using GroupDocs.Editor. By loading a DOCX, optionally editing its HTML, and exporting to DOCM, RTF, or plain‑text, you can automate countless document‑centric tasks in Java applications. Explore additional features such as spell‑checking, track changes, or integration with GroupDocs.Conversion to further extend your solution.


Last Updated: 2026-09-16
Tested With: GroupDocs.Editor 25.3 for Java
Author: GroupDocs

관련 튜토리얼