Search in sources :

Example 6 with WriteHandler

use of com.alibaba.excel.write.handler.WriteHandler in project diboot by dibo-software.

the class ExcelHelper method writeDynamicData.

/**
 * 简单将数据写入excel文件
 * <p>默认列宽自适应数据长度, 可自定义</p>
 *
 * @param filePath
 * @param sheetName
 * @param dataList
 * @param writeHandlers
 * @return
 */
@Deprecated
public static boolean writeDynamicData(String filePath, String sheetName, List<List<String>> dataList, WriteHandler... writeHandlers) throws Exception {
    try {
        ExcelWriterBuilder write = EasyExcel.write(filePath);
        write = write.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy());
        for (WriteHandler handler : writeHandlers) {
            write = write.registerWriteHandler(handler);
        }
        ExcelWriterSheetBuilder sheet = write.sheet(sheetName);
        sheet.doWrite(dataList);
        return true;
    } catch (Exception e) {
        log.error("数据写入excel文件失败", e);
        return false;
    }
}
Also used : ExcelWriterBuilder(com.alibaba.excel.write.builder.ExcelWriterBuilder) ExcelWriterSheetBuilder(com.alibaba.excel.write.builder.ExcelWriterSheetBuilder) WriteHandler(com.alibaba.excel.write.handler.WriteHandler) OptionWriteHandler(com.diboot.file.excel.write.OptionWriteHandler) CommentWriteHandler(com.diboot.file.excel.write.CommentWriteHandler) LongestMatchColumnWidthStyleStrategy(com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy) BusinessException(com.diboot.core.exception.BusinessException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

WriteHandler (com.alibaba.excel.write.handler.WriteHandler)6 CellWriteHandler (com.alibaba.excel.write.handler.CellWriteHandler)3 RowWriteHandler (com.alibaba.excel.write.handler.RowWriteHandler)3 SheetWriteHandler (com.alibaba.excel.write.handler.SheetWriteHandler)3 WorkbookWriteHandler (com.alibaba.excel.write.handler.WorkbookWriteHandler)3 LongestMatchColumnWidthStyleStrategy (com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy)3 CommentWriteHandler (com.diboot.file.excel.write.CommentWriteHandler)3 OptionWriteHandler (com.diboot.file.excel.write.OptionWriteHandler)3 Head (com.alibaba.excel.metadata.Head)2 ExcelWriterBuilder (com.alibaba.excel.write.builder.ExcelWriterBuilder)2 ExcelWriterSheetBuilder (com.alibaba.excel.write.builder.ExcelWriterSheetBuilder)2 BusinessException (com.diboot.core.exception.BusinessException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 NotRepeatExecutor (com.alibaba.excel.event.NotRepeatExecutor)1 ExcelContentProperty (com.alibaba.excel.metadata.property.ExcelContentProperty)1 CellWriteHandlerContext (com.alibaba.excel.write.handler.context.CellWriteHandlerContext)1 AbstractVerticalCellStyleStrategy (com.alibaba.excel.write.style.AbstractVerticalCellStyleStrategy)1 AbstractHeadColumnWidthStyleStrategy (com.alibaba.excel.write.style.column.AbstractHeadColumnWidthStyleStrategy)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1