ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilAssExcelFormatHelper.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2016 ILIAS open source, Extended GPL, see docs/LICENSE */
3 require_once 'Modules/Test/classes/inc.AssessmentConstants.php';
4 require_once 'Services/Excel/classes/class.ilExcel.php';
5 
11 {
12  const escapeString = true;
13 
14  protected $stringEscaping = self::escapeString;
15 
19  public function __construct()
20  {
21  parent::__construct();
22  }
23 
28  public function setFormattedExcelTitle($coordinates, $value)
29  {
30  $this->setCellByCoordinates($coordinates, $value);
31  $this->setColors($coordinates, EXCEL_BACKGROUND_COLOR);
32  $this->setBold($coordinates);
33  }
34 
38  public function setCellByCoordinates($a_coords, $a_value)
39  {
40  if (is_string($a_value) && !is_numeric($a_value)) {
41  $this->workbook->getActiveSheet()->setCellValueExplicit(
42  $a_coords,
43  $this->prepareValue($a_value),
44  \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING,
45  true
46  );
47  } else {
48  parent::setCellByCoordinates($a_coords, $a_value);
49  }
50  }
51 
55  public function setCell($a_row, $a_col, $a_value, $datatype=null)
56  {
57  if (is_string($a_value) && !is_numeric($a_value)) {
58  $this->workbook->getActiveSheet()->setCellValueExplicitByColumnAndRow(
59  $a_col + 1,
60  $a_row,
61  $this->prepareValue($a_value),
62  \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING,
63  true
64  );
65  } else {
66  parent::setCell($a_row, $a_col, $a_value);
67  }
68  }
69 
74  protected function prepareString($a_value)
75  {
76  if ($this->stringEscaping == false) {
77  return $a_value;
78  } else {
79  return strip_tags($a_value);
80  }
81  }
82 
86  public function getStringEscaping()
87  {
88  return $this->stringEscaping;
89  }
90 
95  {
96  $this->stringEscaping = $stringEscaping;
97  }
98 }
const EXCEL_BACKGROUND_COLOR
setCell($a_row, $a_col, $a_value, $datatype=null)
setBold($a_coords)
Set cell(s) to bold.
__construct()
ilAssExcelFormatHelper constructor.
setCellByCoordinates($a_coords, $a_value)
setColors($a_coords, $a_background, $a_font=null)
Set cell(s) colors.
setFormattedExcelTitle($coordinates, $value)
Class ilAssExcelFormatHelper.
prepareValue($a_value)
Prepare value for cell.