forked from github/dataease
Merge pull request #5331 from dataease/pr@dev@fixdataset
fix: 精简模式导入csv处理特殊字符
This commit is contained in:
commit
6c45cd0567
@ -2454,7 +2454,19 @@ public class DataSetTableService {
|
||||
if (num > 1000) {
|
||||
break;
|
||||
}
|
||||
data.add(Arrays.asList(line.split(",")));
|
||||
String str;
|
||||
line += ",";
|
||||
Pattern pCells = Pattern.compile("(\"[^\"]*(\"{2})*[^\"]*\")*[^,]*,");
|
||||
Matcher mCells = pCells.matcher(line);
|
||||
List<String> cells = new ArrayList();//每行记录一个list
|
||||
//读取每个单元格
|
||||
while (mCells.find()) {
|
||||
str = mCells.group();
|
||||
str = str.replaceAll("(?sm)\"?([^\"]*(\"{2})*[^\"]*)\"?.*,", "$1");
|
||||
str = str.replaceAll("(?sm)(\"(\"))", "$2");
|
||||
cells.add(str);
|
||||
}
|
||||
data.add(cells);
|
||||
num++;
|
||||
}
|
||||
ExcelSheetData excelSheetData = new ExcelSheetData();
|
||||
|
@ -72,6 +72,8 @@ import javax.annotation.Resource;
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@ -758,13 +760,20 @@ public class ExtractDataService {
|
||||
List<List<String>> csvData = new ArrayList<>();
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if(line.endsWith(",")){
|
||||
List<String> list = new ArrayList<>(Arrays.asList(line.split(",")));
|
||||
list.add("");
|
||||
csvData.add(list);
|
||||
}else {
|
||||
csvData.add(Arrays.asList(line.split(",")));
|
||||
|
||||
String str;
|
||||
line += ",";
|
||||
Pattern pCells = Pattern.compile("(\"[^\"]*(\"{2})*[^\"]*\")*[^,]*,");
|
||||
Matcher mCells = pCells.matcher(line);
|
||||
List<String> cells = new ArrayList();//每行记录一个list
|
||||
//读取每个单元格
|
||||
while (mCells.find()) {
|
||||
str = mCells.group();
|
||||
str = str.replaceAll("(?sm)\"?([^\"]*(\"{2})*[^\"]*)\"?.*,", "$1");
|
||||
str = str.replaceAll("(?sm)(\"(\"))", "$2");
|
||||
cells.add(str);
|
||||
}
|
||||
csvData.add(cells);
|
||||
}
|
||||
ExcelSheetData csvSheetData = new ExcelSheetData();
|
||||
String[] fieldArray = fields.stream().map(TableField::getFieldName).toArray(String[]::new);
|
||||
|
Loading…
Reference in New Issue
Block a user