Excel action which only supports a maximum of 65536 rows #107

This commit is contained in:
Roman Pinyazhin 2018-05-25 13:10:58 +04:00 committed by GitHub
parent cf026f8a90
commit 1222c4bdee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 65 additions and 2 deletions

View File

@ -224,6 +224,13 @@ public class ExcelAction extends BaseAction implements Action.HasBeforeActionPer
.collect(Collectors.toList());
exporter.exportDataGrid(dataGrid, columns, display, null, fileName, exportMode);
}
if (exporter.isXlsMaxRowNumberExceeded()) {
listComponent.getFrame().showNotification(
messages.getMainMessage("actions.warningExport.title"),
messages.getMainMessage("actions.warningExport.message"),
Frame.NotificationType.WARNING);
}
}
@Override

View File

@ -59,6 +59,8 @@ public class ExcelExporter {
private static final int SPACE_COUNT = 10;
public static final int MAX_ROW_COUNT = 65535;
protected HSSFWorkbook wb;
protected HSSFFont boldFont;
@ -89,6 +91,8 @@ public class ExcelExporter {
protected final MetadataTools metadataTools;
protected boolean isRowNumberExceeded = false;
public enum ExportMode {
SELECTED_ROWS,
ALL_ROWS
@ -206,6 +210,10 @@ public class ExcelExporter {
.filter(selected::contains)
.collect(Collectors.toList());
for (Entity item : ordered) {
if (checkIsRowNumberExceed(r)) {
break;
}
createRow(table, columns, 0, ++r, item.getId());
}
} else {
@ -216,6 +224,10 @@ public class ExcelExporter {
r = createAggregatableRow(table, columns, ++r, 1, datasource);
}
for (Object itemId : ds.getRootItemIds()) {
if (checkIsRowNumberExceed(r)) {
break;
}
r = createHierarhicalRow(treeTable, columns, exportExpanded, r, itemId);
}
} else if (table instanceof GroupTable && datasource instanceof GroupDatasource
@ -225,6 +237,10 @@ public class ExcelExporter {
r = createAggregatableRow(table, columns, ++r, 1, datasource);
}
for (Object item : ds.rootGroups()) {
if (checkIsRowNumberExceed(r)) {
break;
}
r = createGroupRow((GroupTable) table, columns, ++r, (GroupInfo) item, 0);
}
} else {
@ -232,6 +248,10 @@ public class ExcelExporter {
r = createAggregatableRow(table, columns, ++r, 1, datasource);
}
for (Object itemId : datasource.getItemIds()) {
if (checkIsRowNumberExceed(r)) {
break;
}
createRow(table, columns, 0, ++r, itemId);
}
}
@ -339,10 +359,18 @@ public class ExcelExporter {
.filter(selected::contains)
.collect(Collectors.toList());
for (Entity item : ordered) {
if (checkIsRowNumberExceed(r)) {
break;
}
createDataGridRow(dataGrid, columns, 0, ++r, item.getId());
}
} else {
for (Object itemId : datasource.getItemIds()) {
if (checkIsRowNumberExceed(r)) {
break;
}
createDataGridRow(dataGrid, columns, 0, ++r, itemId);
}
}
@ -508,7 +536,13 @@ public class ExcelExporter {
createRow(table, columns, groupNumber, ++rowNumber, itemId);
}
}
sheet.groupRow(oldRowNumber + 1, rowNumber);
if (checkIsRowNumberExceed(rowNumber)) {
sheet.groupRow(oldRowNumber + 1, MAX_ROW_COUNT);
} else {
sheet.groupRow(oldRowNumber + 1, rowNumber);
}
return rowNumber;
}
@ -516,6 +550,11 @@ public class ExcelExporter {
if (startColumn >= columns.size()) {
return;
}
if (rowNumber > MAX_ROW_COUNT) {
return;
}
HSSFRow row = sheet.createRow(rowNumber);
Instance instance = table.getDatasource().getItem(itemId);
@ -612,7 +651,7 @@ public class ExcelExporter {
}
String childCountValue = "";
if (groupChildCount != null){
if (groupChildCount != null) {
childCountValue = " (" + groupChildCount + ")";
}
@ -734,4 +773,15 @@ public class ExcelExporter {
}
}
}
protected boolean checkIsRowNumberExceed(int r) {
return isRowNumberExceeded = r >= MAX_ROW_COUNT;
}
/**
* @return true if exported table contains more than 65536 records
*/
public boolean isXlsMaxRowNumberExceeded() {
return isRowNumberExceeded;
}
}

View File

@ -323,6 +323,9 @@ actions.exportSelectedTitle=Confirm export
actions.exportSelectedCaption=Do you want to export only selected rows?
actions.export.ALL_ROWS=All rows
actions.export.SELECTED_ROWS=Selected rows
actions.warningExport.title = Warning
actions.warningExport.message = Exported table contains more than 65536 records. Because of XLS format limitation, \
all records beyond 65536 will be ignored.
timeZone.auto=Auto
timeZone.auto.descr=Detect current time zone automatically

View File

@ -304,6 +304,9 @@ actions.exportSelectedTitle=Подтверждение
actions.exportSelectedCaption=Экспортировать в Excel только выбранные строки?
actions.export.ALL_ROWS=Все строки
actions.export.SELECTED_ROWS=Выбранные строки
actions.warningExport.title = Внимание
actions.warningExport.message = Количество записей в экспортируемой таблице свыше 65536. Поскольку XLS не \
поддерживает такое количество строк, все записи после 65536 строки проигнорированы.
dynamicAttributes.category=Категория
dynamicAttributes.entity.filter=Ограничивающий фильтр