mcpField
A
apache-poi

apache-poi

github.com/claude-dev-suiteDocuments4637 installsUpdated 2d ago
Repository

About apache-poi

apache-poi is a quick-reference skill for Java developers using Apache POI to read and generate Excel workbooks. It focuses on practical patterns, resource and memory handling, and common spreadsheet troubleshooting.

Key features

  1. 01Create and export Excel workbooks
  2. 02Apply reusable cell styles
  3. 03Stream large workbook writes
  4. 04Parse large files with event-based reading
  5. 05Diagnose common Excel and POI errors

Use cases

  1. 01Generate an Excel export from application data
  2. 02Serve workbook downloads from a REST endpoint
  3. 03Process large spreadsheets with lower memory use
  4. 04Resolve cell type or formatting problems

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/claude-dev-suite/claude-dev-suite --skill apache-poi

After installing, type/apache-poiin Claude Code to confirm it loaded.

Details

From the project README

Apache POI - Quick Reference

When NOT to Use This Skill

  • CSV files - Use OpenCSV, Apache Commons CSV, or Files.lines() for CSV
  • PDF generation - Use Apache PDFBox or iText instead
  • Large Excel files (> 100k rows) - Use SXSSFWorkbook or consider CSV export
  • Excel formulas/macros - POI has limited macro support; consider VBA alternatives
  • Real-time Excel editing - POI is for generation/parsing, not collaborative editing

Deep Knowledge: Use mcp__documentation__fetch_docs with technology: apache-poi for comprehensive API documentation, advanced formatting, and formula handling.

Pattern Essenziali

Maven
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>5.2.5</version>
</dependency>
Create Excel
try (Workbook workbook = new XSSFWorkbook()) {
    Sheet sheet = workbook.createSheet("Data");

    // Header
    Row header = sheet.createRow(0);
    header.createCell(0).setCellValue("Name");
    header.createCell(1).setCellValue("Email");

    // Data
    Row row = sheet.createRow(1);
    row.createCell(0).setCellValue("John");
    row.createCell(1).setCellValue("[email protected]");

    // Auto-size
    sheet.autoSizeColumn(0);
    sheet.autoSizeColumn(1);

    // Write
    workbook.write(new FileOutputStream("output.xlsx"));
}
Export Service
@Service
public class ExportService {
    public byte[] exportToExcel(List<User> users) throws IOException {
        try (Workbook wb = new XSSFWorkbook();
             ByteArrayOutputStream out = new ByteArrayOutputStream()) {
            Sheet sheet = wb.createSheet("Users");
            // ... populate rows
            wb.write(out);
            return out.toByteArray();
        }
    }
}
REST Download Endpoint
@GetMapping("/export")
public ResponseEntity<byte[]> export() throws IOException {
    byte[] data = exportService.exportToExcel(users);
    return ResponseEntity.ok()
        .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=data.xlsx")
        .contentType(MediaType.APPLICATION_OCTET_STREAM)
        .body(data);
}

Cell Styles

CellStyle headerStyle = workbook.createCellStyle();
Font font = workbook.createFont();
font.setBold(true);
headerStyle.setFont(font);
cell.setCellStyle(headerStyle);

Anti-Patterns

Anti-PatternWhy It's WrongCorrect Approach
Not closing workbookMemory leak, file locksUse try-with-resources: try (Workbook wb = new XSSFWorkbook())
Creating styles in loopsWorkbook has max 64,000 styles limitCreate styles once, reuse across cells
Using XSSFWorkbook for large filesOutOfMemoryError for > 100k rowsUse SXSSFWorkbook for streaming writes
Reading entire file into memoryMemory exhaustion on large filesUse event-based parsing (SAX) for reading
Not setting cell typesData interpreted incorrectlyExplicitly set cell type: cell.setCellType(CellType.NUMERIC)
Using autoSizeColumn() for every columnVery slow, especially with many rowsManually set widths or use sparingly
Hardcoding column indicesBrittle, breaks on column changesUse constants or column name maps
Generating Excel for large datasetsExcel has 1M row limit, slowConsider CSV or database export instead

Quick Troubleshooting

IssueDiagnosisSolution
OutOfMemoryError on large ExcelUsing XSSFWorkbook, all data in memorySwitch to SXSSFWorkbook for streaming
IllegalStateException: Cannot get a STRING value from a NUMERIC cellWrong cell type getterCheck type with cell.getCellType() before reading
File corrupted after generationWorkbook not closed properlyUse try-with-resources or explicitly call wb.close()
Styles not applyingExceeding 64,000 style limitReuse CellStyle objects, don't create in loops
Numbers displayed as text in ExcelCell type not setUse cell.setCellType(CellType.NUMERIC) and set value as number
Formula not calculatingFormula mode not setUse cell.setCellFormula("SUM(A1:A10)") or force recalc
Very slow generationautoSizeColumn() on large sheetsRemove or call only on critical columns
Date formatting incorrectDefault format not desiredCreate date CellStyle with custom format

Related Skills

References

Comments

Markdown supported