Skip to content

Commit

Permalink
prevent export and invoice from breaking on equal sign (#2054)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpapst authored Oct 23, 2020
1 parent 4533c99 commit 2ad8f8a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Export/Base/AbstractSpreadsheetRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use App\Repository\Query\TimesheetQuery;
use App\Twig\DateExtensions;
use DateTime;
use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\Border;
Expand Down Expand Up @@ -312,7 +313,7 @@ protected function getColumns(array $exportItems, TimesheetQuery $query, array $
$columns['description']['render'] = function (Worksheet $sheet, int $row, int $column, ExportItemInterface $entity) use (&$isColumnFormatted, $maxWidth, $wrapText) {
$cell = $sheet->getCellByColumnAndRow($column, $row);

$cell->setValue($entity->getDescription());
$cell->setValueExplicit($entity->getDescription(), DataType::TYPE_STRING);

// Apply wrap text if configured
if ($wrapText) {
Expand Down
7 changes: 6 additions & 1 deletion src/Invoice/Renderer/AbstractSpreadsheetRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use App\Entity\InvoiceDocument;
use App\Invoice\InvoiceModel;
use PhpOffice\PhpSpreadsheet\Cell\Cell;
use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
Expand Down Expand Up @@ -93,7 +94,11 @@ public function render(InvoiceDocument $document, InvoiceModel $model): Response
$value = str_replace($searchKey, $content, $value);
}

$cell->setValue($value);
if (\is_string($value)) {
$cell->setValueExplicit($value, DataType::TYPE_STRING);
} else {
$cell->setValue($value);
}
}

if ($sheetValues !== false && $entryRow < $invoiceItemCount - 1) {
Expand Down
1 change: 1 addition & 0 deletions tests/Export/Renderer/AbstractRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ protected function render(ExportRendererInterface $renderer)
->setDuration(400)
->setRate(1947.99)
->setUser($user2)
->setDescription('== jhg ljhg ') // make sure that spreadsheets don't render it as formula
->setActivity($activity)
->setProject($project)
->setBegin(new \DateTime())
Expand Down
1 change: 1 addition & 0 deletions tests/Invoice/Renderer/RendererTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ protected function getInvoiceModel(): InvoiceModel
->setRate(111.11)
->setUser($user1)
->setActivity($activity2)
->setDescription('== jhg ljhg ') // make sure that spreadsheets don't render it as formula
->setProject($project2)
->setBegin(new \DateTime())
->setEnd(new \DateTime())
Expand Down

0 comments on commit 2ad8f8a

Please sign in to comment.