Commit 52b2752a authored by Đào Nhật Quang's avatar Đào Nhật Quang

quangdn

parent 6f785531
...@@ -998,7 +998,24 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -998,7 +998,24 @@ public class CustomerServiceImpl implements CustomerService {
//</editor-fold> //</editor-fold>
//<editor-fold desc="Kiểm tra header của template" defaultstate="collapsed"> //<editor-fold desc="Kiểm tra header của template" defaultstate="collapsed">
if (row.getPhysicalNumberOfCells() != header.size()) { if (row.getPhysicalNumberOfCells() > header.size()) {
for (int i = 0; i < row.getPhysicalNumberOfCells(); i++) {
if (isColumnNullOrBlank(sheet, i)) {
deleteNullColumn(sheet, i);
}
}
for (int i = 0; i < header.size(); i++) {
Cell cell = row.getCell(i);
if (!cell.getStringCellValue().equals(header.get(i).getTitle().split("#")[0])) {
result.put("content", Files.readAllBytes(file.toPath()));
result.put("message", "template-invalid");
return result;
}
}
result.put("content", Files.readAllBytes(file.toPath()));
result.put("message", "template-invalid");
return result;
} else if (row.getPhysicalNumberOfCells() < header.size()) {
result.put("content", Files.readAllBytes(file.toPath())); result.put("content", Files.readAllBytes(file.toPath()));
result.put("message", "template-invalid"); result.put("message", "template-invalid");
return result; return result;
...@@ -1398,6 +1415,25 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1398,6 +1415,25 @@ public class CustomerServiceImpl implements CustomerService {
String regexp = "@\"^\\p{L}+$\""; String regexp = "@\"^\\p{L}+$\"";
return str.matches(regexp); return str.matches(regexp);
} }
private boolean isColumnNullOrBlank(Sheet sheet, int columnIndex) {
for (Row row : sheet) {
if (row.getRowNum() < 3) continue;
Cell cell = row.getCell(columnIndex, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL);
if (cell != null) {
return false;
}
}
return true;
}
private void deleteNullColumn(Sheet sheet, int columnIndex) {
for (Row row : sheet) {
if (row.getRowNum() < 3) continue;
Cell cell = row.getCell(columnIndex, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL);
row.removeCell(cell);
}
}
//</editor-fold> //</editor-fold>
@Override @Override
......
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