write (ExcelUtils)

ruoyi-office · files, excel-export, file-download, http-response, column-formatting

Writes an Excel file to the HTTP response with column width adaptation, dropdown sheets, and Long-to-String conversion to avoid precision loss, then sets download headers.

// Source: https://github.com/yuqing2026/ruoyi-office | License: MIT | Copyright 2021 yudao-cloud
// Provided via justclaw.it.com; keep this notice with the code.
    public static <T> void write(HttpServletResponse response, String filename, String sheetName,
                                 Class<T> head, List<T> data) throws IOException {
        // 输出 Excel
        FastExcelFactory.write(response.getOutputStream(), head)
                .autoCloseStream(false) // 不要自动关闭,交给 Servlet 自己处理
                .registerWriteHandler(new ColumnWidthMatchStyleStrategy()) // 基于 column 长度,自动适配。最大 255 宽度
                .registerWriteHandler(new SelectSheetWriteHandler(head)) // 基于固定 sheet 实现下拉框
                .registerConverter(new LongStringConverter()) // 避免 Long 类型丢失精度
                .sheet(she

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search 40K more like it.

Get a free API key