ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilExcel Class Reference
+ Inheritance diagram for ilExcel:
+ Collaboration diagram for ilExcel:

Public Member Functions

 __construct ()
 
 loadFromFile (string $filename)
 Loads a spreadsheet from file. More...
 
 getValidFormats ()
 Get valid file formats. More...
 
 setFormat (string $a_format)
 Set file format. More...
 
 addSheet (string $a_name, bool $a_activate=true)
 Add sheet. More...
 
 setActiveSheet (int $a_index)
 
 getSheetCount ()
 Returns number of sheets. More...
 
 getSheetTitle ()
 Return the current sheet title. More...
 
 setCellByCoordinates ($a_coords, $a_value)
 Set cell value by coordinates. More...
 
 setCell (int $a_row, int $a_col, $a_value, ?string $a_datatype=null)
 Set cell value. More...
 
 setCellArray (array $a_values, string $a_top_left="A1", $a_null_value=null)
 Set cell values from array. More...
 
 getCell (int $a_row, int $a_col)
 Returns the value of a cell. More...
 
 getSheetAsArray ()
 Returns the active sheet as an array. More...
 
 getColumnCount ()
 Returns the number of columns the sheet contains. More...
 
 getColumnCoord (int $a_col)
 Get column "name" from number. More...
 
 sendToClient (string $a_file_name)
 Send workbook to client. More...
 
 writeToFile (string $a_file)
 Save workbook to file. More...
 
 writeToTmpFile ()
 
 setBold (string $a_coords)
 Set cell(s) to bold. More...
 
 setColors (string $a_coords, string $a_background, string $a_font=null)
 Set cell(s) colors. More...
 
 setBorders (string $a_coords, bool $a_top, bool $a_right=false, bool $a_bottom=false, bool $a_left=false)
 Toggle cell(s) borders. More...
 
 getCoordByColumnAndRow (int $pColumn=1, int $pRow=1)
 Get cell coordinate (e.g. More...
 
 addLink (int $a_row, int $a_column, string $a_path)
 
 columnIndexAdjustment (int $column)
 Adjustment needed because of migration PHPExcel to PhpSpreadsheet. More...
 
 mergeCells (string $coordinatesRange)
 

Data Fields

const FORMAT_XML = "Xlsx"
 
const FORMAT_BIFF = "Xls"
 

Protected Member Functions

 prepareValue ($a_value)
 Prepare value for cell. More...
 
 prepareDateValue (ilDateTime $a_value)
 
 prepareBooleanValue (bool $a_value)
 
 prepareString (string $a_value)
 
 setDateFormat (Cell $a_cell, $a_value)
 Set date format of cell. More...
 
 setGlobalAutoSize ()
 Set all existing columns on all sheets to autosize. More...
 
 prepareStorage (string $a_file_name)
 Prepare workbook for storage/delivery. More...
 

Protected Attributes

string $format
 
ilLanguage $lng
 
Spreadsheet $workbook
 
string $type
 

Private Member Functions

 cleanupNonCharachters (string $string)
 

Private Attributes

array $noncharacters
 

Detailed Description

Definition at line 34 of file class.ilExcel.php.

Constructor & Destructor Documentation

◆ __construct()

ilExcel::__construct ( )
Exceptions

Definition at line 68 of file class.ilExcel.php.

References $DIC, ILIAS\Repository\lng(), and setFormat().

69  {
70  global $DIC;
71 
72  $this->lng = $DIC->language();
73  $this->setFormat(self::FORMAT_XML);
74  $this->workbook = new Spreadsheet();
75  $this->workbook->removeSheetByIndex(0);
76  }
setFormat(string $a_format)
Set file format.
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

Member Function Documentation

◆ addLink()

ilExcel::addLink ( int  $a_row,
int  $a_column,
string  $a_path 
)
Exceptions

Definition at line 563 of file class.ilExcel.php.

References columnIndexAdjustment().

567  : void {
568  $column = $this->columnIndexAdjustment($a_column);
569  $this->workbook->getActiveSheet()->getCellByColumnAndRow($column, $a_row)->getHyperlink()->setUrl($a_path);
570  }
columnIndexAdjustment(int $column)
Adjustment needed because of migration PHPExcel to PhpSpreadsheet.
+ Here is the call graph for this function:

◆ addSheet()

ilExcel::addSheet ( string  $a_name,
bool  $a_activate = true 
)

Add sheet.

Exceptions

Definition at line 122 of file class.ilExcel.php.

References setActiveSheet(), and ilStr\shortenTextExtended().

Referenced by ilSurveyEvaluationGUI\exportResultsDetailsExcel().

125  : int {
126  #20749
127  // see Worksheet::$_invalidCharacters;
128  $invalid = array('*', ':', '/', '\\', '?', '[', ']', '\'-','\'');
129 
130  $a_name = str_replace($invalid, "", $a_name);
131 
132  // #19056 - phpExcel only allows 31 chars
133  // see https://github.com/PHPOffice/PHPExcel/issues/79
134  $a_name = ilStr::shortenTextExtended($a_name, 31);
135 
136  $sheet = new Worksheet($this->workbook, $a_name);
137  $this->workbook->addSheet($sheet);
138  $new_index = $this->workbook->getSheetCount() - 1;
139 
140  if ($a_activate) {
141  $this->setActiveSheet($new_index);
142  }
143 
144  return $new_index;
145  }
setActiveSheet(int $a_index)
static shortenTextExtended(string $a_str, int $a_len, bool $a_dots=false, bool $a_next_blank=false, bool $a_keep_extension=false)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cleanupNonCharachters()

ilExcel::cleanupNonCharachters ( string  $string)
private

Definition at line 590 of file class.ilExcel.php.

Referenced by prepareString().

590  : string
591  {
592  return mb_ereg_replace('[' . implode('', $this->noncharacters) . ']', '', $string);
593  }
+ Here is the caller graph for this function:

◆ columnIndexAdjustment()

ilExcel::columnIndexAdjustment ( int  $column)

Adjustment needed because of migration PHPExcel to PhpSpreadsheet.

PhpExcel column was 0 index based and PhpSpreadshet set this index to 1

Definition at line 576 of file class.ilExcel.php.

Referenced by addLink(), getCell(), getColumnCoord(), getCoordByColumnAndRow(), and setCell().

576  : int
577  {
578  return ++$column;
579  }
+ Here is the caller graph for this function:

◆ getCell()

ilExcel::getCell ( int  $a_row,
int  $a_col 
)

Returns the value of a cell.

Returns
mixed

Definition at line 357 of file class.ilExcel.php.

References columnIndexAdjustment().

Referenced by ilDclTextRecordFieldModel\getValueFromExcel(), ilDclBaseRecordFieldModel\getValueFromExcel(), and ilDclStandardField\getValueFromExcel().

360  {
361  $col = $this->columnIndexAdjustment($a_col);
362  return $this->workbook->getActiveSheet()->getCellByColumnAndRow($col, $a_row)->getValue();
363  }
columnIndexAdjustment(int $column)
Adjustment needed because of migration PHPExcel to PhpSpreadsheet.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getColumnCoord()

◆ getColumnCount()

ilExcel::getColumnCount ( )

Returns the number of columns the sheet contains.

Definition at line 376 of file class.ilExcel.php.

376  : int
377  {
378  return Coordinate::columnIndexFromString($this->workbook->getActiveSheet()->getHighestDataColumn());
379  }

◆ getCoordByColumnAndRow()

ilExcel::getCoordByColumnAndRow ( int  $pColumn = 1,
int  $pRow = 1 
)

Get cell coordinate (e.g.

"B2") for column and row number

Definition at line 550 of file class.ilExcel.php.

References columnIndexAdjustment().

Referenced by ilSurveyEvaluationGUI\exportResultsDetailsExcel().

553  : string {
554  $col = $this->columnIndexAdjustment($pColumn);
555  $columnLetter = Coordinate::stringFromColumnIndex($col);
556 
557  return $columnLetter . $pRow;
558  }
columnIndexAdjustment(int $column)
Adjustment needed because of migration PHPExcel to PhpSpreadsheet.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSheetAsArray()

ilExcel::getSheetAsArray ( )

Returns the active sheet as an array.

Definition at line 368 of file class.ilExcel.php.

368  : array
369  {
370  return $this->workbook->getActiveSheet()->toArray();
371  }

◆ getSheetCount()

ilExcel::getSheetCount ( )

Returns number of sheets.

Definition at line 159 of file class.ilExcel.php.

159  : int
160  {
161  return $this->workbook->getSheetCount();
162  }

◆ getSheetTitle()

ilExcel::getSheetTitle ( )

Return the current sheet title.

Definition at line 168 of file class.ilExcel.php.

168  : string
169  {
170  return $this->workbook->getActiveSheet()->getTitle();
171  }

◆ getValidFormats()

ilExcel::getValidFormats ( )

Get valid file formats.

Definition at line 97 of file class.ilExcel.php.

Referenced by setFormat().

97  : array
98  {
99  return array(self::FORMAT_XML, self::FORMAT_BIFF);
100  }
+ Here is the caller graph for this function:

◆ loadFromFile()

ilExcel::loadFromFile ( string  $filename)

Loads a spreadsheet from file.

Definition at line 85 of file class.ilExcel.php.

85  : void
86  {
87  $this->workbook = IOFactory::load($filename);
88  }
$filename
Definition: buildRTE.php:78

◆ mergeCells()

ilExcel::mergeCells ( string  $coordinatesRange)
Parameters
string$coordinatesRangeA coordinates range string like 'A1:B5'
Exceptions

Definition at line 585 of file class.ilExcel.php.

585  : void
586  {
587  $this->workbook->getActiveSheet()->mergeCells($coordinatesRange);
588  }

◆ prepareBooleanValue()

ilExcel::prepareBooleanValue ( bool  $a_value)
protected

Definition at line 223 of file class.ilExcel.php.

References $lng, and ilLanguage\txt().

Referenced by prepareValue().

223  : string
224  {
225  $lng = $this->lng;
226 
227  return $a_value ? $lng->txt('yes') : $lng->txt('no');
228  }
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
ilLanguage $lng
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ prepareDateValue()

ilExcel::prepareDateValue ( ilDateTime  $a_value)
protected
Parameters
ilDateTime$a_value
Returns
false|float

Definition at line 208 of file class.ilExcel.php.

References ilDateTime\get(), IL_CAL_DATE, and IL_CAL_DATETIME.

Referenced by prepareValue().

209  {
210  switch (true) {
211  case $a_value instanceof ilDate:
212  $a_value = Date::stringToExcel($a_value->get(IL_CAL_DATE));
213  break;
214 
215  default:
216  $a_value = Date::stringToExcel($a_value->get(IL_CAL_DATETIME));
217  break;
218  }
219 
220  return $a_value;
221  }
get(int $a_format, string $a_format_str='', string $a_tz='')
get formatted date
const IL_CAL_DATETIME
const IL_CAL_DATE
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ prepareStorage()

ilExcel::prepareStorage ( string  $a_file_name)
protected

Prepare workbook for storage/delivery.

Definition at line 414 of file class.ilExcel.php.

References setGlobalAutoSize().

Referenced by sendToClient(), and writeToFile().

414  : string
415  {
416  $this->setGlobalAutoSize();
417  $this->workbook->setActiveSheetIndex(0);
418 
419  switch ($this->format) {
420  case self::FORMAT_BIFF:
421  if (!stristr($a_file_name, ".xls")) {
422  $a_file_name .= ".xls";
423  }
424  break;
425 
426  case self::FORMAT_XML:
427  if (!stristr($a_file_name, ".xlsx")) {
428  $a_file_name .= ".xlsx";
429  }
430  break;
431  }
432 
433  return $a_file_name;
434  }
setGlobalAutoSize()
Set all existing columns on all sheets to autosize.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ prepareString()

ilExcel::prepareString ( string  $a_value)
protected

Definition at line 230 of file class.ilExcel.php.

References cleanupNonCharachters().

Referenced by prepareValue().

230  : string
231  {
232  return $this->cleanupNonCharachters(
233  strip_tags($a_value)
234  ); // #14542
235  }
cleanupNonCharachters(string $string)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ prepareValue()

ilExcel::prepareValue (   $a_value)
protected

Prepare value for cell.

Parameters
mixed$a_value
Returns
mixed
Exceptions
InvalidArgumentException

Definition at line 184 of file class.ilExcel.php.

References prepareBooleanValue(), prepareDateValue(), and prepareString().

Referenced by ilAssExcelFormatHelper\setCell(), setCell(), setCellArray(), ilAssExcelFormatHelper\setCellByCoordinates(), and setCellByCoordinates().

185  {
186  if (is_bool($a_value)) {
187  return $this->prepareBooleanValue($a_value);
188  }
189 
190  if ($a_value instanceof ilDateTime) {
191  return $this->prepareDateValue($a_value);
192  }
193 
194  if (is_string($a_value)) {
195  if (!mb_check_encoding($a_value, 'UTF-8')) {
196  throw new InvalidArgumentException('Invalid UTF-8 passed.');
197  }
198  return $this->prepareString($a_value);
199  }
200 
201  return $a_value;
202  }
prepareBooleanValue(bool $a_value)
prepareDateValue(ilDateTime $a_value)
prepareString(string $a_value)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sendToClient()

ilExcel::sendToClient ( string  $a_file_name)

Send workbook to client.

Exceptions

Definition at line 440 of file class.ilExcel.php.

References ilFileDelivery\deliverFileAttached(), ilFileUtils\ilTempnam(), and prepareStorage().

440  : void
441  {
442  $a_file_name = $this->prepareStorage($a_file_name);
443  switch ($this->format) {
444  case self::FORMAT_BIFF:
445  $a_mime_type = MimeType::APPLICATION__VND_MS_EXCEL;
446  break;
447 
448  case self::FORMAT_XML:
449  $a_mime_type = MimeType::APPLICATION__VND_OPENXMLFORMATS_OFFICEDOCUMENT_SPREADSHEETML_SHEET;
450  break;
451  default:
452  $a_mime_type = MimeType::APPLICATION__OCTET_STREAM;
453  break;
454  }
455  $tmp_name = ilFileUtils::ilTempnam();
456 
457  $writer = IOFactory::createWriter($this->workbook, $this->format);
458  $writer->save($tmp_name);
459 
460  ilFileDelivery::deliverFileAttached($tmp_name, $a_file_name, $a_mime_type, true);
461  }
prepareStorage(string $a_file_name)
Prepare workbook for storage/delivery.
static deliverFileAttached(string $path_to_file, ?string $download_file_name=null, ?string $mime_type=null, bool $delete_file=false)
static ilTempnam(?string $a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
+ Here is the call graph for this function:

◆ setActiveSheet()

ilExcel::setActiveSheet ( int  $a_index)
Exceptions

Definition at line 150 of file class.ilExcel.php.

Referenced by addSheet().

150  : void
151  {
152  $this->workbook->setActiveSheetIndex($a_index);
153  }
+ Here is the caller graph for this function:

◆ setBold()

◆ setBorders()

ilExcel::setBorders ( string  $a_coords,
bool  $a_top,
bool  $a_right = false,
bool  $a_bottom = false,
bool  $a_left = false 
)

Toggle cell(s) borders.

Definition at line 523 of file class.ilExcel.php.

529  : void {
530  $style = $this->workbook->getActiveSheet()->getStyle($a_coords);
531 
532  // :TODO: border styles?
533  if ($a_top) {
534  $style->getBorders()->getTop()->setBorderStyle(Border::BORDER_THIN);
535  }
536  if ($a_right) {
537  $style->getBorders()->getRight()->setBorderStyle(Border::BORDER_THIN);
538  }
539  if ($a_bottom) {
540  $style->getBorders()->getBottom()->setBorderStyle(Border::BORDER_THIN);
541  }
542  if ($a_left) {
543  $style->getBorders()->getLeft()->setBorderStyle(Border::BORDER_THIN);
544  }
545  }

◆ setCell()

ilExcel::setCell ( int  $a_row,
int  $a_col,
  $a_value,
?string  $a_datatype = null 
)

Set cell value.

Parameters
int$a_row
int$a_col
mixed$a_value
?string$a_datatype Explicit data type, see DataType::TYPE_*

Definition at line 288 of file class.ilExcel.php.

References columnIndexAdjustment(), prepareValue(), and setDateFormat().

Referenced by ilSurveyEvaluationGUI\exportResultsDetailsExcel(), ilDclTextSelectionRecordFieldModel\fillExcelExport(), ilDclTextRecordFieldModel\fillExcelExport(), ilDclBaseRecordFieldModel\fillExcelExport(), ilSumScoreTableGUI\fillHeaderExcel(), ilDclTextFieldModel\fillHeaderExcel(), ilSCORM2004TrackingItemsTableGUI\fillHeaderExcel(), ilSCORMTrackingItemsTableGUI\fillHeaderExcel(), ilDclStandardField\fillHeaderExcel(), ilLPProgressTableGUI\fillHeaderExcel(), ilTrObjectUsersPropsTableGUI\fillHeaderExcel(), ilTrUserObjectsPropsTableGUI\fillHeaderExcel(), ilTrMatrixTableGUI\fillHeaderExcel(), ilBookingReservationsTableGUI\fillHeaderExcel(), ilDclBaseFieldModel\fillHeaderExcel(), ilTrSummaryTableGUI\fillHeaderExcel(), ilTable2GUI\fillHeaderExcel(), ilLPTableBaseGUI\fillMetaExcel(), ilDclBaseRecordModel\fillRecordFieldExcelExport(), ilSumScoreTableGUI\fillRowExcel(), ilPollAnswerTableGUI\fillRowExcel(), ilPollUserTableGUI\fillRowExcel(), ilUserLPTableGUI\fillRowExcel(), ilSCORM2004TrackingItemsTableGUI\fillRowExcel(), ilSCORMTrackingItemsTableGUI\fillRowExcel(), ILIAS\MyStaff\ListCompetences\Skills\ilMStListCompetencesSkillsTableGUI\fillRowExcel(), ILIAS\MyStaff\ListCertificates\ilMStListCertificatesTableGUI\fillRowExcel(), ilLPObjectStatisticsTypesTableGUI\fillRowExcel(), ilMStShowUserCoursesTableGUI\fillRowExcel(), ILIAS\MyStaff\ListUsers\ilMStListUsersTableGUI\fillRowExcel(), ilLPObjectStatisticsDailyTableGUI\fillRowExcel(), ilMStListCoursesTableGUI\fillRowExcel(), ilLPObjectStatisticsTableGUI\fillRowExcel(), ilLPProgressTableGUI\fillRowExcel(), ilTrObjectUsersPropsTableGUI\fillRowExcel(), ilTrUserObjectsPropsTableGUI\fillRowExcel(), ilTrMatrixTableGUI\fillRowExcel(), ilBookingReservationsTableGUI\fillRowExcel(), ilTrSummaryTableGUI\fillRowExcel(), ilTable2GUI\fillRowExcel(), and ilSurveyEvaluationGUI\parseResultsToExcel().

293  : void {
294  $col = $this->columnIndexAdjustment($a_col);
295 
296  if (!is_null($a_datatype)) {
297  $this->workbook->getActiveSheet()->setCellValueExplicitByColumnAndRow(
298  $col,
299  $a_row,
300  $this->prepareValue($a_value),
301  $a_datatype
302  );
303  } elseif ($a_value instanceof ilDateTime) {
304  $wb = $this->workbook->getActiveSheet()->setCellValueByColumnAndRow(
305  $col,
306  $a_row,
307  $this->prepareValue($a_value)
308  );
309  $this->setDateFormat($wb->getCellByColumnAndRow($col, $a_row), $a_value);
310  } elseif (is_numeric($a_value)) {
311  $wb = $this->workbook->getActiveSheet()->setCellValueExplicitByColumnAndRow(
312  $col,
313  $a_row,
314  $this->prepareValue($a_value),
315  DataType::TYPE_NUMERIC
316  );
317  } else {
318  $wb = $this->workbook->getActiveSheet()->setCellValueExplicitByColumnAndRow(
319  $col,
320  $a_row,
321  $this->prepareValue($a_value),
322  DataType::TYPE_STRING
323  );
324  }
325  }
setDateFormat(Cell $a_cell, $a_value)
Set date format of cell.
columnIndexAdjustment(int $column)
Adjustment needed because of migration PHPExcel to PhpSpreadsheet.
prepareValue($a_value)
Prepare value for cell.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setCellArray()

ilExcel::setCellArray ( array  $a_values,
string  $a_top_left = "A1",
  $a_null_value = null 
)

Set cell values from array.

Parameters
array$a_values
string$a_top_left
mixed$a_null_valueValue in source array that stands for blank cell

Definition at line 334 of file class.ilExcel.php.

References $cols, and prepareValue().

338  : void {
339  foreach ($a_values as $row_idx => $cols) {
340  if (is_array($cols)) {
341  foreach ($cols as $col_idx => $col_value) {
342  $a_values[$row_idx][$col_idx] = $this->prepareValue($col_value);
343  }
344  } else {
345  $a_values[$row_idx] = $this->prepareValue($cols);
346  }
347  }
348 
349  $this->workbook->getActiveSheet()->fromArray($a_values, $a_null_value, $a_top_left);
350  }
$cols
Definition: xhr_table.php:11
prepareValue($a_value)
Prepare value for cell.
+ Here is the call graph for this function:

◆ setCellByCoordinates()

ilExcel::setCellByCoordinates (   $a_coords,
  $a_value 
)

Set cell value by coordinates.

Parameters
string$a_coordsCoordinate of the cell, eg: 'A1'
mixed$a_value

Definition at line 257 of file class.ilExcel.php.

References prepareValue(), and setDateFormat().

257  : void
258  {
259  if ($a_value instanceof ilDateTime) {
260  $wb = $this->workbook->getActiveSheet()->setCellValue(
261  $a_coords,
262  $this->prepareValue($a_value)
263  );
264  $cell = $wb->getCell($a_coords);
265  $this->setDateFormat($cell, $a_value);
266  } elseif (is_numeric($a_value)) {
267  $this->workbook->getActiveSheet()->setCellValueExplicit(
268  $a_coords,
269  $this->prepareValue($a_value),
270  DataType::TYPE_NUMERIC
271  );
272  } else {
273  $this->workbook->getActiveSheet()->setCellValueExplicit(
274  $a_coords,
275  $this->prepareValue($a_value),
276  DataType::TYPE_STRING
277  );
278  }
279  }
setDateFormat(Cell $a_cell, $a_value)
Set date format of cell.
prepareValue($a_value)
Prepare value for cell.
+ Here is the call graph for this function:

◆ setColors()

ilExcel::setColors ( string  $a_coords,
string  $a_background,
string  $a_font = null 
)

Set cell(s) colors.

Definition at line 499 of file class.ilExcel.php.

Referenced by ilSurveyEvaluationGUI\exportResultsDetailsExcel(), ilSurveyEvaluationGUI\parseResultsToExcel(), and ilAssExcelFormatHelper\setFormattedExcelTitle().

503  : void {
504  $opts = array(
505  'fill' => array(
506  'fillType' => Fill::FILL_SOLID,
507  'color' => array('rgb' => $a_background)
508  )
509  );
510 
511  if ($a_font) {
512  $opts['font'] = array(
513  'color' => array('rgb' => $a_font)
514  );
515  }
516 
517  $this->workbook->getActiveSheet()->getStyle($a_coords)->applyFromArray($opts);
518  }
+ Here is the caller graph for this function:

◆ setDateFormat()

ilExcel::setDateFormat ( Cell  $a_cell,
  $a_value 
)
protected

Set date format of cell.

Parameters
Cell$a_cell
mixed$a_value

Definition at line 243 of file class.ilExcel.php.

Referenced by setCell(), and setCellByCoordinates().

243  : void
244  {
245  if ($a_value instanceof ilDate) {
246  $a_cell->getStyle()->getNumberFormat()->setFormatCode("dd.mm.yyyy");
247  } elseif ($a_value instanceof ilDateTime) {
248  $a_cell->getStyle()->getNumberFormat()->setFormatCode("dd.mm.yyyy hh:mm:ss");
249  }
250  }
+ Here is the caller graph for this function:

◆ setFormat()

ilExcel::setFormat ( string  $a_format)

Set file format.

Definition at line 105 of file class.ilExcel.php.

References getValidFormats().

Referenced by __construct().

105  : void
106  {
107  if (in_array($a_format, $this->getValidFormats())) {
108  $this->format = $a_format;
109  }
110  }
getValidFormats()
Get valid file formats.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setGlobalAutoSize()

ilExcel::setGlobalAutoSize ( )
protected

Set all existing columns on all sheets to autosize.

Definition at line 393 of file class.ilExcel.php.

Referenced by prepareStorage().

393  : void
394  {
395  // this may change the active sheet
396  foreach ($this->workbook->getWorksheetIterator() as $worksheet) {
397  $this->workbook->setActiveSheetIndex($this->workbook->getIndex($worksheet));
398  $sheet = $this->workbook->getActiveSheet();
399  $cellIterator = $sheet->getRowIterator()->current()->getCellIterator();
400  $cellIterator->setIterateOnlyExistingCells(true);
401  foreach ($cellIterator as $cell) {
402  $sheet->getColumnDimension($cell->getColumn())->setAutoSize(true);
403  }
404  }
405  }
+ Here is the caller graph for this function:

◆ writeToFile()

ilExcel::writeToFile ( string  $a_file)

Save workbook to file.

Exceptions

Definition at line 468 of file class.ilExcel.php.

References prepareStorage().

468  : void
469  {
470  $a_file = $this->prepareStorage($a_file);
471 
472  $writer = IOFactory::createWriter($this->workbook, $this->format);
473  $writer->save($a_file);
474  }
prepareStorage(string $a_file_name)
Prepare workbook for storage/delivery.
+ Here is the call graph for this function:

◆ writeToTmpFile()

ilExcel::writeToTmpFile ( )
Exceptions

Definition at line 479 of file class.ilExcel.php.

References $filename, and ilFileUtils\ilTempnam().

479  : string
480  {
481  $writer = IOFactory::createWriter($this->workbook, $this->format);
483  $writer->save($filename);
484 
485  return $filename;
486  }
$filename
Definition: buildRTE.php:78
static ilTempnam(?string $a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
+ Here is the call graph for this function:

Field Documentation

◆ $format

string ilExcel::$format
protected

Definition at line 38 of file class.ilExcel.php.

◆ $lng

ilLanguage ilExcel::$lng
protected

Definition at line 61 of file class.ilExcel.php.

Referenced by prepareBooleanValue().

◆ $noncharacters

array ilExcel::$noncharacters
private
Initial value:
= [
'\x{FFFE}-\x{FFFF}',
'\x{1FFFE}-\x{1FFFF}',
'\x{2FFFE}-\x{2FFFF}',
'\x{3FFFE}-\x{3FFFF}',
'\x{4FFFE}-\x{4FFFF}',
'\x{5FFFE}-\x{5FFFF}',
'\x{6FFFE}-\x{6FFFF}',
'\x{7FFFE}-\x{7FFFF}',
'\x{8FFFE}-\x{8FFFF}',
'\x{9FFFE}-\x{9FFFF}',
'\x{AFFFE}-\x{AFFFF}',
'\x{BFFFE}-\x{BFFFF}',
'\x{CFFFE}-\x{CFFFF}',
'\x{DFFFE}-\x{DFFFF}',
'\x{EFFFE}-\x{EFFFF}',
'\x{FFFFE}-\x{FFFFF}',
'\x{10FFFE}-\x{10FFFF}',
'\x{FDD0}-\x{FDEF}'
]

Definition at line 40 of file class.ilExcel.php.

◆ $type

string ilExcel::$type
protected

Definition at line 63 of file class.ilExcel.php.

◆ $workbook

Spreadsheet ilExcel::$workbook
protected

Definition at line 62 of file class.ilExcel.php.

◆ FORMAT_BIFF

const ilExcel::FORMAT_BIFF = "Xls"

Definition at line 37 of file class.ilExcel.php.

◆ FORMAT_XML

const ilExcel::FORMAT_XML = "Xlsx"

Definition at line 36 of file class.ilExcel.php.


The documentation for this class was generated from the following file: