mirror of
https://github.com/continew-org/continew-starter.git
synced 2025-09-11 06:57:14 +08:00
style: 优化全局代码格式
This commit is contained in:
@@ -55,7 +55,8 @@ public class ExcelBigNumberConverter implements Converter<Long> {
|
||||
* 转换为 Java 数据(读取 Excel)
|
||||
*/
|
||||
@Override
|
||||
public Long convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty,
|
||||
public Long convertToJavaData(ReadCellData<?> cellData,
|
||||
ExcelContentProperty contentProperty,
|
||||
GlobalConfiguration globalConfiguration) {
|
||||
return Convert.toLong(cellData.getData());
|
||||
}
|
||||
@@ -64,7 +65,8 @@ public class ExcelBigNumberConverter implements Converter<Long> {
|
||||
* 转换为 Excel 数据(写入 Excel)
|
||||
*/
|
||||
@Override
|
||||
public WriteCellData<Object> convertToExcelData(Long value, ExcelContentProperty contentProperty,
|
||||
public WriteCellData<Object> convertToExcelData(Long value,
|
||||
ExcelContentProperty contentProperty,
|
||||
GlobalConfiguration globalConfiguration) {
|
||||
if (null != value) {
|
||||
String str = Long.toString(value);
|
||||
|
@@ -62,19 +62,25 @@ public class ExcelUtils {
|
||||
* @param clazz 导出数据类型
|
||||
* @param response 响应对象
|
||||
*/
|
||||
public static <T> void export(List<T> list, String fileName, String sheetName, Class<T> clazz,
|
||||
public static <T> void export(List<T> list,
|
||||
String fileName,
|
||||
String sheetName,
|
||||
Class<T> clazz,
|
||||
HttpServletResponse response) {
|
||||
try {
|
||||
fileName =
|
||||
String.format("%s_%s.xlsx", fileName, DateUtil.format(new Date(), DatePattern.PURE_DATETIME_PATTERN));
|
||||
fileName = String.format("%s_%s.xlsx", fileName, DateUtil
|
||||
.format(new Date(), DatePattern.PURE_DATETIME_PATTERN));
|
||||
fileName = URLUtil.encode(fileName);
|
||||
response.setHeader("Content-disposition", "attachment;filename=" + fileName);
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
|
||||
EasyExcel.write(response.getOutputStream(), clazz).autoCloseStream(false)
|
||||
// 自动适配宽度
|
||||
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
|
||||
// 自动转换大数值
|
||||
.registerConverter(new ExcelBigNumberConverter()).sheet(sheetName).doWrite(list);
|
||||
EasyExcel.write(response.getOutputStream(), clazz)
|
||||
.autoCloseStream(false)
|
||||
// 自动适配宽度
|
||||
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
|
||||
// 自动转换大数值
|
||||
.registerConverter(new ExcelBigNumberConverter())
|
||||
.sheet(sheetName)
|
||||
.doWrite(list);
|
||||
} catch (Exception e) {
|
||||
log.error("Export excel occurred an error: {}. fileName: {}.", e.getMessage(), fileName, e);
|
||||
throw new BaseException("导出 Excel 出现错误");
|
||||
|
Reference in New Issue
Block a user