【发布时间】:2017-10-20 17:45:14
【问题描述】:
我正在使用 Java 和 opencsv(2.3) 创建 csv 文件。
它是正确创建的。但是当我打开文件时,我看到所有数据都显示在单列中。
为了将值对齐到单独的列中
1.我在excel的数据选项卡中选择“文本到列”
2.我选择分隔符为“;”
- 我看到所有值都正确拆分为单独的列,但逗号后的值消失了
CSVWriter 我用来创建 CSV 文件:
File file = new File(fileName);
CSVWriter writer = new CSVWriter(new FileWriter(fileName, true), ';');
String[] col= new String[4];
for(Customer c : CustomerList) {
col[0] = c.getCustomerName();
col[1] = c.getCustomerId();
col[2] = c.getCustomerBirthDate();
col[3] = c.getRegFee(); /** 145,65**/
col[4] = c.getRegPlace();
writer.writeNext(col);
}
writer.close();
CSV 文件 - 实际内容:
"Micky";"1";"19901220";"455,56";"Place1"
"Grace";"2";"19901231";"465,87";"Place2"
CSV 文件 - 使用 excel 打开时:
"Micky";"1";"19901220";"455" // , 56 and Place1 are vanished
"Grace";"2";"19901231";"465" // , 87 and Place2 are vanished
【问题讨论】: