ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilExcel Class Reference
+ 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 $col, $value, ?string $datatype=null, bool $disable_strip_tags_for_strings=false)
 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 ($value)
 Prepare value for cell. More...
 
 prepareDateValue (ilDateTime $a_value)
 
 prepareBooleanValue (bool $a_value)
 
 prepareString (string $value, bool $disable_strip_tags=false)
 
 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

PhpOffice\PhpSpreadsheet\Exception

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

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: shib_login.php:26

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

+ Here is the call graph for this function:

Member Function Documentation

◆ addLink()

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

PhpOffice\PhpSpreadsheet\Exception

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

573 : void {
574 $coordinate = $this->getCoordByColumnAndRow($a_column, $a_row);
575 $this->workbook->getActiveSheet()->getCell($coordinate)->getHyperlink()->setUrl($a_path);
576 }
getCoordByColumnAndRow(int $pColumn=1, int $pRow=1)
Get cell coordinate (e.g.

◆ addSheet()

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

Add sheet.

Exceptions

PhpOffice\PhpSpreadsheet\Exception

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

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)

◆ cleanupNonCharachters()

ilExcel::cleanupNonCharachters ( string  $string)
private

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

596 : string
597 {
598 return mb_ereg_replace('[' . implode('', $this->noncharacters) . ']', '', $string);
599 }

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

582 : int
583 {
584 return ++$column;
585 }

◆ getCell()

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

Returns the value of a cell.

Returns
mixed

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

366 {
367 $coordinate = $this->getCoordByColumnAndRow($a_col, $a_row);
368 return $this->workbook->getActiveSheet()->getCell($coordinate)->getValue();
369 }

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

+ Here is the caller graph for this function:

◆ getColumnCoord()

ilExcel::getColumnCoord ( int  $a_col)

Get column "name" from number.

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

390 : string
391 {
392 $col = $this->columnIndexAdjustment($a_col);
393 return Coordinate::stringFromColumnIndex($col);
394 }
columnIndexAdjustment(int $column)
Adjustment needed because of migration PHPExcel to PhpSpreadsheet.

Referenced by ilSumScoreTableGUI\fillHeaderExcel(), ilTable2GUI\fillHeaderExcel(), ilTrMatrixTableGUI\fillHeaderExcel(), ilTrObjectUsersPropsTableGUI\fillHeaderExcel(), ilTrSummaryTableGUI\fillHeaderExcel(), and ilTrUserObjectsPropsTableGUI\fillHeaderExcel().

+ Here is the caller graph for this function:

◆ getColumnCount()

ilExcel::getColumnCount ( )

Returns the number of columns the sheet contains.

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

382 : int
383 {
384 return Coordinate::columnIndexFromString($this->workbook->getActiveSheet()->getHighestDataColumn());
385 }

◆ getCoordByColumnAndRow()

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

Get cell coordinate (e.g.

"B2") for column and row number

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

559 : string {
560 $col = $this->columnIndexAdjustment($pColumn);
561 $columnLetter = Coordinate::stringFromColumnIndex($col);
562
563 return $columnLetter . $pRow;
564 }

◆ getSheetAsArray()

ilExcel::getSheetAsArray ( )

Returns the active sheet as an array.

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

374 : array
375 {
376 return $this->workbook->getActiveSheet()->toArray();
377 }

◆ 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.

97 : array
98 {
100 }
const FORMAT_BIFF
const FORMAT_XML

References FORMAT_BIFF, and FORMAT_XML.

Referenced by setFormat().

+ 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

References $filename.

◆ mergeCells()

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

PhpOffice\PhpSpreadsheet\Exception

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

591 : void
592 {
593 $this->workbook->getActiveSheet()->mergeCells($coordinatesRange);
594 }

◆ prepareBooleanValue()

ilExcel::prepareBooleanValue ( bool  $a_value)
protected

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

220 : string
221 {
223
224 return $a_value ? $lng->txt('yes') : $lng->txt('no');
225 }
ilLanguage $lng
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...

References $lng.

◆ prepareDateValue()

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

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

206 {
207 switch (true) {
208 case $a_value instanceof ilDate:
209 $a_value = Date::stringToExcel($a_value->get(IL_CAL_DATE));
210 break;
211
212 default:
213 $a_value = Date::stringToExcel($a_value->get(IL_CAL_DATETIME));
214 break;
215 }
216
217 return $a_value;
218 }
const IL_CAL_DATE
const IL_CAL_DATETIME
get(int $a_format, string $a_format_str='', string $a_tz='')
get formatted date
Class for single dates.

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

+ Here is the call graph for this function:

◆ prepareStorage()

ilExcel::prepareStorage ( string  $a_file_name)
protected

Prepare workbook for storage/delivery.

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

420 : string
421 {
422 $this->setGlobalAutoSize();
423 $this->workbook->setActiveSheetIndex(0);
424
425 switch ($this->format) {
427 if (stripos($a_file_name, '.xls') === false) {
428 $a_file_name .= '.xls';
429 }
430 break;
431
432 case self::FORMAT_XML:
433 if (stripos($a_file_name, '.xlsx') === false) {
434 $a_file_name .= '.xlsx';
435 }
436 break;
437 }
438
439 return $a_file_name;
440 }
setGlobalAutoSize()
Set all existing columns on all sheets to autosize.

