phpexcel删除行_在PHPexcel中删除空行
我有以下代碼.
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestDataRow();
$highestColumn = $sheet->getHighestDataColumn();
for ($row = 2; $row <= $highestRow; $row++){
$rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn .
$row,NULL,TRUE,FALSE);
}
如果所有列都是空的,我需要忽略行.我已經(jīng)看到了鏈接ignore empty columns,但是不確定這是否對(duì)我有用.如果它為空,則不需要消除列,但是如果所有列均為空,則不需要消除整個(gè)行.
解決方法:
您需要遍歷行并檢查所有單元格是否為空
樣例代碼
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestDataRow();
$highestColumn = $sheet->getHighestDataColumn();
for ($row = 2; $row <= $highestRow; $row++){
$rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row,NULL,TRUE,FALSE);
if(isEmptyRow(reset($rowData))) { continue; } // skip empty row
// do something usefull
}
function isEmptyRow($row) {
foreach($row as $cell){
if (null !== $cell) return false;
}
return true;
}
標(biāo)簽:phpexcel,php
來(lái)源: https://codeday.me/bug/20191110/2013644.html
總結(jié)
以上是生活随笔為你收集整理的phpexcel删除行_在PHPexcel中删除空行的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: php 做 往安居客发布房源,安居客发布
- 下一篇: 动态规划算法php,php算法学习之动态