1. Introduction: Why 'Excel' Again?
One of the most common yet challenging requirements in enterprise solution development is undoubtedly **'Excel processing'**. Users in real-world business environments want more than just viewing flashy dashboards on web screens: they want to query complex multi-header grid data, download templates formatted in a group-based tree structure, work offline, and then bulk-upload the results back into the system.
For a long time, Apache POI was effectively the standard for Excel processing in the Java backend ecosystem. Thanks to its abundant references in the open-source ecosystem and the overwhelming advantage of being free, most projects start with POI. However, when the following complex business requirements are combined, development teams run into a massive technical barrier.
-
Generating group-field templates with **complex hierarchical multi-headers (Multi-Header)** and tree structures
-
When introducing a high-performance spreadsheet component such as SpreadJSin a web UI, formatting/data synchronization discrepancies can occur between the frontend and backend
-
Beyond simple value input/output, SUMPRODUCT, DSUM, and other advanced statistical/formula calculation enginesserver-side real-time evaluation of
-
When processing tens of thousands to hundreds of thousands of rows, JVM OutOfMemoryError(OOM) and GC spikes occur
This article examines the actual limitations encountered in an Apache POI environment and shares our experience of innovating the architecture by adopting **DsExcel (Document Solutions for Excel, formerly GcExcel)**. In particular, it covers the synergy of native JSON integration with SpreadJS on the frontend, as well as the strategies for importing tree-structured templates, exporting multi-header grids, and processing complex formulasthat we once carefully considered during domain modeling and data design, in detail at the code and architecture levels.
2. In-Depth Comparison of Backend Excel Engines: Apache POI vs DsExcel
The key factors to consider when choosing an Excel library for the backend are memory architecture, formula calculation engine, template productivity, and licensing costs.
2.1 Architecture and Memory Management Models
The Duality of Apache POI (XSSFWorkbook vs SXSSFWorkbook)
-
XSSFWorkbook (DOM model): Loads all sheets, rows, cells, and style objects in an Excel file (XLSX) into the JVM heap as a complete object graph. Once the data exceeds tens of thousands of entries, numerous Java wrapper objects are created for each cell, causing memory usage to increase exponentially and quickly resulting in OOM.
-
SXSSFWorkbook (streaming window model): To overcome OOM, it retains only a sliding window in memory (for example, the most recent 100 rows) and flushes the rest to temporary files on disk. However, it comes with serious limitations.
-
It is impossible to modify rows that have already passed or access them in reverse order.
-
Dynamically recalculating merged cells (Merged Region) or hierarchical headers is extremely difficult.
-
Calculating cross-sheet reference formulas and supporting pivot tables is nearly impossible.
-
When generating template-based reports, it is difficult to read the formatting of an existing template while simultaneously performing streaming write operations (Read-Write Template).
DsExcel's High-Performance Engine Architecture
-
DsExcel perfectly emulates Microsoft Excel's calculation engine and internal data structures while using a highly optimized memory-mapped structure suited to Java/.NET environments.
-
Memory optimization based on pointers and primitive arrays: Rather than endlessly creating heavy instances for each cell like POI, it caches data and styles based on internal indexes, limiting heap usage to approximately 1/5 to 1/10 that of POI.
-
It can generate and parse workbooks with hundreds of thousands of rows or more at high speed entirely in memory, without temporary disk I/O.
2.2 Differences in the Formula Calculation Engine
In practice, support for frequently requested formulas such as SUMPRODUCT, DSUM, INDEX/MATCH, XLOOKUP, and dynamic arrays (Spill) is a decisive measure of an engine's maturity.
-
Apache POI: Although FormulaEvaluator is built in, the list of supported functions is limited. In particular, when evaluating SUMPRODUCT, which performs multi-condition array operations, or database functions (DSUM, DCOUNT), implementations are often missing, or NotImplementedException is frequently thrown when parsing complex nested parentheses.
-
DsExcel: It includes an independent, high-performance formula calculation engine that is 100% compatible with Microsoft Excel specifications and can perfectly calculate more than 450 standard Excel functions offline (server-side). It guarantees complete formula consistency without installing Excel Desktop or Office Interop (Interop).
2.3 Template Binding Productivity
-
POI approach: After loading a designed Excel format, developers must manually count row/column indexes (rowNum++, cellNum++) and inject font, border, and background-color styles through Java code. Even if a planner or designer changes just one line of formatting, the entire backend index calculation logic breaks.
-
DsExcel approach: Powerful Declarative Template Engineis provided by default. If you write syntax such as {{ds.fieldName}} and {{ds.group(R=T)}} directly in the Excel file, the backend can automatically complete repeated row expansion, subtotal/total insertion, and dynamic cell merging simply by passing a Java POJO or JSON dataset.
2.4 Comprehensive Comparison Matrix
|
Comparison Item |
Apache POI (XSSF / SXSSF) |
DsExcel (Document Solutions for Excel) |
|---|---|---|
|
License |
Open source (Apache License 2.0, free) |
Commercial license (MESCIUS, developer/core license) |
|
Memory Footprint |
XSSF: Very high / SXSSF: Low |
Very low and stable due to in-memory optimization |
|
Streaming Limitations |
Restrictions on reading/modification and no formula calculation |
Full interface support (random access available) |
|
SpreadJS Integration |
Nonstandard (XLSX byte parsing required) |
Native support (full compatibility with fromJson and toJson) |
|
Formula Calculation Support |
Focused mainly on basic functions, with limitations on advanced formulas |
Supports all 450+ Excel functions and dynamic arrays |
|
Template Engine |
None (manual coding required) |
Built-in declarative template syntax |
|
Document Conversion Features |
Requires integration with separate tools |
Direct support for PDF, HTML, and image conversion |
3. Synergy with the Front End (SpreadJS): A Complete Full-Stack Excel Pipeline
For systems that have adopted SpreadJSas the front-end grid component, choosing DsExcel as the backend engine is not merely an alternative but an essential design decision.
3.1 Lossless Native JSON Exchange (Zero-Fidelity Loss)
Generally, exporting or importing the contents of a web screen (grid) to or from a server-side Excel file requires going through the following complex bottleneck steps.
-
Existing Approach (SpreadJS + Apache POI):
a. Generate an XLSX binary blob on the client (SpreadJS)
b. Transmit several MB of binary data over the network
c. On the backend, POI decompresses the ZIP archive and parses thousands of XML files
d. After modification, compress the data back into a ZIP archive and return it to the client
-Issues: CPU overload, wasted transmission bandwidth, and loss of advanced CSS/themes/conditional formatting that POI cannot interpret.
-
Modern Architecture (SpreadJS + DsExcel):
-SpreadJS and DsExcel share the **same data schema and JSON specification (SpreadJS JSON Format)**.
-The client transmits only the grid's serialized JSON string (spread.toJSON()).
-The backend (DsExcel) reads it in a single line.
Workbook workbook = new Workbook();
workbook.fromJson(spreadJsonString);
-After performing business logic operations, large-scale data merging, and masking on the server, it can either return the result using workbook.toJson() or immediately render it as a final-distribution .xlsx or .pdf file.
3.2 Lossless Preservation of Styles, Multiple Merges, and Conditional Formatting
Multi-level header spans (Span), font hierarchies, data bars (Data Bar), color scales, and dropdown data validation rules configured by users in SpreadJS are reflected in the backend DsExcel with 100% fidelity. The structural problems encountered when using POI—having to map CellStyle individually and worry about index overflow—are completely eliminated.
4. Real-World Case Study: Resolving Complex Enterprise-Domain Issues
4.1 Case 1: Lossless Excel Import and Export for a Hierarchical Web Grid with Multi-Level Headers (Multi-Header)
-
Problem Definition:The web grid on the screen has a grouped header structure with three or more levels. To process this with POI, we had to recursively calculate horizontal and vertical merge coordinates using CellRangeAddress, and the coordinates became distorted whenever columns changed dynamically.
-
DsExcel + SpreadJS solution:By passing the SpreadJS Column Header structure directly into DsExcel using fromJson, the internal merge coordinates are preserved perfectly. This resolves inconsistencies between the header schemas on the server and the front end.
4.2 Case 2: Tree-structure Group-Field Data Import Template
-
Problem definition:The entity model had subcategories under major categories, with dynamic attribute fields grouped beneath them in a tree structure.
-
Applying the DsExcel template engine:By setting declarative markers such as {{ds.groupName(M=T)}} in the template XLSX and simply passing in the dataset, dynamic row expansion and cell merging were automated. The manual pointer-calculation logic was eliminated, maximizing maintainability.
4.3 Case 3: Processing Advanced Formulas (SUMPRODUCT, DSUM) and Server-Side Calculation
-
Problem definition:We needed to immediately validate the results of complex conditional weighting calculations in uploaded files on the server.
-
Solution strategy:By calling DsExcel's workbook.calculate(), the built-in Excel-compatible engine identifies all dependent cells and derives accurate results, avoiding the duplicated effort of reimplementing the mathematical logic in Java code.
4.4 Case 4: Domain Model Architecture for Attachment and Data Management
-
Architecture design:To prevent HTTP thread exhaustion during large-volume processing, we introduced an asynchronous queue pipeline (Spring Task / RabbitMQ) and used try-with-resources to immediately release DsExcel workbook resources, thereby maintaining stable JVM memory usage.
5. Practical Code Walkthrough: POI vs DsExcel
5.1 Apache POI Implementation Example (Manual Coordinate Mapping)
Workbook poiWorkbook = new XSSFWorkbook();
Sheet sheet = poiWorkbook.createSheet("계층형데이터");
Row headerRow1 = sheet.createRow(0);
headerRow1.createCell(0).setCellValue("조직 인프라 정보");
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 1));
int rowIndex = 2;
for (DepartmentDto dto : dataList) {
Row row = sheet.createRow(rowIndex++);
row.createCell(0).setCellValue(dto.getDivision());
// ... 인덱스 수동 관리 및 스타일 설정 생략
}
5.2 DsExcel + SpreadJS Pipeline Implementation Example
public byte[] generateExcelWithDsExcel(String spreadJsJson, List<DepartmentDto> dataList) {
try (Workbook workbook = new Workbook()) {
workbook.fromJson(spreadJsJson); // 프론트 디자인 로드
IWorksheet sheet = workbook.getActiveSheet();
sheet.addDataSource("dept", dataList); // 데이터 바인딩
workbook.calculate(); // 수식 재계산
ByteArrayOutputStream out = new ByteArrayOutputStream();
workbook.save(out, SaveFileFormat.Xlsx);
return out.toByteArray();
}
}
6. Conclusion and Adoption Decision Guide
6.1 When It Is Fine to Continue Using POI
-
Exporting raw data in a simple one-dimensional table format
-
Generating small Excel files with a fixed format (no more than a few thousand records)
-
Open-source projects that cannot invest in additional licensing costs
6.2 When Migration to DsExcel Is Strongly Recommended
-
SpreadJSProjects that require a perfect WYSIWYG environment by adopting
-
Managing templates containing complex multi-level headers, tree-structured data, and numerous merged cells
-
When server-side reliability evaluation of advanced formulas such as SUMPRODUCT and XLOOKUP is required
-
When system stability during large-volume processing is threatened by POI OOM failures
Closing remarks
In modern enterprise architectures, Excel is not merely a file but a collection of core business rules. The combination of DsExcel and SpreadJSwill give developers the freedom to move beyond the drudgery of coordinate calculations and focus on business logic.
BigJumbo