◆ prepareString()

ilExcel::prepareString ( string  $value,
bool  $disable_strip_tags = false 
)
protected

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

230 : string {
231 if (!mb_check_encoding($value, 'UTF-8')) {
232 throw new InvalidArgumentException('Invalid UTF-8 passed.');
233 }
234
235 return $this->cleanupNonCharachters(
236 $disable_strip_tags ? $value : strip_tags($value)
237 ); // #14542
238 }
cleanupNonCharachters(string $string)

◆ prepareValue()

ilExcel::prepareValue (   $value)
protected

Prepare value for cell.

Parameters
mixed$value
Returns
mixed
Exceptions
InvalidArgumentException

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

185 {
186 if (is_bool($value)) {
187 return $this->prepareBooleanValue($value);
188 }
189
190 if ($value instanceof ilDateTime) {
191 return $this->prepareDateValue($value);
192 }
193
194 if (is_string($value)) {
195 return $this->prepareString($value);
196 }
197
198 return $value;
199 }
@classDescription Date and time handling
prepareDateValue(ilDateTime $a_value)
prepareString(string $value, bool $disable_strip_tags=false)
prepareBooleanValue(bool $a_value)

◆ sendToClient()

ilExcel::sendToClient ( string  $a_file_name)

Send workbook to client.

Exceptions

PhpOffice\PhpSpreadsheet\Writer\Exception

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

446 : void
447 {
448 $a_file_name = $this->prepareStorage($a_file_name);
449 switch ($this->format) {
451 $a_mime_type = MimeType::APPLICATION__VND_MS_EXCEL;
452 break;
453
454 case self::FORMAT_XML:
455 $a_mime_type = MimeType::APPLICATION__VND_OPENXMLFORMATS_OFFICEDOCUMENT_SPREADSHEETML_SHEET;
456 break;
457 default:
458 $a_mime_type = MimeType::APPLICATION__OCTET_STREAM;
459 break;
460 }
461 $tmp_name = ilFileUtils::ilTempnam();
462
463 $writer = IOFactory::createWriter($this->workbook, $this->format);
464 $writer->save($tmp_name);
465
466 ilFileDelivery::deliverFileAttached($tmp_name, $a_file_name, $a_mime_type, true);
467 }
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.

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

+ Here is the call graph for this function:

◆ setActiveSheet()

ilExcel::setActiveSheet ( int  $a_index)
Exceptions

PhpOffice\PhpSpreadsheet\Exception

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

150 : void
151 {
152 $this->workbook->setActiveSheetIndex($a_index);
153 }

◆ setBold()

ilExcel::setBold ( string  $a_coords)

Set cell(s) to bold.

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

497 : void
498 {
499 $this->workbook->getActiveSheet()->getStyle($a_coords)->getFont()->setBold(true);
500 }

Referenced by ilSumScoreTableGUI\fillHeaderExcel(), ilTable2GUI\fillHeaderExcel(), ilLPProgressTableGUI\fillHeaderExcel(), ilTrMatrixTableGUI\fillHeaderExcel(), ilTrObjectUsersPropsTableGUI\fillHeaderExcel(), ilTrSummaryTableGUI\fillHeaderExcel(), and ilTrUserObjectsPropsTableGUI\fillHeaderExcel().

+ Here is the caller graph for this function:

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

535 : void {
536 $style = $this->workbook->getActiveSheet()->getStyle($a_coords);
537
538 // :TODO: border styles?
539 if ($a_top) {
540 $style->getBorders()->getTop()->setBorderStyle(Border::BORDER_THIN);
541 }
542 if ($a_right) {
543 $style->getBorders()->getRight()->setBorderStyle(Border::BORDER_THIN);
544 }
545 if ($a_bottom) {
546 $style->getBorders()->getBottom()->setBorderStyle(Border::BORDER_THIN);
547 }
548 if ($a_left) {
549 $style->getBorders()->getLeft()->setBorderStyle(Border::BORDER_THIN);
550 }
551 }

◆ setCell()

ilExcel::setCell ( int  $a_row,
int  $col,
  $value,
?string  $datatype = null,
bool  $disable_strip_tags_for_strings = false 
)

Set cell value.

Parameters
int$a_row
int$col
mixed$value
?string$datatype Explicit data type, see DataType::TYPE_*

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

