OfficeForge를 만나보세요: Microsoft Office를 오픈소스 자동화로 강화하세요
Source: Dev.to
Part I: 모든 언어의 개발자를 위한
어떤 언어에서도 동작하는 가벼운 CLI
OfficeForge는 Go를 사용하지 않고도 Microsoft Office 문서를 자동화할 수 있는 CLI 도구를 제공합니다. Python, Node.js, PHP, Bash 등 어떤 언어로 코딩하든, 서식은 그대로 유지하면서 Word 파일을 생성하고, 템플릿을 채우며, 문서를 일괄 처리할 수 있습니다.
Windows 아키텍처에 맞는 바이너리를 Releases 페이지에서 다운로드하여 시작하세요.
템플릿에서 단일 키워드 교체
officeforge docx-single --input template.docx --output output.docx --key "{{NAME}}" --value "John Doe"
CSV/JSON에서 다수 문서 생성
officeforge docx-batch --input template.docx --output ./contracts --data employees.csv
유연한 파일명 패턴
패턴을 사용해 생성되는 문서의 파일명을 제어할 수 있습니다:
# 순차 번호
officeforge docx-batch --input template.docx --output ./output --data employees.csv --pattern "contract_%03d.docx"
# 결과: contract_001.docx, contract_002.docx, contract_003.docx
# 데이터 기반 명명 (CSV에 NAME 열이 있어야 함)
officeforge docx-batch --input template.docx --output ./output --data employees.csv --pattern "{NAME}_contract.docx"
# 결과: Alice_contract.docx, Bob_contract.docx
# 여러 필드 사용 (CSV에 ID와 COMPANY 열이 있음)
officeforge docx-batch --input template.docx --output ./output --data clients.csv --pattern "{COMPANY}_{ID}_agreement.docx"
# 결과: Acme_001_agreement.docx, TechCorp_002_agreement.docx
# 데이터와 인덱스 결합
officeforge docx-batch --input template.docx --output ./output --data employees.csv --pattern "{DEPARTMENT}_report_{INDEX}.docx"
# 결과: Engineering_report_1.docx, Sales_report_2.docx
OfficeForge는 의존성이 전혀 없는 독립 실행 파일이므로, 시스템 명령을 실행할 수 있는 어떤 언어에서도 호출할 수 있습니다.
Node.js 예시 (child_process 사용)
import { exec } from "node:child_process";
import { promisify } from "node:util";
const execAsync = promisify(exec);
(async () => {
try {
const { stdout, stderr } = await execAsync(
`officeforge docx-batch --input template.docx --output ./contracts --data employees.csv --pattern "{EMPLOYEE_NAME} Contract.docx"`
);
if (stderr) console.error("CLI stderr:", stderr);
console.log("Success:", stdout);
} catch (err) {
console.error("Error:", err);
}
})();
Python 예시 (subprocess 사용)
import subprocess
cmd = [
"officeforge",
"docx-batch",
"--input", "template.docx",
"--output", "./contracts",
"--data", "employees.csv",
"--pattern", "{EMPLOYEE_NAME} Contract.docx"
]
result = subprocess.run(cmd, capture_output=True, text=True)
if result.returncode != 0:
print("Error:", result.stderr)
else:
print("Success:", result.stdout)
PHP 예시 (exec 사용)
&1", $output, $returnCode);
if ($returnCode !== 0) {
echo "Error:\n";
echo implode("\n", $output);
} else {
echo "Success:\n";
echo implode("\n", $output);
}
?>
Node.js, Python, PHP, Bash, Go 등 어떤 환경에서도 OfficeForge CLI를 이용하면 언어에 구애받지 않고 고속으로 DOCX를 자동 생성할 수 있습니다.
Part II: Go 개발자를 위한 네이티브 통합
Go 코드에 OfficeForge 직접 통합
Go 개발자를 위해 OfficeForge는 애플리케이션에 임베드할 수 있는 완전한 프로그래밍 라이브러리 형태로도 제공됩니다.
설치
go get github.com/siliconcatalyst/officeforge@latest
또는 혼용 사용을 위해 CLI만 설치하려면:
go install github.com/siliconcatalyst/officeforge/cmd/officeforge@latest
단일 키워드 교체
import "github.com/siliconcatalyst/officeforge/docx"
err := docx.ProcessDocxSingle("template.docx", "output.docx", "{{NAME}}", "John Doe")
if err != nil {
log.Fatal(err)
}
다중 교체
import "github.com/siliconcatalyst/officeforge/docx"
replacements := map[string]string{
"{{NAME}}": "John Doe",
"{{EMAIL}}": "john@example.com",
"{{DATE}}": "2025-12-07",
}
err := docx.ProcessDocxMulti("template.docx", "output.docx", replacements)
if err != nil {
log.Fatal(err)
}
일괄 문서 생성
import "github.com/siliconcatalyst/officeforge/docx"
records := []map[string]string{
{"NAME": "Alice", "EMAIL": "alice@example.com"},
{"NAME": "Bob", "EMAIL": "bob@example.com"},
}
// 순차 번호
err := docx.ProcessDocxMultipleRecords("template.docx", "./output", records, "contract_%03d.docx")
// 결과: contract_001.docx, contract_002.docx
// 레코드 필드 기반 명명
err = docx.ProcessDocxMultipleRecords("template.docx", "./output", records, "{NAME}_contract.docx")
// 결과: Alice_contract.docx, Bob_contract.docx
// 여러 필드 사용
err = docx.ProcessDocxMultipleRecords("template.docx", "./output", records, "{NAME}_{EMAIL}.docx")
// 결과: Alice_alice@example.com.docx, Bob_bob@example.com.docx
// 데이터와 인덱스 결합
err = docx.ProcessDocxMultipleRecords("template.docx", "./output", records, "employee_{INDEX}_{NAME}.docx")
// 결과: employee_1_Alice.docx, employee_2_Bob.docx
고급 명명 로직
import (
"fmt"
"github.com/siliconcatalyst/officeforge/docx"
)
nameFunc := func(record map[string]string, index int) string {
// 데이터에 기반한 사용자 정의 로직
if record["PRIORITY"] == "high" {
return fmt.Sprintf("urgent_%s_%d.docx", record["NAME"], index)
}
return fmt.Sprintf("standard_%s_%d.docx", record["NAME"], index)
}
err := docx.ProcessDocxMultipleRecordsWithNames("template.docx", "./output", records, nameFunc)