4include_once 
'./libs/composer/vendor/autoload.php';
 
   51        $this->lng = 
$DIC->language();
 
   54        $this->workbook->removeSheetByIndex(0);
 
   67        $this->workbook = IOFactory::load(
$filename);
 
   81        return array(self::FORMAT_XML, self::FORMAT_BIFF);
 
   92            $this->format = $a_format;
 
  108    public function addSheet($a_name, $a_activate = 
true)
 
  112        $invalid = array(
'*', 
':', 
'/', 
'\\', 
'?', 
'[', 
']', 
'\'-
','\
'');
 
  114        $a_name = str_replace($invalid, 
"", $a_name);
 
  120        $sheet = 
new Worksheet($this->workbook, $a_name);
 
  121        $this->workbook->addSheet($sheet);
 
  122        $new_index = $this->workbook->getSheetCount() - 1;
 
  124        if ((
bool) $a_activate) {
 
  138        $this->workbook->setActiveSheetIndex($a_index);
 
  149        return $this->workbook->getSheetCount();
 
  160        return $this->workbook->getActiveSheet()->getTitle();
 
  179        if (is_bool($a_value)) {
 
  183        } elseif (is_string($a_value)) {
 
  197            case $a_value instanceof 
ilDate:
 
  217        return $a_value ? 
$lng->txt(
'yes') : 
$lng->txt(
'no');
 
  226        return strip_tags($a_value); 
 
  237        if ($a_value instanceof 
ilDate) {
 
  239            $a_cell->
getStyle()->getNumberFormat()->setFormatCode(
"dd.mm.yyyy");
 
  242            $a_cell->
getStyle()->getNumberFormat()->setFormatCode(
"dd.mm.yyyy hh:mm:ss");
 
  255            $wb = $this->workbook->getActiveSheet()->setCellValue(
 
  259            $cell = $wb->getCell($a_coords);
 
  261        } elseif (is_numeric($a_value)) {
 
  262            $this->workbook->getActiveSheet()->setCellValueExplicit(
 
  265                DataType::TYPE_NUMERIC
 
  268            $this->workbook->getActiveSheet()->setCellValueExplicit(
 
  271                DataType::TYPE_STRING
 
  284    public function setCell($a_row, $a_col, $a_value, $a_datatype = 
null)
 
  288        if (!is_null($a_datatype)) {
 
  289            $this->workbook->getActiveSheet()->setCellValueExplicitByColumnAndRow(
 
  296            $wb = $this->workbook->getActiveSheet()->setCellValueByColumnAndRow(
 
  301            $this->
setDateFormat($wb->getCellByColumnAndRow($col, $a_row), $a_value);
 
  302        } elseif (is_numeric($a_value)) {
 
  303            $wb = $this->workbook->getActiveSheet()->setCellValueExplicitByColumnAndRow(
 
  307                DataType::TYPE_NUMERIC
 
  310            $wb = $this->workbook->getActiveSheet()->setCellValueExplicitByColumnAndRow(
 
  314                DataType::TYPE_STRING
 
  326    public function setCellArray(array $a_values, $a_top_left = 
"A1", $a_null_value = 
null)
 
  328        foreach ($a_values as $row_idx => 
$cols) {
 
  329            if (is_array(
$cols)) {
 
  330                foreach (
$cols as $col_idx => $col_value) {
 
  331                    $a_values[$row_idx][$col_idx] = $this->
prepareValue($col_value);
 
  338        $this->workbook->getActiveSheet()->fromArray($a_values, $a_null_value, $a_top_left);
 
  354        return $this->workbook->getActiveSheet()->getCellByColumnAndRow($col, $a_row)->getValue();
 
  365        return $this->workbook->getActiveSheet()->toArray();
 
  376        return Coordinate::columnIndexFromString($this->workbook->getActiveSheet()->getHighestDataColumn());
 
  389        return Coordinate::stringFromColumnIndex($col);
 
  398        foreach ($this->workbook->getWorksheetIterator() as $worksheet) {
 
  399            $this->workbook->setActiveSheetIndex($this->workbook->getIndex($worksheet));
 
  400            $sheet = $this->workbook->getActiveSheet();
 
  401            $cellIterator = $sheet->getRowIterator()->current()->getCellIterator();
 
  402            $cellIterator->setIterateOnlyExistingCells(
true);
 
  403            foreach ($cellIterator as $cell) {
 
  404                $sheet->getColumnDimension($cell->getColumn())->setAutoSize(
true);
 
  419        $this->workbook->setActiveSheetIndex(0);
 
  421        switch ($this->format) {
 
  423                if (!stristr($a_file_name, 
".xls")) {
 
  424                    $a_file_name .= 
".xls";
 
  429                if (!stristr($a_file_name, 
".xlsx")) {
 
  430                    $a_file_name .= 
".xlsx";
 
  445        require_once(
'./Services/FileDelivery/classes/class.ilPHPOutputDelivery.php');
 
  448        switch ($this->format) {
 
  462        $writer = IOFactory::createWriter($this->workbook, $this->format);
 
  463        $writer->save($tmp_name);
 
  477        $writer = IOFactory::createWriter($this->workbook, $this->format);
 
  478        $writer->save($a_file);
 
  488        $writer = IOFactory::createWriter($this->workbook, $this->format);
 
  506        $this->workbook->getActiveSheet()->getStyle($a_coords)->getFont()->setBold(
true);
 
  516    public function setColors($a_coords, $a_background, $a_font = 
null)
 
  520                'fillType' => Fill::FILL_SOLID,
 
  521                'color' => array(
'rgb' => $a_background)
 
  526            $opts[
'font'] = array(
 
  527                'color' => array(
'rgb' => $a_font)
 
  531        $this->workbook->getActiveSheet()->getStyle($a_coords)->applyFromArray($opts);
 
  543    public function setBorders($a_coords, $a_top, $a_right = 
false, $a_bottom = 
false, $a_left = 
false)
 
  545        $style = $this->workbook->getActiveSheet()->getStyle($a_coords);
 
  549            $style->getBorders()->getTop()->setBorderStyle(Border::BORDER_THIN);
 
  552            $style->getBorders()->getRight()->setBorderStyle(Border::BORDER_THIN);
 
  555            $style->getBorders()->getBottom()->setBorderStyle(Border::BORDER_THIN);
 
  558            $style->getBorders()->getLeft()->setBorderStyle(Border::BORDER_THIN);
 
  572        $columnLetter = Coordinate::stringFromColumnIndex($col);
 
  574        return $columnLetter . $pRow;
 
  582    public function addLink($a_row, $a_column, $a_path)
 
  586        $this->workbook->getActiveSheet()->getCellByColumnAndRow($column, $a_row)->getHyperlink()->setUrl($a_path);
 
An exception for terminatinating execution or to throw for unit testing.
getStyle()
Get cell style.
Helper class to manipulate cell coordinates.
Factory to create readers and writers easily.
@classDescription Date and time handling
get($a_format, $a_format_str='', $a_tz='')
get formatted date
writeToFile($a_file)
Save workbook to file.
getSheetAsArray()
Returns the active sheet as an array.
getSheetCount()
Returns number of sheets.
prepareValue($a_value)
Prepare value for cell.
setCell($a_row, $a_col, $a_value, $a_datatype=null)
Set cell value.
setGlobalAutoSize()
Set all existing columns on all sheets to autosize.
setCellArray(array $a_values, $a_top_left="A1", $a_null_value=null)
Set cell values from array.
columnIndexAdjustment(int $column)
Adjustment needed because of migration PHPExcel to PhpSpreadsheet.
addLink($a_row, $a_column, $a_path)
sendToClient($a_file_name)
Send workbook to client.
setDateFormat(Cell $a_cell, $a_value)
Set date format.
prepareStorage($a_file_name)
Prepare workbook for storage/delivery.
setCellByCoordinates($a_coords, $a_value)
Set cell value by coordinates.
__construct()
Constructor.
getColumnCount()
Returns the number of columns the sheet contains.
setColors($a_coords, $a_background, $a_font=null)
Set cell(s) colors.
loadFromFile($filename)
Loads a spreadsheet from file.
setBold($a_coords)
Set cell(s) to bold.
prepareDateValue(ilDateTime $a_value)
setBorders($a_coords, $a_top, $a_right=false, $a_bottom=false, $a_left=false)
Toggle cell(s) borders.
getSheetTitle()
Return the current sheet title.
getColumnCoord($a_col)
Get column "name" from number.
prepareBooleanValue($a_value)
addSheet($a_name, $a_activate=true)
Add sheet.
setFormat($a_format)
Set file format.
getValidFormats()
Get valid file formats.
setActiveSheet($a_index)
Set active sheet.
getCell($a_row, $a_col)
Returns the value of a cell.
getCoordByColumnAndRow($pColumn=1, $pRow=1)
Get cell coordinate (e.g.
static deliverFileAttached($path_to_file, $download_file_name='', $mime_type='', $delete_file=false)
void
const APPLICATION__OCTET_STREAM
const APPLICATION__VND_MS_EXCEL
const APPLICATION__VND_OPENXMLFORMATS_OFFICEDOCUMENT_SPREADSHEETML_SHEET
static ilTempnam($a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
static shortenText( $a_str, $a_len, $a_dots=false, $a_next_blank=false, $a_keep_extension=false)
shorten a string to given length.