use of com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy in project RuoYi-Vue-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异常");
}
}
use of com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy 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异常");
}
}
use of com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy in project citrus by Yiuman.
the class WebUtils method exportExcel.
/**
* 导出excel文档
*
* @param response 当前响应
* @param clazz 类型
* @param data 数据
* @param name 导出文件名
* @param <T> 导出定义类的类型
* @throws IOException IO异常
*/
public static <T> void exportExcel(HttpServletResponse response, Class<T> clazz, List<T> data, String name) throws IOException {
addExportFilenameHeaders(response, name);
response.setContentType(APPLICATION_VND_MS_EXCEL);
EasyExcel.write(response.getOutputStream(), clazz).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).sheet("sheet1").doWrite(data);
}
use of com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy in project citrus by Yiuman.
the class WebUtils method exportExcel.
/**
* 动态列导出Excel
*
* @param response 响应
* @param headers 表头
* @param data 数据
* @param name 文件 名
* @throws IOException IO异常
*/
public static void exportExcel(HttpServletResponse response, List<List<String>> headers, List<List<Object>> data, String name) throws IOException {
addExportFilenameHeaders(response, name + ".xls");
response.setContentType(APPLICATION_VND_MS_EXCEL);
EasyExcel.write(response.getOutputStream()).registerConverter(new LocalDateTimeDateConverter()).head(headers).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).sheet("sheet1").doWrite(data);
}
use of com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy 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;
}
}
Aggregations