297 : void {
298 $coordinate = $this->getCoordByColumnAndRow($col, $a_row);
299
300 if ($datatype === DataType::TYPE_STRING) {
301 $this->workbook->getActiveSheet()->setCellValueExplicit(
302 $coordinate,
303 $this->prepareString($value, $disable_strip_tags_for_strings),
304 $datatype
305 );
306 } elseif ($datatype !== null) {
307 $this->workbook->getActiveSheet()->setCellValueExplicit(
308 $coordinate,
309 $this->prepareValue($value),
310 $datatype
311 );
312 } elseif ($value instanceof ilDateTime) {
313 $wb = $this->workbook->getActiveSheet()->setCellValue(
314 $coordinate,
315 $this->prepareValue($value)
316 );
317 $this->setDateFormat($wb->getCell($coordinate), $value);
318 } elseif (is_numeric($value)) {
319 $this->workbook->getActiveSheet()->setCellValueExplicit(
320 $coordinate,
321 $this->prepareValue($value),
322 DataType::TYPE_NUMERIC
323 );
324 } else {
325 $this->workbook->getActiveSheet()->setCellValueExplicit(
326 $coordinate,
327 $this->prepareValue($value),
328 DataType::TYPE_STRING
329 );
330 }
331 }
prepareValue($value)
Prepare value for cell.
setDateFormat(Cell $a_cell, $a_value)
Set date format of cell.

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

+ 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 340 of file class.ilExcel.php.

344 : void {
345 foreach ($a_values as $row_idx => $cols) {
346 if (is_array($cols)) {
347 foreach ($cols as $col_idx => $col_value) {
348 $a_values[$row_idx][$col_idx] = $this->prepareValue($col_value);
349 }
350 } else {
351 $a_values[$row_idx] = $this->prepareValue($cols);
352 }
353 }
354
355 $this->workbook->getActiveSheet()->fromArray($a_values, $a_null_value, $a_top_left);
356 }

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

260 : void
261 {
262 if ($a_value instanceof ilDateTime) {
263 $wb = $this->workbook->getActiveSheet()->setCellValue(
264 $a_coords,
265 $this->prepareValue($a_value)
266 );
267 $cell = $wb->getCell($a_coords);
268 $this->setDateFormat($cell, $a_value);
269 } elseif (is_numeric($a_value)) {
270 $this->workbook->getActiveSheet()->setCellValueExplicit(
271 $a_coords,
272 $this->prepareValue($a_value),
273 DataType::TYPE_NUMERIC
274 );
275 } else {
276 $this->workbook->getActiveSheet()->setCellValueExplicit(
277 $a_coords,
278 $this->prepareValue($a_value),
279 DataType::TYPE_STRING
280 );
281 }
282 }

◆ setColors()

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

Set cell(s) colors.

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

509 : void {
510 $opts = [
511 'fill' => [
512 'fillType' => Fill::FILL_SOLID,
513 'color' => ['rgb' => $a_background]
514 ]
515 ];
516
517 if ($a_font) {
518 $opts['font'] = [
519 'color' => ['rgb' => $a_font]
520 ];
521 }
522
523 $this->workbook->getActiveSheet()->getStyle($a_coords)->applyFromArray($opts);
524 }

◆ setDateFormat()

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

Set date format of cell.

Parameters
Cell$a_cell
mixed$a_value

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

246 : void
247 {
248 if ($a_value instanceof ilDate) {
249 $a_cell->getStyle()->getNumberFormat()->setFormatCode('dd.mm.yyyy');
250 } elseif ($a_value instanceof ilDateTime) {
251 $a_cell->getStyle()->getNumberFormat()->setFormatCode('dd.mm.yyyy hh:mm:ss');
252 }
253 }

◆ setFormat()

ilExcel::setFormat ( string  $a_format)

Set file format.

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

105 : void
106 {
107 if (in_array($a_format, $this->getValidFormats())) {
108 $this->format = $a_format;
109 }
110 }
getValidFormats()

References getValidFormats().

Referenced by __construct().

+ 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 399 of file class.ilExcel.php.

399 : void
400 {
401 // this may change the active sheet
402 foreach ($this->workbook->getWorksheetIterator() as $worksheet) {
403 $this->workbook->setActiveSheetIndex($this->workbook->getIndex($worksheet));
404 $sheet = $this->workbook->getActiveSheet();
405 $cellIterator = $sheet->getRowIterator()->current()->getCellIterator();
406 $cellIterator->setIterateOnlyExistingCells(true);
407 foreach ($cellIterator as $cell) {
408 $sheet->getColumnDimension($cell->getColumn())->setAutoSize(true);
409 }
410 }
411 }

◆ writeToFile()

ilExcel::writeToFile ( string  $a_file)

Save workbook to file.

Exceptions

PhpOffice\PhpSpreadsheet\Writer\Exception

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

474 : void
475 {
476 $a_file = $this->prepareStorage($a_file);
477
478 $writer = IOFactory::createWriter($this->workbook, $this->format);
479 $writer->save($a_file);
480 }

◆ writeToTmpFile()

ilExcel::writeToTmpFile ( )
Exceptions

PhpOffice\PhpSpreadsheet\Writer\Exception

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

485 : string
486 {
487 $writer = IOFactory::createWriter($this->workbook, $this->format);
489 $writer->save($filename);
490
491 return $filename;
492 }

References $filename, and ilFileUtils\ilTempnam().

+ 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.

◆ $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.

Referenced by getValidFormats().

◆ FORMAT_XML

const ilExcel::FORMAT_XML = 'Xlsx'

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