解决 了嗨,目前我正在使用 SimpleXLSX 解析 xlsx(excel 文件),在返回数组值时删除所有空单元格值,但我需要在返回值中保留任何单元格的空/NULL 值
$xlsx = new SimpleXLSX($uploadfile);
$j =1;
//list($num_cols, $num_rows) = $xlsx->dimension(); //Previous
$items = array();
list($cols,) = $xlsx->dimension($j);
print_r($xlsx->rows());
//foreach ($xlsx->rows() as $r) { //Previous
foreach( $xlsx->rows($j) as $k => $r) { //fixed
// if ($i != 0) {
// for( $i=0; $i < $num_cols; $i++ )//Previous
for( $i = 0; $i < $cols; $i++) //fixed
if(!empty($r[$i]))
{
$v = $r[$i];
}else{
$v = ' ';
}
// echo $v;
$items[$i] = $v;
//
}
$val = implode('|', $items);
O/P:
Array
(
[0] => Array
(
[0] => Name of the Candidate
[1] => phone number
[2] => Postal Address
[3] => mobilenumber
[4] => country
)
[1] => Array
(
[0] => abc
[2] => 123,
[4] => india
)
[2] => Array
(
[0] => fsdfsf
[1] => 23423423
[3] => 3223423423
[4] => us
)
)