Skip to content
This repository was archived by the owner on Jan 2, 2019. It is now read-only.
This repository was archived by the owner on Jan 2, 2019. It is now read-only.

Excel5 writer seems broken when adding many RichText cells. #284

@vansante

Description

@vansante

When creating an Excel5 file with many (>300) RichText cells, Excel seems to have problems opening the file. The generation goes fine and throws no errors. Excel throws an error and cuts off halfway through the spreadsheet. The xlsx file generated by the same code is fine. The PHP versions used are 5.5.5 and 5.4.13.
I have opened the files with Office 2007.

Here is some code to reproduce the bug:

<?php

/** Error reporting */
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('Europe/London');

define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');

/** Include PHPExcel */
require_once '../Classes/PHPExcel.php';


// Create new PHPExcel object
echo date('H:i:s') , " Create new PHPExcel object" , EOL;
$objPHPExcel = new PHPExcel();

// Set default font
$objPHPExcel->getDefaultStyle()->getFont()->setName('Arial')
                      ->setSize(10);
$NUM_ROWS = 30;
$NUM_COLS = 8;

for ($row = 0; $row < $NUM_ROWS; $row++) {
    for ($col = 0; $col < $NUM_COLS; $col++) {
        $objRichText = new PHPExcel_RichText();
        $objRichText->createText('Hello World! ' . $row . '.' . $col);

        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $objRichText);
    }
}

$objPHPExcel->getActiveSheet()->setTitle('RichText Test');

// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);


// Save Excel 95 file
echo date('H:i:s') , " Write to Excel5 format" , EOL;
$callStartTime = microtime(true);

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save(str_replace('.php', '.xls', __FILE__));
echo date('H:i:s') , " File written to " , str_replace('.php', '.xls', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;

echo 'File has been created in ' , getcwd() , EOL;

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions