Browse Source

Merge branch 'temp_merge' into developing

pull/2472/head
Jiaju Zhuang 3 years ago
parent
commit
13a92f2800
  1. 4
      easyexcel-core/src/main/java/com/alibaba/excel/analysis/csv/CsvExcelReadExecutor.java
  2. 5
      easyexcel-core/src/main/java/com/alibaba/excel/read/builder/ExcelReaderBuilder.java
  3. 2
      easyexcel-core/src/main/java/com/alibaba/excel/read/metadata/ReadWorkbook.java
  4. 5
      easyexcel-core/src/main/java/com/alibaba/excel/read/metadata/holder/csv/CsvReadWorkbookHolder.java

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

@ -84,12 +84,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) {

5
easyexcel-core/src/main/java/com/alibaba/excel/read/builder/ExcelReaderBuilder.java

@ -38,6 +38,11 @@ public class ExcelReaderBuilder extends AbstractExcelReaderParameterBuilder<Exce
return this;
}
public ExcelReaderBuilder encoding(String encoding){
readWorkbook.setEncoding(encoding);
return this;
}
/**
* Read InputStream
* <p>

2
easyexcel-core/src/main/java/com/alibaba/excel/read/metadata/ReadWorkbook.java

@ -98,4 +98,6 @@ public class ReadWorkbook extends ReadBasicParameter {
* @see CellExtraTypeEnum
*/
private Set<CellExtraTypeEnum> extraReadSet;
private String encoding;
}

5
easyexcel-core/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;
import org.apache.commons.csv.CSVParser;
@ -24,9 +26,12 @@ public class CsvReadWorkbookHolder extends ReadWorkbookHolder {
private CSVParser csvParser;
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();
}
}

Loading…
Cancel
Save