Commit be0556ec authored by Carsten  Rose's avatar Carsten Rose
Browse files

Download/Excel: Add special column name '_XLSb' and Excel column type 'b'...

Download/Excel: Add special column name '_XLSb' and Excel column type 'b' (Base64 encode). Newline in text is correct handled with this option.
parent 84a63fae
Pipeline #753 passed with stage
in 1 minute and 57 seconds
...@@ -6388,23 +6388,26 @@ Setup ...@@ -6388,23 +6388,26 @@ Setup
* Lines starting with '#' will be skipped (comments). Inline comment signs are NOT recognized as comment sign. * Lines starting with '#' will be skipped (comments). Inline comment signs are NOT recognized as comment sign.
* Separate <keyword> and <value> by '='. * Separate <keyword> and <value> by '='.
+-------------+----------------+---------------------------------------------------------------------------------------------------+ +-------------+----------------------+---------------------------------------------------------------------------------------------------+
| Keyword | Example | Description | | Keyword | Example | Description |
+=============+================+===================================================================================================+ +=============+======================+===================================================================================================+
| 'worksheet' | worksheet=main | Select a worksheet in case the excel file has multiple of them. | | 'worksheet' | worksheet=main | Select a worksheet in case the excel file has multiple of them. |
+-------------+----------------+---------------------------------------------------------------------------------------------------+ +-------------+----------------------+---------------------------------------------------------------------------------------------------+
| 'mode' | mode=insert | Values: insert,overwrite. | | 'mode' | mode=insert | Values: insert,overwrite. |
+-------------+----------------+---------------------------------------------------------------------------------------------------+ +-------------+----------------------+---------------------------------------------------------------------------------------------------+
| 'position' | position=A1 | Default is 'A1'. Use the excel notation. | | 'position' | position=A1 | Default is 'A1'. Use the excel notation. |
+-------------+----------------+---------------------------------------------------------------------------------------------------+ +-------------+----------------------+---------------------------------------------------------------------------------------------------+
| 'newline' | newline | Start a new row. The column will be the one of the last 'position' statement. | | 'newline' | newline | Start a new row. The column will be the one of the last 'position' statement. |
+-------------+----------------+---------------------------------------------------------------------------------------------------+ +-------------+----------------------+---------------------------------------------------------------------------------------------------+
| 'str', 's' | s=hello world | Set the given string on the given position. The current position will be shiftet one to the right.| | 'str', 's' | s=hello world | Set the given string on the given position. The current position will be shift one to the right. |
+-------------+----------------+---------------------------------------------------------------------------------------------------+ | | | If the string contains newlines, option'b' (base64) should be used. |
| 'n' | n=123 | Set number on the given position. The current position will be shiftet one to the right. | +-------------+----------------------+---------------------------------------------------------------------------------------------------+
+-------------+----------------+---------------------------------------------------------------------------------------------------+ | 'b' | b=aGVsbG8gd29ybGQK | Same as 's', but the given string has to Base64 encoded and will be decoded before export. |
| 'f' | f==SUM(A5:C6) | Set a formular on the given position. The current position will be shiftet one to the right. | +-------------+----------------------+---------------------------------------------------------------------------------------------------+
+-------------+----------------+---------------------------------------------------------------------------------------------------+ | 'n' | n=123 | Set number on the given position. The current position will be shift one to the right. |
+-------------+----------------------+---------------------------------------------------------------------------------------------------+
| 'f' | f==SUM(A5:C6) | Set a formular on the given position. The current position will be shift one to the right. |
+-------------+----------------------+---------------------------------------------------------------------------------------------------+
Create a output like this: :: Create a output like this: ::
...@@ -6420,7 +6423,8 @@ This fills D11, E11, F11, D12 ...@@ -6420,7 +6423,8 @@ This fills D11, E11, F11, D12
In Report Syntax: :: In Report Syntax: ::
10.sql = SELECT 'position=D11' AS _XLS, # With ... AS _XLS
10.sql = SELECT 'position=D10' AS _XLS,
's=Hello' AS _XLS, 's=Hello' AS _XLS,
's=World' AS _XLS, 's=World' AS _XLS,
's=First Line' AS _XLS, 's=First Line' AS _XLS,
...@@ -6428,6 +6432,19 @@ In Report Syntax: :: ...@@ -6428,6 +6432,19 @@ In Report Syntax: ::
's=Second line' AS _XLS, 's=Second line' AS _XLS,
'n=123' AS _XLS, 'n=123' AS _XLS,
# With ... AS _XLSs
20.sql = SELECT 'position=D20' AS _XLS,
'Hello' AS _XLSs,
'World' AS _XLSs,
'First Line' AS _XLSs,
'newline' AS _XLS,
'Second line' AS _XLSs,
'n=123' AS _XLS,
# With ... AS _XLSb (Base64 encoding)
30.sql = SELECT 'position=D30' AS _XLS,
'<some content with special characters like newline/carriage return>' AS _XLSb
.. _drag_and_drop: .. _drag_and_drop:
Drag and drop Drag and drop
......
...@@ -1307,9 +1307,10 @@ const COLUMN_STRIPTAGS = 'striptags'; ...@@ -1307,9 +1307,10 @@ const COLUMN_STRIPTAGS = 'striptags';
const COLUMN_MIME_TYPE = 'mimeType'; // Will also be used to identify equal named columns in upload record. const COLUMN_MIME_TYPE = 'mimeType'; // Will also be used to identify equal named columns in upload record.
const COLUMN_FILE_SIZE = 'fileSize'; // Will also be used to identify equal named columns in upload record. const COLUMN_FILE_SIZE = 'fileSize'; // Will also be used to identify equal named columns in upload record.
const COLUMN_IMPORT = "import"; const COLUMN_IMPORT = "import";
const COLUMN_EXCEL_STRING = 'XLSs';
const COLUMN_EXCEL_NUMERIC = 'XLSn';
const COLUMN_EXCEL_PLAIN = 'XLS'; const COLUMN_EXCEL_PLAIN = 'XLS';
const COLUMN_EXCEL_NUMERIC = 'XLSn';
const COLUMN_EXCEL_STRING = 'XLSs';
const COLUMN_EXCEL_BASE64 = 'XLSb';
const COLUMN_WRAP_TOKEN = '+'; const COLUMN_WRAP_TOKEN = '+';
...@@ -1355,7 +1356,7 @@ const EXCEL_STRING2 = 'str'; ...@@ -1355,7 +1356,7 @@ const EXCEL_STRING2 = 'str';
const EXCEL_STRING = 's'; const EXCEL_STRING = 's';
const EXCEL_FORMULA = 'f'; const EXCEL_FORMULA = 'f';
const EXCEL_NUMERIC = 'n'; const EXCEL_NUMERIC = 'n';
const EXCEL_BOOL = 'b'; const EXCEL_BASE64 = 'b';
const EXCEL_NULL = 'null'; const EXCEL_NULL = 'null';
const EXCEL_INLINE = 'inlineStr'; const EXCEL_INLINE = 'inlineStr';
const EXCEL_ERROR = 'e'; const EXCEL_ERROR = 'e';
......
...@@ -73,7 +73,7 @@ class OnArray { ...@@ -73,7 +73,7 @@ class OnArray {
} }
/** /**
* Trim all elemements in an array. * Trim all elements in an array.
* The array has to be a 1-dimensional array. * The array has to be a 1-dimensional array.
* *
* @param array $arr * @param array $arr
......
...@@ -452,10 +452,12 @@ class Download { ...@@ -452,10 +452,12 @@ class Download {
* *
* @return string * @return string
* @throws CodeException * @throws CodeException
* @throws DbException
* @throws DownloadException * @throws DownloadException
* @throws UserFormException * @throws UserFormException
* @throws UserReportException * @throws UserReportException
* @throws \PhpOffice\PhpSpreadsheet\Exception
* @throws \PhpOffice\PhpSpreadsheet\Reader\Exception
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
*/ */
public function process($vars, $outputMode = OUTPUT_MODE_DIRECT) { public function process($vars, $outputMode = OUTPUT_MODE_DIRECT) {
......
...@@ -142,10 +142,15 @@ class Excel { ...@@ -142,10 +142,15 @@ class Excel {
case EXCEL_STRING2: case EXCEL_STRING2:
case EXCEL_FORMULA: case EXCEL_FORMULA:
case EXCEL_NUMERIC: case EXCEL_NUMERIC:
case EXCEL_BOOL: case EXCEL_BASE64:
case EXCEL_NULL: case EXCEL_NULL:
case EXCEL_INLINE: case EXCEL_INLINE:
case EXCEL_ERROR: case EXCEL_ERROR:
if($key==EXCEL_BASE64){
$value=base64_decode($value);
$key=EXCEL_STRING;
}
$spreadsheet->getActiveSheet() $spreadsheet->getActiveSheet()
->setCellValueExplicit( ->setCellValueExplicit(
$posColumn . $posRow, $posColumn . $posRow,
......
...@@ -796,6 +796,9 @@ class Report { ...@@ -796,6 +796,9 @@ class Report {
case COLUMN_EXCEL_STRING: case COLUMN_EXCEL_STRING:
$content .= EXCEL_STRING . '=' . $columnValue . PHP_EOL; $content .= EXCEL_STRING . '=' . $columnValue . PHP_EOL;
break; break;
case COLUMN_EXCEL_BASE64:
$content .= EXCEL_BASE64 . '=' . base64_encode($columnValue) . PHP_EOL;
break;
case COLUMN_EXCEL_NUMERIC: case COLUMN_EXCEL_NUMERIC:
$content .= EXCEL_NUMERIC . '=' . $columnValue . PHP_EOL; $content .= EXCEL_NUMERIC . '=' . $columnValue . PHP_EOL;
break; break;
......
Supports Markdown
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