forked from github/dataease
fix: 精简模式导入csv处理特殊字符
This commit is contained in:
parent
69621cb6aa
commit
a0f9bc50a2
@ -2452,7 +2452,19 @@ public class DataSetTableService {
|
|||||||
if (num > 1000) {
|
if (num > 1000) {
|
||||||
break;
|
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++;
|
num++;
|
||||||
}
|
}
|
||||||
ExcelSheetData excelSheetData = new ExcelSheetData();
|
ExcelSheetData excelSheetData = new ExcelSheetData();
|
||||||
|
@ -72,6 +72,8 @@ import javax.annotation.Resource;
|
|||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@ -758,13 +760,20 @@ public class ExtractDataService {
|
|||||||
List<List<String>> csvData = new ArrayList<>();
|
List<List<String>> csvData = new ArrayList<>();
|
||||||
String line;
|
String line;
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
if(line.endsWith(",")){
|
|
||||||
List<String> list = new ArrayList<>(Arrays.asList(line.split(",")));
|
String str;
|
||||||
list.add("");
|
line += ",";
|
||||||
csvData.add(list);
|
Pattern pCells = Pattern.compile("(\"[^\"]*(\"{2})*[^\"]*\")*[^,]*,");
|
||||||
}else {
|
Matcher mCells = pCells.matcher(line);
|
||||||
csvData.add(Arrays.asList(line.split(",")));
|
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();
|
ExcelSheetData csvSheetData = new ExcelSheetData();
|
||||||
String[] fieldArray = fields.stream().map(TableField::getFieldName).toArray(String[]::new);
|
String[] fieldArray = fields.stream().map(TableField::getFieldName).toArray(String[]::new);
|
||||||
|
Loading…
Reference in New Issue
Block a user