从SpreadsheetExcelReader获取最终输出数组中包含的空白列值

我正在使用下面的插件来读取micrsoft excel文件(.xls扩展名)

http://php-spreadsheetreader.googlecode.com/svn-history/r26/Excel/OLERead.php

按照当前的插件实现,它将读取excel作为数组返回。

下面的代码读取excels并将其作为数组返回

include_once('spreadsheet_excel_reader.php'); $data = new Spreadsheet_Excel_Reader_New(); $data->setOutputEncoding('CP1251'); $data->read('full path of file'); echo '<pre>';print_r($data->sheets[0]['cells']);echo '</pre>';exit; 

数组单元格包含的值数等于Excel表中的行数。

每个值本身都是一个数组,其中包含的键数等于表中的列数。

数组单元格如下所示 –

  [cells] => Array( [1] => Array ( [1] => a [2] => b [3] => c [4] => d [5] => e [6] => f [7] => g ) [2] => Array ( [1] => fddfg [2] => dfgd [5] => ghjgh [6] => dgdf [7] => uyijkgh ) [3] => Array ( [1] => fghfg [2] => gvsfdgdf [4] => fdg4t4 [5] => gfdg [6] => dfgd [7] => ghfghf ) [4] => Array ( [1] => fgh [2] => sfsdf [5] => fghfgh [6] => fsdf [7] => dfgdfg ) ) 

从上面的数组中可以看出,键1包含了表格的标题数组。 所以在excel表格中共有7列。 目前,如果任何单元格在表单中不包含任何值,则会跳过数组中的值,但是我的要求是,如果单元格不包含任何值,则该数组应该包含空值。

在插件中,整个数组创build过程发生在下面的函数中

函数_parsesheet($ spos)

我试图添加一个新的情况下处理空条目,但没有成功。

对上述问题的任何帮助将是很大的。

 $max = 0; array_walk($data->sheets[0]['cells'],function($row) use (&$max) { $max = max(max(array_keys($row)),$max); }); array_walk($data->sheets[0]['cells'],function(&$row) use ($max) { $row = $row + array_fill_keys(range(1,$max),NULL); ksort($row); }); var_dump($data->sheets[0]['cells']); 

用NULL单元填充每个缺less的列对于缺失的行不做任何事情。 PHP> = 5.3.0

你应该如何处理你的内容后的所有空值? 您可以遍历数组并填充所有缺less的行。