PHPExcel一起的单元格包含相同的数据问题 [英] PHPExcel together cells contain same data issue

查看:120
本文介绍了PHPExcel一起的单元格包含相同的数据问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然我使用PHPExcel类读取ods文件(xls和xlsx可以),但两个单元格在一起并且包含相同的数据,第二个单元格为空白,这是一个错误吗?这是我的代码:

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>' ;

?>

这是bug.ods中的内容

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

...这是print_r输出.

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

有什么主意吗?

推荐答案

PHPExcel问题跟踪器上的问题: http://phpexcel.codeplex.com/workitem/17471 这对于两个值是固定的,但是如果值重复而不是两次,则存在问题

Issue on PHPExcel issue tracker: http://phpexcel.codeplex.com/workitem/17471 This fixed for two values, but if value repeat rather than two times problem exist

这篇关于PHPExcel一起的单元格包含相同的数据问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