Commit 42007ed0 authored by pengxin's avatar pengxin

导出CSV特殊符号处理。

parent e99cdcfa
......@@ -392,6 +392,12 @@ public class DatasetOutputServiceImpl extends BaseService<DatasetOutput, Long> i
JsonNode rootNode = objectMapper.readTree(datasetData.getData());
String instruction = rootNode.get(DatasetConstant.INSTRUCTION).textValue();
String output = rootNode.get(DatasetConstant.OUTPUT).textValue();
// 对包含换行符的字符串进行处理
instruction = instruction.replaceAll("\n", " ");
output = output.replaceAll("\n", " ");
// 将包含逗号的字符串用双引号包围,并转义其中的双引号
pw.println(escapeCsvValue(instruction) + "," + escapeCsvValue(output));
}
pw.flush();
......@@ -413,11 +419,6 @@ public class DatasetOutputServiceImpl extends BaseService<DatasetOutput, Long> i
return fileName;
}
/**
* 特殊符号处理
* @param value 处理值
* @return 返回处理
*/
private String escapeCsvValue(String value) {
// 使用Apache Commons CSV库来转义CSV值中的特殊字符
String escaped = StringEscapeUtils.escapeCsv(value);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment