PHPExcel Sumif and Skip

2020-03-31 07:21发布

问题:

I just want to ask if there's a function in excel/phpexcel that can SUM a range of cells but skip to add every one cell.

Ex. Range is A1:G1 and it will only sum A1+C1+E1+G1 skipping every 1 cell.

Or how can I do that? Please take note that range is dynamic. It could be a1:g1 or further or less.

回答1:

Build the formula dynamically in your PHP script:

$startCell = 'A';
$endCell = 'H';
$row = 1;

$formula = '=' . $startCell . $row;
while ($startCell++ != $endCell && $startCell++ != $endCell) {
    $formula .= '+' . $startCell . $row;
}

EDIT

Note that I've also added a pure Excel formula answer to your previous question



标签: php phpexcel