忽略PHPExcel中的空单元格 [英] Ignore empty cells PHPExcel

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

问题描述

我正在使用库 PHPExcel 来读取Excel文件中的数据.我遇到的问题是,当我使用类似的东西时:

I'm using the library PHPExcel to read data in an Excel file. The problem I'm having, is that when I use something like:

$obj = PHPExcel_IOFactory::load($file);
$data = $obj->getActiveSheet()->toArray(null,true,true,true);

要加载我的文件并将其内容转换为数组,我将获得数组中Excel文件的所有列和行,即使其中没​​有任何数据也是如此. PHPExcel库中是否有一种方法或某种方法告诉它忽略我的Excel工作表中不包含任何数据的单元格? (而不是在我的$data中有一堆空的关联数组)

To load my file and convert its content into an array, I get all the columns and rows of my Excel file in my array even those without any data in them. Is there a method or something in the library PHPExcel to tell it to ignore cells in my Excel sheet that do not contain any data? (Instead of having a bunch of empty associative arrays in my $data)

推荐答案

如果您的问题是获取要跟随真实数据的空列,而您想避免这些情况,则可以执行以下操作:

If your problem is in getting empty columns that go after real data, and you would like to avoid these, you could do something like this:

$maxCell = $sheet->getHighestRowAndColumn();
$data = $sheet->rangeToArray('A1:' . $maxCell['column'] . $maxCell['row']);

这将返回仅表示包含真实数据的区域的数组.

This will return array representing only the area containing real data.

这篇关于忽略PHPExcel中的空单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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