Search in sources :

Example 1 with OptionWriteHandler

use of com.diboot.file.excel.write.OptionWriteHandler in project diboot by dibo-software.

the class ExcelHelper method buildWriteSheet.

/**
 * 构建WriteSheet
 * <p>
 * 默认:自列适应宽、单元格下拉选项(验证)写入,批注写入
 *
 * @param sheetName      可指定sheetName
 * @param columnNameList 需要导出的ExcelModel列字段名称列表,为空时导出所有列
 * @param consumer
 * @param writeHandlers
 */
public static <T> void buildWriteSheet(String sheetName, Collection<String> columnNameList, BiConsumer<CommentWriteHandler, WriteSheet> consumer, WriteHandler... writeHandlers) {
    ExcelWriterSheetBuilder writerSheet = EasyExcel.writerSheet().sheetName(sheetName);
    CommentWriteHandler commentWriteHandler = new CommentWriteHandler();
    writerSheet.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy());
    writerSheet.registerWriteHandler(new OptionWriteHandler());
    writerSheet.registerWriteHandler(commentWriteHandler);
    for (WriteHandler handler : writeHandlers) {
        writerSheet.registerWriteHandler(handler);
    }
    if (V.notEmpty(columnNameList)) {
        writerSheet.includeColumnFiledNames(columnNameList);
    }
    consumer.accept(commentWriteHandler, writerSheet.build());
}
Also used : ExcelWriterSheetBuilder(com.alibaba.excel.write.builder.ExcelWriterSheetBuilder) OptionWriteHandler(com.diboot.file.excel.write.OptionWriteHandler) WriteHandler(com.alibaba.excel.write.handler.WriteHandler) OptionWriteHandler(com.diboot.file.excel.write.OptionWriteHandler) CommentWriteHandler(com.diboot.file.excel.write.CommentWriteHandler) CommentWriteHandler(com.diboot.file.excel.write.CommentWriteHandler) LongestMatchColumnWidthStyleStrategy(com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy)

Aggregations

ExcelWriterSheetBuilder (com.alibaba.excel.write.builder.ExcelWriterSheetBuilder)1 WriteHandler (com.alibaba.excel.write.handler.WriteHandler)1 LongestMatchColumnWidthStyleStrategy (com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy)1 CommentWriteHandler (com.diboot.file.excel.write.CommentWriteHandler)1 OptionWriteHandler (com.diboot.file.excel.write.OptionWriteHandler)1