From 52bcc433275178f9a396557ef5dbe6ac0f061bbd Mon Sep 17 00:00:00 2001 From: FuFei <69680491+fufeii@users.noreply.github.com> Date: Fri, 6 May 2022 15:22:26 +0800 Subject: [PATCH] =?UTF-8?q?fix=20#2227=20=E8=AF=BB=E5=8F=96csv=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=97=B6autoTrim=E9=85=8D=E7=BD=AE=E5=A4=B1=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/alibaba/excel/analysis/csv/CsvExcelReadExecutor.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 2c35b105d..e4e6b01bf 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 @@ private void dealRecord(CSVRecord record, int rowIndex) { 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 @@ private void dealRecord(CSVRecord record, int rowIndex) { // 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); }