出库单导入;
This commit is contained in:
+55
@@ -0,0 +1,55 @@
|
||||
package com.mhd.wms.domain.stockOutOrder.repository.listener;
|
||||
|
||||
import com.alibaba.excel.converters.Converter;
|
||||
import com.alibaba.excel.enums.CellDataTypeEnum;
|
||||
import com.alibaba.excel.metadata.GlobalConfiguration;
|
||||
import com.alibaba.excel.metadata.data.ReadCellData;
|
||||
import com.alibaba.excel.metadata.property.ExcelContentProperty;
|
||||
|
||||
/**
|
||||
* 自定义转换器,不进行任何类型转换,直接返回原始值
|
||||
* 覆盖EasyExcel默认的StringNumberConverter,避免数字格式化错误
|
||||
*/
|
||||
public class NoConvertConverter implements Converter<String> {
|
||||
|
||||
@Override
|
||||
public Class<?> supportJavaTypeKey() {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CellDataTypeEnum supportExcelTypeKey() {
|
||||
// 关键:返回NUMBER类型,覆盖StringNumberConverter
|
||||
return CellDataTypeEnum.NUMBER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty,
|
||||
GlobalConfiguration globalConfiguration) {
|
||||
// 不进行任何格式化,直接返回原始值的字符串表示
|
||||
if (cellData == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
// 根据单元格类型获取原始值
|
||||
try {
|
||||
CellDataTypeEnum type = cellData.getType();
|
||||
if (type == CellDataTypeEnum.STRING) {
|
||||
return cellData.getStringValue() != null ? cellData.getStringValue() : "";
|
||||
} else if (type == CellDataTypeEnum.NUMBER) {
|
||||
// 直接转换数字为字符串,不进行格式化
|
||||
return cellData.getNumberValue() != null ? cellData.getNumberValue().toString() : "";
|
||||
} else if (type == CellDataTypeEnum.BOOLEAN) {
|
||||
return cellData.getBooleanValue() != null ? cellData.getBooleanValue().toString() : "";
|
||||
} else if (type == CellDataTypeEnum.EMPTY) {
|
||||
return "";
|
||||
} else {
|
||||
// 其他类型尝试获取字符串值
|
||||
return cellData.getStringValue() != null ? cellData.getStringValue() : "";
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 如果获取失败,返回空字符串
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user