diff --git a/easyexcel-core/src/main/java/com/alibaba/excel/analysis/csv/CsvExcelReadExecutor.java b/easyexcel-core/src/main/java/com/alibaba/excel/analysis/csv/CsvExcelReadExecutor.java index 2c35b105..e4e6b01b 100644 --- a/easyexcel-core/src/main/java/com/alibaba/excel/analysis/csv/CsvExcelReadExecutor.java +++ b/easyexcel-core/src/main/java/com/alibaba/excel/analysis/csv/CsvExcelReadExecutor.java @@ -96,6 +96,7 @@ public class CsvExcelReadExecutor implements ExcelReadExecutor { Map cellMap = new LinkedHashMap<>(); Iterator cellIterator = record.iterator(); int columnIndex = 0; + Boolean autoTrim = csvReadContext.currentReadHolder().globalConfiguration().getAutoTrim(); while (cellIterator.hasNext()) { String cellString = cellIterator.next(); ReadCellData readCellData = new ReadCellData<>(); @@ -105,7 +106,7 @@ public class CsvExcelReadExecutor implements ExcelReadExecutor { // csv is an empty string of whether ,, is read or ,"", if (StringUtils.isNotBlank(cellString)) { readCellData.setType(CellDataTypeEnum.STRING); - readCellData.setStringValue(cellString); + readCellData.setStringValue(autoTrim ? cellString.trim() : cellString); } else { readCellData.setType(CellDataTypeEnum.EMPTY); }