use of com.alibaba.excel.write.builder.ExcelWriterBuilder in project easyexcel by alibaba.
the class EasyExcelFactory method write.
/**
* Build excel the write
*
* @param file
* File to write
* @param head
* Annotate the class for configuration information
* @return Excel writer builder
*/
public static ExcelWriterBuilder write(File file, Class head) {
ExcelWriterBuilder excelWriterBuilder = new ExcelWriterBuilder();
excelWriterBuilder.file(file);
if (head != null) {
excelWriterBuilder.head(head);
}
return excelWriterBuilder;
}
use of com.alibaba.excel.write.builder.ExcelWriterBuilder in project easyexcel by alibaba.
the class EasyExcelFactory method write.
/**
* Build excel the write
*
* @param pathName
* File path to write
* @param head
* Annotate the class for configuration information
* @return Excel writer builder
*/
public static ExcelWriterBuilder write(String pathName, Class head) {
ExcelWriterBuilder excelWriterBuilder = new ExcelWriterBuilder();
excelWriterBuilder.file(pathName);
if (head != null) {
excelWriterBuilder.head(head);
}
return excelWriterBuilder;
}
use of com.alibaba.excel.write.builder.ExcelWriterBuilder in project diboot by dibo-software.
the class ExcelHelper method writeData.
/**
* 简单将数据写入excel文件
* <p>默认列宽自适应数据长度、写入单元格下拉选项, 可自定义</p>
*
* @param filePath
* @param sheetName
* @param dataList
* @param <T>
* @return
*/
@Deprecated
public static <T extends BaseExcelModel> boolean writeData(String filePath, String sheetName, List<T> dataList, WriteHandler... writeHandlers) throws Exception {
try {
if (V.isEmpty(dataList)) {
return writeDynamicData(filePath, sheetName, Collections.emptyList());
}
Class<T> tClass = (Class<T>) dataList.get(0).getClass();
ExcelWriterBuilder write = EasyExcel.write(filePath, tClass);
write = write.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy());
for (WriteHandler handler : writeHandlers) {
write = write.registerWriteHandler(handler);
}
write.sheet(sheetName).doWrite(dataList);
return true;
} catch (Exception e) {
log.error("数据写入excel文件失败", e);
return false;
}
}
use of com.alibaba.excel.write.builder.ExcelWriterBuilder 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;
}
}
use of com.alibaba.excel.write.builder.ExcelWriterBuilder in project ballcat by ballcat-projects.
the class AbstractSheetWriteHandler method getExcelWriter.
/**
* 通用的获取ExcelWriter方法
* @param response HttpServletResponse
* @param responseExcel ResponseExcel注解
* @return ExcelWriter
*/
@SneakyThrows(IOException.class)
public ExcelWriter getExcelWriter(HttpServletResponse response, ResponseExcel responseExcel) {
ExcelWriterBuilder writerBuilder = EasyExcel.write(response.getOutputStream()).registerConverter(LocalDateStringConverter.INSTANCE).registerConverter(LocalDateTimeStringConverter.INSTANCE).autoCloseStream(true).excelType(responseExcel.suffix()).inMemory(responseExcel.inMemory());
if (StringUtils.hasText(responseExcel.password())) {
writerBuilder.password(responseExcel.password());
}
if (responseExcel.include().length != 0) {
writerBuilder.includeColumnFiledNames(Arrays.asList(responseExcel.include()));
}
if (responseExcel.exclude().length != 0) {
writerBuilder.excludeColumnFiledNames(Arrays.asList(responseExcel.exclude()));
}
if (responseExcel.writeHandler().length != 0) {
for (Class<? extends WriteHandler> clazz : responseExcel.writeHandler()) {
writerBuilder.registerWriteHandler(BeanUtils.instantiateClass(clazz));
}
}
// 开启国际化头信息处理
if (responseExcel.i18nHeader() && i18nHeaderCellWriteHandler != null) {
writerBuilder.registerWriteHandler(i18nHeaderCellWriteHandler);
}
// 自定义注入的转换器
registerCustomConverter(writerBuilder);
if (responseExcel.converter().length != 0) {
for (Class<? extends Converter> clazz : responseExcel.converter()) {
writerBuilder.registerConverter(BeanUtils.instantiateClass(clazz));
}
}
String templatePath = configProperties.getTemplatePath();
if (StringUtils.hasText(responseExcel.template())) {
ClassPathResource classPathResource = new ClassPathResource(templatePath + File.separator + responseExcel.template());
InputStream inputStream = classPathResource.getInputStream();
writerBuilder.withTemplate(inputStream);
}
writerBuilder = excelWriterBuilderEnhance.enhanceExcel(writerBuilder, response, responseExcel, templatePath);
return writerBuilder.build();
}
Aggregations