-
Notifications
You must be signed in to change notification settings - Fork 7.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
3.0.5版本读取CSV文件,head为中文时无法读取,autoTrim无效 #2227
Labels
bug
Something isn't working
pending verification
This problem needs to be confirmed
planning
It may be developed later
Comments
无法读取问题已发现原因:文件是GBK编码时出现,若是UTF8则正常读取。 |
autoTrim问题还是存在 |
复现代码 @Test
public void test() {
// 注意商户号列的空格
String csvData = "序号,商户号,商户名\n" +
"1, 商户号1 ,商户名1\n" +
"2, 商户号2 ,商户名2\n" +
"3, 商户号3 ,商户名3";
EasyExcel.read(new ByteArrayInputStream(csvData.getBytes()))
.registerReadListener(new AnalysisEventListener<RowContent>() {
@Override
public void invoke(RowContent o, AnalysisContext analysisContext) {
System.out.println(o + ",原始长度=" + o.getKey2().length() + ",trim长度后=" + o.getKey2().trim().length());
}
@Override
public void doAfterAllAnalysed(AnalysisContext context) {
}
})
.autoTrim(true)
.headRowNumber(1)
.head(RowContent.class)
.excelType(ExcelTypeEnum.CSV)
.sheet()
.doRead();
} model类 @Data
public class RowContent {
@ExcelProperty(value = "序号")
private String key1;
@ExcelProperty(value = "商户号")
private String key2;
@ExcelProperty(value = "商户名")
private String key3;
} 运行结果
|
zhuangjiaju
added a commit
that referenced
this issue
May 11, 2022
这个要怎么解决呢,我要导入的文件是对方提供的,自己不可改编码格式。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
bug
Something isn't working
pending verification
This problem needs to be confirmed
planning
It may be developed later
触发Bug的代码
读取一个CSV文件,第一行的标题头为中文,使用@ExcelProperty加标题名的方式读取不出数据(字段都为null),使用@ExcelProperty加index的方式可以读取,autoTrim参数无效
The text was updated successfully, but these errors were encountered: