我正在使用 org.apache.commons.csv.CSVPrinter (Java 8) 来生成一个从 DB RecordSet 开始的 CSV 文本文件。我的数据库表中有一个描述字段,用户可以在其中插入他想要的任何内容,例如新行!
当我在 Excel 或 Google 电子表格上导入 CSV 时,每行在描述中都有一个换行符,显然会破坏 CSV 结构。
我应该手动替换/删除这些字符还是有办法配置 CSVPrinter 以自动删除它?
谢谢大家。F
编辑:这里是一个代码片段:
CSVFormat csvFormat = CSVFormat.DEFAULT.withRecordSeparator("\n").withQuoteMode(QuoteMode.ALL).withQuote('"');
CSVPrinter csvPrinter = new CSVPrinter(csvContent, csvFormat);
// 准备从数据库收集的字符串列表。我明确使用 String 数组,因为我需要在将其写入 CSV 之前对 DB 内容执行一些文本编辑
List fasciaOrariaRecord = new ArrayList();
时间bandRecord.add(...);
时间bandRecord.add(...);
// ...
csvPrinter.printRecord (csvHeader);
// 更多行...
csvPrinter.close();
HUH函数
相关分类