Search in sources :

Example 1 with ExcelBigNumberConvert

use of com.ruoyi.common.excel.convert.ExcelBigNumberConvert in project RuoYi-Cloud-Plus by JavaLionLi.

the class ExcelUtil method exportExcel.

/**
 * 导出excel
 *
 * @param list      导出数据集合
 * @param sheetName 工作表的名称
 * @return 结果
 */
public static <T> void exportExcel(List<T> list, String sheetName, Class<T> clazz, HttpServletResponse response) {
    try {
        String filename = encodingFilename(sheetName);
        response.reset();
        FileUtils.setAttachmentResponseHeader(response, filename);
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8");
        ServletOutputStream os = response.getOutputStream();
        EasyExcel.write(os, clazz).autoCloseStream(false).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).registerConverter(new ExcelBigNumberConvert()).sheet(sheetName).doWrite(list);
    } catch (IOException e) {
        throw new RuntimeException("导出Excel异常");
    }
}
Also used : ServletOutputStream(javax.servlet.ServletOutputStream) ExcelBigNumberConvert(com.ruoyi.common.excel.convert.ExcelBigNumberConvert) IOException(java.io.IOException) LongestMatchColumnWidthStyleStrategy(com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy)

Aggregations

LongestMatchColumnWidthStyleStrategy (com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy)1 ExcelBigNumberConvert (com.ruoyi.common.excel.convert.ExcelBigNumberConvert)1 IOException (java.io.IOException)1 ServletOutputStream (javax.servlet.ServletOutputStream)1