Browse Source

Merge pull request #2464 from fufeii/developing

fix #2227 读取csv文件时autoTrim配置失效
pull/2472/head
Jiaju Zhuang 3 years ago committed by GitHub
parent
commit
4446d636c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      easyexcel-core/src/main/java/com/alibaba/excel/analysis/csv/CsvExcelReadExecutor.java

3
easyexcel-core/src/main/java/com/alibaba/excel/analysis/csv/CsvExcelReadExecutor.java

@ -96,6 +96,7 @@ public class CsvExcelReadExecutor implements ExcelReadExecutor {
Map<Integer, Cell> cellMap = new LinkedHashMap<>(); Map<Integer, Cell> cellMap = new LinkedHashMap<>();
Iterator<String> cellIterator = record.iterator(); Iterator<String> cellIterator = record.iterator();
int columnIndex = 0; int columnIndex = 0;
Boolean autoTrim = csvReadContext.currentReadHolder().globalConfiguration().getAutoTrim();
while (cellIterator.hasNext()) { while (cellIterator.hasNext()) {
String cellString = cellIterator.next(); String cellString = cellIterator.next();
ReadCellData<String> readCellData = new ReadCellData<>(); ReadCellData<String> readCellData = new ReadCellData<>();
@ -105,7 +106,7 @@ public class CsvExcelReadExecutor implements ExcelReadExecutor {
// csv is an empty string of whether <code>,,</code> is read or <code>,"",</code> // csv is an empty string of whether <code>,,</code> is read or <code>,"",</code>
if (StringUtils.isNotBlank(cellString)) { if (StringUtils.isNotBlank(cellString)) {
readCellData.setType(CellDataTypeEnum.STRING); readCellData.setType(CellDataTypeEnum.STRING);
readCellData.setStringValue(cellString); readCellData.setStringValue(autoTrim ? cellString.trim() : cellString);
} else { } else {
readCellData.setType(CellDataTypeEnum.EMPTY); readCellData.setType(CellDataTypeEnum.EMPTY);
} }

Loading…
Cancel
Save