Commit 4e80990e authored by Carsten  Rose's avatar Carsten Rose
Browse files

F4922 / Excel Import: First successful run with dynamic data 'p:?id=excelexport'

parent b6cfd023
Pipeline #671 passed with stage
in 1 minute and 39 seconds
......@@ -260,6 +260,7 @@ const ERROR_DOWNLOAD_FILE_NOT_READABLE = 1705;
// Excel
const ERROR_EXCEL_POSITION_ARGUMENT_EMPTY = 1800;
const ERROR_EXCEL_INVALID_COORDINATES = 1801;
// KeyValueParser
const ERROR_KVP_VALUE_HAS_NO_KEY = 1900;
......@@ -1297,6 +1298,7 @@ const COLUMN_PDF = 'pdf';
const COLUMN_FILE = 'file';
const COLUMN_ZIP = 'zip';
const COLUMN_MONITOR = 'monitor';
const COLUMN_EXCEL = 'excel';
const COLUMN_NL2BR = 'nl2br';
const COLUMN_HTMLENTITIES = 'htmlentities';
......
......@@ -86,14 +86,25 @@ class OnString {
}
/**
* Split an Excel position string line 'A1' oder 'ACD4567' to [ 'A', '1'], resp. [ 'ACD', '4567' ]
* Split an Excel position string line to column and row.
* E.g.: $pos = 'A1' to [ 'A', '1'], resp. 'ACD4567' to [ 'ACD', '4567' ]
*
* @param $pos
* @return mixed
* @param &$column - return the alpha part of $pos
* @param &$row - return the digit part of $pos
* @return bool - true if a alpha string and a numeric string is found, else false.
*/
public static function splitExcelPos($pos){
public static function splitExcelPos($pos, &$column, &$row){
preg_match_all('/(\w)|(\d)/', $pos, $matches);
return $matches;
if(count($matches[0])!=2) {
return false;
}
$column = $matches[0][0];
$row = $matches[0][1];
return true;
}
}
......@@ -63,16 +63,16 @@ class Excel {
}
// Use Template or NEW
if (isset($files[0])) {
// Open template
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($files[0]);
} else {
if (empty($files[0])) {
// Create new
$spreadsheet = new Spreadsheet();
} else {
// Open template
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($files[0]);
}
// Iterate over all sources.
foreach($data as $page) {
foreach ($data as $page) {
$spreadsheet = $this->fillSpreadsheet($spreadsheet, $page);
}
......@@ -93,10 +93,9 @@ class Excel {
$worksheet = $spreadsheet->getActiveSheet();
$pos = 'A1';
$tmpArr = OnString::splitExcelPos($pos);
$posColumn = $tmpArr[COLUMN];
$posRow = $tmpArr[ROW];
if(!OnString::splitExcelPos($pos, $posColumn, $posRow)){
throw new downloadException("Invalid cell coordinates: " . $pos, ERROR_EXCEL_INVALID_COORDINATES);
}
$arr = explode(PHP_EOL, $data);
foreach ($arr as $line) {
......@@ -116,13 +115,14 @@ class Excel {
throw new downloadException("Not implemented: " . $token[0], ERROR_NOT_IMPLEMENTED);
case EXCEL_POSITION:
if (empty($token[1])) {
throw new downloadException("Position argument is empty", ERROR_EXCEL_POSITION_ARGUMENT_EMPTY);
}
$pos = $token[1];
$tmpArr = OnString::splitExcelPos($pos);
$posColumn = $tmpArr[COLUMN];
$posRow = $tmpArr[ROW];
if(!OnString::splitExcelPos($token[1], $posColumn, $posRow)){
throw new downloadException("Invalid cell coordinates: " . $pos, ERROR_EXCEL_INVALID_COORDINATES);
}
break;
case EXCEL_ROW:
......
......@@ -750,6 +750,7 @@ class Report {
case COLUMN_PDF:
case COLUMN_FILE:
case COLUMN_ZIP:
case COLUMN_EXCEL:
$linkValue = $this->doDownload($columnName, $columnValue);
$content .= $this->link->renderLink($linkValue);
break;
......@@ -1178,7 +1179,7 @@ class Report {
return '';
}
$columNameToMode = [COLUMN_PDF => DOWNLOAD_MODE_PDF, COLUMN_FILE => DOWNLOAD_MODE_FILE, COLUMN_ZIP => DOWNLOAD_MODE_ZIP];
$columNameToMode = [COLUMN_PDF => DOWNLOAD_MODE_PDF, COLUMN_FILE => DOWNLOAD_MODE_FILE, COLUMN_ZIP => DOWNLOAD_MODE_ZIP, COLUMN_EXCEL => DOWNLOAD_MODE_EXCEL];
$param = explode('|', $columnValue);
......@@ -1186,9 +1187,10 @@ class Report {
if (!isset($columNameToMode[$columnName])) {
throw new CodeException("Unexpected columnname: $columnName", ERROR_UNEXPECTED_TYPE);
}
$defaultMode = TOKEN_DOWNLOAD_MODE . ':' . $columNameToMode[$columnName];
# get all default values, depending on the columnname
# get all default values, depending on the column name
$defaultSip = TOKEN_SIP;
$defaultDownload = TOKEN_DOWNLOAD;
......
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