ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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 ()
 
 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 559 of file class.ilExcel.php.

References getCoordByColumnAndRow().

563  : void {
564  $coordinate = $this->getCoordByColumnAndRow($a_column, $a_row);
565  $this->workbook->getActiveSheet()->getCell($coordinate)->getHyperlink()->setUrl($a_path);
566  }
getCoordByColumnAndRow(int $pColumn=1, int $pRow=1)
Get cell coordinate (e.g.
+ 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 = ['*', ':', '/', '\\', '?', '[', ']', '\'-', '\''];
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 586 of file class.ilExcel.php.

Referenced by prepareString().

586  : string
587  {
588  return mb_ereg_replace('[' . implode('', $this->noncharacters) . ']', '', $string);
589  }
+ 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 572 of file class.ilExcel.php.

Referenced by getColumnCoord(), and getCoordByColumnAndRow().

572  : int
573  {
574  return ++$column;
575  }
+ 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 353 of file class.ilExcel.php.

References getCoordByColumnAndRow().

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

356  {
357  $coordinate = $this->getCoordByColumnAndRow($a_col, $a_row);
358  return $this->workbook->getActiveSheet()->getCell($coordinate)->getValue();
359  }
getCoordByColumnAndRow(int $pColumn=1, int $pRow=1)
Get cell coordinate (e.g.
+ 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 372 of file class.ilExcel.php.

372  : int
373  {
374  return Coordinate::columnIndexFromString($this->workbook->getActiveSheet()->getHighestDataColumn());
375  }

◆ getCoordByColumnAndRow()

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

Get cell coordinate (e.g.

"B2") for column and row number

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

References columnIndexAdjustment().

Referenced by addLink(), ilSurveyEvaluationGUI\exportResultsDetailsExcel(), getCell(), ilAssExcelFormatHelper\setCell(), and setCell().

549  : string {
550  $col = $this->columnIndexAdjustment($pColumn);
551  $columnLetter = Coordinate::stringFromColumnIndex($col);
552 
553  return $columnLetter . $pRow;
554  }
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 364 of file class.ilExcel.php.

364  : array
365  {
366  return $this->workbook->getActiveSheet()->toArray();
367  }

◆ 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 ( )
Returns
list<string>

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

Referenced by setFormat().

97  : array
98  {
99  return [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 581 of file class.ilExcel.php.

581  : void
582  {
583  $this->workbook->getActiveSheet()->mergeCells($coordinatesRange);
584  }

◆ 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 410 of file class.ilExcel.php.

References setGlobalAutoSize().

Referenced by sendToClient(), and writeToFile().

410  : string
411  {
412  $this->setGlobalAutoSize();
413  $this->workbook->setActiveSheetIndex(0);
414 
415  switch ($this->format) {
416  case self::FORMAT_BIFF:
417  if (stripos($a_file_name, '.xls') === false) {
418  $a_file_name .= '.xls';
419  }
420  break;
421 
422  case self::FORMAT_XML:
423  if (stripos($a_file_name, '.xlsx') === false) {
424  $a_file_name .= '.xlsx';
425  }
426  break;
427  }
428 
429  return $a_file_name;
430  }
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 436 of file class.ilExcel.php.

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

436  : void
437  {
438  $a_file_name = $this->prepareStorage($a_file_name);
439  switch ($this->format) {
440  case self::FORMAT_BIFF:
441  $a_mime_type = MimeType::APPLICATION__VND_MS_EXCEL;
442  break;
443 
444  case self::FORMAT_XML:
445  $a_mime_type = MimeType::APPLICATION__VND_OPENXMLFORMATS_OFFICEDOCUMENT_SPREADSHEETML_SHEET;
446  break;
447  default:
448  $a_mime_type = MimeType::APPLICATION__OCTET_STREAM;
449  break;
450  }
451  $tmp_name = ilFileUtils::ilTempnam();
452 
453  $writer = IOFactory::createWriter($this->workbook, $this->format);
454  $writer->save($tmp_name);
455 
456  ilFileDelivery::deliverFileAttached($tmp_name, $a_file_name, $a_mime_type, true);
457  }
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 519 of file class.ilExcel.php.

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

◆ 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 getCoordByColumnAndRow(), prepareValue(), and setDateFormat().

Referenced by ilSurveyEvaluationGUI\exportResultsDetailsExcel(), ilDclTextSelectionRecordFieldModel\fillExcelExport(), ilDclTextRecordFieldModel\fillExcelExport(), ilDclBaseRecordFieldModel\fillExcelExport(), ilSumScoreTableGUI\fillHeaderExcel(), ilDclTextFieldModel\fillHeaderExcel(), ilSCORMTrackingItemsTableGUI\fillHeaderExcel(), ilSCORM2004TrackingItemsTableGUI\fillHeaderExcel(), ilDclStandardField\fillHeaderExcel(), ilLPProgressTableGUI\fillHeaderExcel(), ilTrObjectUsersPropsTableGUI\fillHeaderExcel(), ilTrUserObjectsPropsTableGUI\fillHeaderExcel(), ilTrMatrixTableGUI\fillHeaderExcel(), ilDclBaseFieldModel\fillHeaderExcel(), ilBookingReservationsTableGUI\fillHeaderExcel(), ilTrSummaryTableGUI\fillHeaderExcel(), ilTable2GUI\fillHeaderExcel(), ilLPTableBaseGUI\fillMetaExcel(), ilDclBaseRecordModel\fillRecordFieldExcelExport(), ilSumScoreTableGUI\fillRowExcel(), ilPollAnswerTableGUI\fillRowExcel(), ilPollUserTableGUI\fillRowExcel(), ilUserLPTableGUI\fillRowExcel(), ilSCORMTrackingItemsTableGUI\fillRowExcel(), ilSCORM2004TrackingItemsTableGUI\fillRowExcel(), ILIAS\MyStaff\ListCompetences\Skills\ilMStListCompetencesSkillsTableGUI\fillRowExcel(), ILIAS\MyStaff\ListCertificates\ilMStListCertificatesTableGUI\fillRowExcel(), ilMStShowUserCoursesTableGUI\fillRowExcel(), ilLPObjectStatisticsTypesTableGUI\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  $coordinate = $this->getCoordByColumnAndRow($a_col, $a_row);
295 
296  if ($a_datatype !== null) {
297  $this->workbook->getActiveSheet()->setCellValueExplicit(
298  $coordinate,
299  $this->prepareValue($a_value),
300  $a_datatype
301  );
302  } elseif ($a_value instanceof ilDateTime) {
303  $wb = $this->workbook->getActiveSheet()->setCellValue(
304  $coordinate,
305  $this->prepareValue($a_value)
306  );
307  $this->setDateFormat($wb->getCell($coordinate), $a_value);
308  } elseif (is_numeric($a_value)) {
309  $this->workbook->getActiveSheet()->setCellValueExplicit(
310  $coordinate,
311  $this->prepareValue($a_value),
312  DataType::TYPE_NUMERIC
313  );
314  } else {
315  $this->workbook->getActiveSheet()->setCellValueExplicit(
316  $coordinate,
317  $this->prepareValue($a_value),
318  DataType::TYPE_STRING
319  );
320  }
321  }
setDateFormat(Cell $a_cell, $a_value)
Set date format of cell.
getCoordByColumnAndRow(int $pColumn=1, int $pRow=1)
Get cell coordinate (e.g.
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<int,mixed|array<int,mixed>>$a_values
string$a_top_left
mixed$a_null_valueValue in source array that stands for blank cell

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

References prepareValue().

334  : void {
335  foreach ($a_values as $row_idx => $cols) {
336  if (is_array($cols)) {
337  foreach ($cols as $col_idx => $col_value) {
338  $a_values[$row_idx][$col_idx] = $this->prepareValue($col_value);
339  }
340  } else {
341  $a_values[$row_idx] = $this->prepareValue($cols);
342  }
343  }
344 
345  $this->workbook->getActiveSheet()->fromArray($a_values, $a_null_value, $a_top_left);
346  }
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 495 of file class.ilExcel.php.

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

499  : void {
500  $opts = [
501  'fill' => [
502  'fillType' => Fill::FILL_SOLID,
503  'color' => ['rgb' => $a_background]
504  ]
505  ];
506 
507  if ($a_font) {
508  $opts['font'] = [
509  'color' => ['rgb' => $a_font]
510  ];
511  }
512 
513  $this->workbook->getActiveSheet()->getStyle($a_coords)->applyFromArray($opts);
514  }
+ 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()
+ 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 389 of file class.ilExcel.php.

Referenced by prepareStorage().

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

◆ writeToFile()

ilExcel::writeToFile ( string  $a_file)

Save workbook to file.

Exceptions

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

References prepareStorage().

464  : void
465  {
466  $a_file = $this->prepareStorage($a_file);
467 
468  $writer = IOFactory::createWriter($this->workbook, $this->format);
469  $writer->save($a_file);
470  }
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 475 of file class.ilExcel.php.

References $filename, and ilFileUtils\ilTempnam().

475  : string
476  {
477  $writer = IOFactory::createWriter($this->workbook, $this->format);
479  $writer->save($filename);
480 
481  return $filename;
482  }
$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: