php电子表格excel阅读器返回匿名值

时间:2016-12-12 17:38:44

标签: php excel codeigniter phpexcelreader

我正在使用php电子表格excel阅读器来阅读excel文件并进行一些操作。 它工作正常,突然开始返回值'常规',如果是整数列

Sample rows from excel:

enter image description here

代码:

$dataFields = array("alias"=>"alias","store_quantity"=>"store_quantity","godown_quantity"=>"godown_quantity","name"=>"name");

$mandatoryFeilds = array("alias","store_quantity","godown_quantity","name");

$fieldsPos = array();
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('CP1251');
$data->read($_FILES['upload-file']['tmp_name']);
for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++)
{    
     if ( isset($data->sheets[0]['cells'][1][$j]) == true )
     {
          $fieldsPos[$data->sheets[0]['cells'][1][$j]] = $j;
          if(array_search($data->sheets[0]['cells'][1][$j],$mandatoryFeilds)!==false)
          {
               unset($mandatoryFeilds[array_search($data->sheets[0]['cells'][1][$j],$mandatoryFeilds)]);

          }
     }
}

if(count($mandatoryFeilds)>0)
{
     die('Some of the mandatory columns are missing in excel');
}

for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) 
{
    //printing the output here to check values received from excel which are some anonymous values getting returned
    var_dump($data->sheets[0]['cells'][$i]);

}

输出:

array("alias"=>"General","name"=>"Item A","store_quantity"=>"General","godown_quantity"=>"General")

任何人都可以帮我这个吗?任何帮助都将受到重视

3 个答案:

答案 0 :(得分:0)

问题发生了,因为我将我的操作系统从Ubuntu 14更新到Ubuntu 16,后者将Libre Office版本从4.2更新为5

Libre 5中的excel文件正在以上面讨论的方式阅读。因此它与Libre版本有关,而不是与电子表格阅读器有关。

答案 1 :(得分:0)

我遇到了同样的问题。原来那些细胞被阻塞了。这就是电子表格阅读器无法正确读取的原因。

答案 2 :(得分:-1)

据我检查,问题出在Libre Office 5上。

在编辑Excel工作表时无法进入Windows。

我通过读取cellinfo的原始字段来处理整数问题:

$data = new JPhpExcelReader($filename);

$id = $data->sheets[0]['cellsInfo'][$i][1]['raw'];