Skip to content

Mars-Sea/doc-gen-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

25 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Doc-Gen-Service

πŸ‡¨πŸ‡³ δΈ­ζ–‡ζ–‡ζ‘£

License: MIT Java Spring Boot

A document generation microservice based on Spring Boot, using poi-tl for Word template rendering and EasyExcel for Excel operations. Provides RESTful APIs for external systems (e.g., Go services) to call, with Docker containerization support.

✨ Features

  • πŸ“„ Word Document Generation - Template-based dynamic document generation using poi-tl
  • πŸ“‘ Batch Word Generation - Generate multi-page documents from multiple data records
  • πŸ“Š Excel Generation - Dynamic Excel creation with EasyExcel
  • πŸ“‹ Excel Template Fill - Fill Excel templates with variables and list data
  • πŸ”„ Table Loop Rendering - Automatic detection and rendering of collection data
  • πŸ“€ Template Management - Upload and list template files via API
  • 🐳 Docker Ready - Multi-architecture support (amd64/arm64)
  • πŸ“š Go SDK - Ready-to-use Go client library

πŸ“ Changelog

v0.0.4 (2026-01-08)

  • πŸ› Fixed: Batch Word generation now correctly adds page breaks between documents
  • ⚑ Improved: Using poi-tl native NiceXWPFDocument.merge() for better document format preservation

πŸš€ Quick Start

Using Docker (Recommended)

# Build and run
mvn clean package -DskipTests
docker-compose up -d --build

# Access Swagger UI
open http://localhost:8081/swagger-ui.html

Local Development

# Build
mvn clean package -DskipTests

# Run
java -jar target/doc-gen-service-0.0.4.jar

πŸ“– API Reference

Generate Word Document

POST /api/v1/doc/word
Content-Type: application/json
{
  "templateName": "template.docx",
  "data": {
    "title": "My Report",
    "date": "2025-01-01"
  },
  "fileName": "output_report"
}

Batch Generate Word Document

Generate a single document with multiple pages from multiple data records.

POST /api/v1/doc/word/batch
Content-Type: application/json
{
  "templateName": "certificate.docx",
  "dataList": [
    {"name": "Alice", "award": "Gold"},
    {"name": "Bob", "award": "Silver"}
  ],
  "fileName": "certificates"
}

Generate Excel Document

POST /api/v1/doc/excel
Content-Type: application/json
{
  "sheetName": "Sheet1",
  "headers": ["Name", "Age", "City"],
  "data": [
    ["Alice", 25, "Beijing"],
    ["Bob", 30, "Shanghai"]
  ],
  "fileName": "employees"
}

Fill Excel Template

Fill Excel templates with variables {variable} and list data {.field}.

POST /api/v1/doc/excel/fill
Content-Type: application/json
{
  "templateName": "report-template.xlsx",
  "data": {"title": "Sales Report", "date": "2025-01-01"},
  "listData": {
    "items": [
      {"no": 1, "name": "Product A", "price": 100},
      {"no": 2, "name": "Product B", "price": 200}
    ]
  },
  "fileName": "sales_report"
}

Template Management

# Upload template
POST /api/v1/template/upload
Content-Type: multipart/form-data

# List templates
GET /api/v1/template/list

# Download template
GET /api/v1/template/download/{templateName}

# Delete template
DELETE /api/v1/template/{templateName}

πŸ”§ Configuration

Environment Variable Default Description
TEMPLATE_PATH ./templates Template files directory
SERVER_PORT 8081 Server port

πŸ“¦ Go SDK

go get github.com/Mars-Sea/doc-gen-service/sdk/[email protected]
client := docgen.NewClient("http://localhost:8081")

// Generate Word document
doc, _ := client.GenerateWord("template.docx", data, "report")
os.WriteFile("report.docx", doc, 0644)

// Batch generate Word document
dataList := []map[string]any{
    {"name": "Alice", "award": "Gold"},
    {"name": "Bob", "award": "Silver"},
}
batchDoc, _ := client.BatchGenerateWord("certificate.docx", dataList, "certificates")

// Fill Excel template
filledExcel, _ := client.FillExcelTemplate("template.xlsx", data, listData, "output")

🐳 Multi-Architecture Docker Build

# Build for ARM64
docker buildx build --platform linux/arm64 -t doc-gen-service:arm64 --load .

# Build for AMD64
docker buildx build --platform linux/amd64 -t doc-gen-service:amd64 --load .

πŸ“‹ Template Syntax

Word (poi-tl)

Syntax Description Example
{{variable}} Text replacement {{title}}
{{@image}} Image insertion {{@logo}}
{{#table}} Table loop {{#items}}
{{?condition}} Conditional {{?showHeader}}

Excel (EasyExcel)

Syntax Description Example
{variable} Single value {title}
{.field} List row loop {.name}, {.price}

πŸ› οΈ Tech Stack

Technology Version Purpose
Java 17 Runtime
Spring Boot 3.2.1 Web Framework
poi-tl 1.12.1 Word Template Engine
EasyExcel 4.0.1 Excel Processing
SpringDoc 2.3.0 API Documentation

πŸ“„ License

MIT License

πŸ”— Links

About

πŸ“„ Document generation microservice based on Spring Boot + poi-tl. RESTful API for Word/Excel template rendering. Docker & Go SDK supported.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors