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 {
//</editor-fold>
//<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("message", "template-invalid");
return result;
......@@ -1398,6 +1415,25 @@ public class CustomerServiceImpl implements CustomerService {
String regexp = "@\"^\\p{L}+$\"";
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>
@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