我使用opencsv
(2.3版)CSVWriter
在Java中创建csv文件。
但是,在打开我创建的csv文件时,将以所有数据都存储在单个列中的方式打开它。
我用来创建CSV文件的CSVWriter:
File file = new File(fileName);
CSVWriter writer = new CSVWriter(new FileWriter(fileName, true), ';');
String[] col= new String[3];
for(Customer c : CustomerList) {
col[0] = c.getCustomerName();
col[1] = c.getCustomerId();
col[2] = c.getCustomerBirthDate();
writer.writeNext(col);
}
writer.close();
CSV文件-单列中的所有数据:
“ Micky”;“ 1”;“ 19901220”
“宽限期”;“ 2”;“ 19901231”
预期数据在每个单元中对齐:
问题:
仅写时是否可以使用
CSVWriter
将数据放置在其单独的列中?如果opencsv不支持它,我应该使用其他csv吗?
最佳答案
fn有了问题的答案。您需要使用逗号作为分隔符(这是默认设置),外部读取器才能自动将其提取。逗号是openCSV的默认值。
或者,您可以进入excel并告诉它使用分号作为分隔符。使用“文本到列”选项。