diff --git a/src/main/java/com/alibaba/excel/analysis/csv/CsvExcelReadExecutor.java b/src/main/java/com/alibaba/excel/analysis/csv/CsvExcelReadExecutor.java index d411ef0d..cb0af033 100644 --- a/src/main/java/com/alibaba/excel/analysis/csv/CsvExcelReadExecutor.java +++ b/src/main/java/com/alibaba/excel/analysis/csv/CsvExcelReadExecutor.java @@ -82,12 +82,12 @@ public class CsvExcelReadExecutor implements ExcelReadExecutor { CSVFormat csvFormat = csvReadWorkbookHolder.getCsvFormat(); if (csvReadWorkbookHolder.getMandatoryUseInputStream()) { - return csvFormat.parse(new InputStreamReader(csvReadWorkbookHolder.getInputStream())); + return csvFormat.parse(new InputStreamReader(csvReadWorkbookHolder.getInputStream(),csvReadWorkbookHolder.getEncoding())); } if (csvReadWorkbookHolder.getFile() != null) { return csvFormat.parse(new FileReader(csvReadWorkbookHolder.getFile())); } - return csvFormat.parse(new InputStreamReader(csvReadWorkbookHolder.getInputStream())); + return csvFormat.parse(new InputStreamReader(csvReadWorkbookHolder.getInputStream(),csvReadWorkbookHolder.getEncoding())); } private void dealRecord(CSVRecord record, int rowIndex) { diff --git a/src/main/java/com/alibaba/excel/read/builder/ExcelReaderBuilder.java b/src/main/java/com/alibaba/excel/read/builder/ExcelReaderBuilder.java index b630eea2..0cb11009 100644 --- a/src/main/java/com/alibaba/excel/read/builder/ExcelReaderBuilder.java +++ b/src/main/java/com/alibaba/excel/read/builder/ExcelReaderBuilder.java @@ -38,6 +38,11 @@ public class ExcelReaderBuilder extends AbstractExcelReaderParameterBuilder diff --git a/src/main/java/com/alibaba/excel/read/metadata/ReadWorkbook.java b/src/main/java/com/alibaba/excel/read/metadata/ReadWorkbook.java index 54ab034c..eb9c9b86 100644 --- a/src/main/java/com/alibaba/excel/read/metadata/ReadWorkbook.java +++ b/src/main/java/com/alibaba/excel/read/metadata/ReadWorkbook.java @@ -98,4 +98,6 @@ public class ReadWorkbook extends ReadBasicParameter { * @see CellExtraTypeEnum */ private Set extraReadSet; + + private String encoding; } diff --git a/src/main/java/com/alibaba/excel/read/metadata/holder/csv/CsvReadWorkbookHolder.java b/src/main/java/com/alibaba/excel/read/metadata/holder/csv/CsvReadWorkbookHolder.java index 0a322d58..b83b3bc8 100644 --- a/src/main/java/com/alibaba/excel/read/metadata/holder/csv/CsvReadWorkbookHolder.java +++ b/src/main/java/com/alibaba/excel/read/metadata/holder/csv/CsvReadWorkbookHolder.java @@ -4,9 +4,11 @@ import com.alibaba.excel.read.metadata.ReadWorkbook; import com.alibaba.excel.read.metadata.holder.ReadWorkbookHolder; import com.alibaba.excel.support.ExcelTypeEnum; +import com.alibaba.excel.util.StringUtils; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; +import org.apache.commons.compress.utils.CharsetNames; import org.apache.commons.csv.CSVFormat; /** @@ -21,9 +23,12 @@ public class CsvReadWorkbookHolder extends ReadWorkbookHolder { private CSVFormat csvFormat; + private String encoding; + public CsvReadWorkbookHolder(ReadWorkbook readWorkbook) { super(readWorkbook); setExcelType(ExcelTypeEnum.CSV); this.csvFormat = CSVFormat.DEFAULT; + this.encoding = StringUtils.isEmpty(readWorkbook.getEncoding())? CharsetNames.UTF_8:readWorkbook.getEncoding(); } }