Skip to content

Commit 700bdc3

Browse files
committed
Fix xlsx export was faulty when exporting results with exactly 0 or 1 result
1 parent 147beb0 commit 700bdc3

3 files changed

Lines changed: 10 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 2.0.1
2+
* Fix xlsx export was faulty when exporting results with exactly 0 or 1 result
3+
14
## 2.0.0
25
* Update to Mapbender 4.1
36
* Removed dataStores entry in `parameters.yaml`

Element/HttpHandler.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,22 @@ protected function exportAction(Element $element, Request $request)
9999
{
100100
$query = $this->requireQuery($element, $request->request->get('id'));
101101
$rows = $this->executeQuery($element, $query);
102+
102103
$exportFormat = match ($this->getSafeConfiguration($element)['export_format']) {
103104
'csv' => ExportResponse::TYPE_CSV,
104105
'xls' => ExportResponse::TYPE_XLS,
105106
default => ExportResponse::TYPE_XLSX,
106107
};
107-
if ($exportFormat === ExportResponse::TYPE_XLSX && count($rows) > 1) {
108+
if ($exportFormat === ExportResponse::TYPE_XLSX && count($rows) > 0) {
108109
// XLSX export does not automatically add title rows, so add them manually
109110
$keys = array_keys($rows[0]);
110111
$titleRow = array_combine($keys, $keys);
111112
$rows = array_merge([$titleRow], $rows);
112113
}
114+
if (count($rows) === 0) {
115+
// XLSX export does not allow empty files, so add a dummy row
116+
$rows[] = [];
117+
}
113118
return new ExportResponse($rows, 'export-list', $exportFormat);
114119
}
115120

Resources/public/queryBuilder.element.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
},
8585

8686
/**
87-
* Execute SQL and export als excel or data.
87+
* Execute SQL and export as excel or data.
8888
* This fake the form POST method to get download export file.
8989
*
9090
* @returns jQuery form object

0 commit comments

Comments
 (0)