1

Closed

OOCalc cells contain same data bug?

description

While I am reading ods files (xls and xlsx are ok) using PHPExcel class and two cells are together and contain the same data, the second cell goes blank, Is it a bug? Here is my code:
 
 
 
 
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . '../../Librerias/phpexcel/Classes/');
include 'PHPExcel/IOFactory.php';
 
$input_fileName = dirname(__FILE__) . '/bug.ods';
$input_file_type = PHPExcel_IOFactory::identify($input_fileName);   
$reader = PHPExcel_IOFactory::createReader($input_file_type);
$reader->setReadDataOnly(true); 
$objPHPExcel = $reader->load($input_fileName);  
$objPHPExcel->setActiveSheetIndex(0);
$rowIterator = $objPHPExcel->getActiveSheet()->getRowIterator();
 
$array_data = array();
foreach($rowIterator as $row){
    $cellIterator = $row->getCellIterator();
    $cellIterator->setIterateOnlyExistingCells(false);
    $rowIndex = $row->getRowIndex ();    
    foreach ($cellIterator as $cell) {
            $array_data[$rowIndex][$cell->getColumn()] = $cell->getCalculatedValue();
    }
}
echo '<pre>' ; print_r($array_data); echo '</pre>' ;
?>
 
 
 
 
Here is the content into bug.ods
 
 
 
 

| A | B | C | D | E | F

1 | 1 | 1 | 2 | 2 | 3 | 3
2 | 2 | 2 | 1 | 1 | 3 | 3
3 | 3 | 3 | 1 | 1 | 2 | 2
4 | a | a | b | b | c | c
5 | b | b | a | a | c | c
6 | c | c | a | a | b | b
 
 
 
 
... and here is the print_r output.
 
 
 
 
Array
(
[1] => Array
    (
        [A] => 1
        [B] => 
        [C] => 2
        [D] => 
        [E] => 3
    )
 
[2] => Array
    (
        [A] => 2
        [B] => 
        [C] => 1
        [D] => 
        [E] => 3
    )
 
[3] => Array
    (
        [A] => 3
        [B] => 
        [C] => 1
        [D] => 
        [E] => 2
    )
 
[4] => Array
    (
        [A] => a
        [B] => 
        [C] => b
        [D] => 
        [E] => c
    )
 
[5] => Array
    (
        [A] => b
        [B] => 
        [C] => a
        [D] => 
        [E] => c
    )
 
[6] => Array
    (
        [A] => c
        [B] => 
        [C] => a
        [D] => 
        [E] => b
    )
 
)
 
 
 
 
 
Am I doing something wrong? Is it a bug?
 
Some idea?

file attachments

Closed May 19, 2012 at 10:38 PM by MarkBaker

comments

cyberconte wrote May 10, 2012 at 12:14 AM

This is because the reader is ignoring the "number-columns-repeated" xml tag. In my case, it looks like this:

/table:table-row><table:table-row table:style-name="ro3"><table:table-cell table:number-columns-repeated="2" office:value-type=\
"string"><text:p>stringtest</text:p></table:table-cell><table:table-cell office:value-type="string"><text:p>stringtest2</text:p></table:table-cell>

The first stringtest comes through just fine, but the second one is uninitialized

This is a fundamental omission that makes reading ods files unreliable with this library.

cyberconte wrote May 10, 2012 at 2:26 AM

Fix for this issue.

MarkBaker wrote May 13, 2012 at 7:09 PM

Thank you cyberconte

OpenOffice didn't make any noticeable use of the number-columns-repeated tag, but LibreOffice uses it extensively. I'd already implemented a simple fix, but it idn't allow for more than two repeats (so it did work with bug.ods, but not with other ods files) but your solution works for two or more repeats so I've implemented it "as is".