-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Subtotal Calculation #332
Comments
I can confirm both LibreOffice 5 and Excel 2016 will produce 4, but PhpSpreadsheet will produce 6 with the following, essentially same, code: <?php
require __DIR__ . '/vendor/autoload.php';
// Create new Spreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A2', 1);
$sheet->setCellValue('A3', 1);
$sheet->setCellValue('A4', '=SUBTOTAL(9,A2:A3)');
$sheet->setCellValue('A6', 1);
$sheet->setCellValue('A7', 1);
$sheet->setCellValue('A8', '=SUBTOTAL(9,A2:A7)');
var_dump($sheet->getCell('A8')->getCalculatedValue()); |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
I'm also having the same problem. Excel 16 on Mac will display as a sum until I recalculate the formula. Has anyone figured this out? |
Guten Tag
Unsere Firma ist bis zum 23. April 2018 ferienhalber geschlossen.
Die Nachrichten werden in dieser Zeit nur sporadisch gelesen.
In dringenden Fällen füllen Sie bitte unser Supportformular aus:
https://support.yourchoice.ch/
Mit freundlichen Grüssen
YourChoice Informatik GmbH
…________________________________
YourChoice Informatik GmbH
Mattenweg 15
2557 Studen BE
[email protected]
https://www.yourchoice.ch
|
I attempted to update the SUBTOTAL function. I noticed there was a filter to remove hidden cells. So I copied it to remove cells that contain protected static function filterFormulaArgs($cellReference, $args)
{
return array_filter(
$args,
function ($index) use ($cellReference) {
list(, $row, $column) = explode('.', $index);
//take this cell out if it contains the SUBTOTAL formula
return strpos(strtoupper($cellReference->getWorksheet()->getCell($column . $row)->getValue()), '=SUBTOTAL(') === false;
},
ARRAY_FILTER_USE_KEY
);
}
/**
* SUBTOTAL.
*
* Returns a subtotal in a list or database.
*
* @param int the number 1 to 11 that specifies which function to
* use in calculating subtotals within a list
* @param array of mixed Data Series
*
* @return float
*/
public static function SUBTOTAL(...$args)
{
$aArgs = Functions::flattenArrayIndexed($args);
$cellReference = array_pop($aArgs);
$subtotal = array_shift($aArgs);
// Calculate
if ((is_numeric($subtotal)) && (!is_string($subtotal))) {
if ($subtotal > 100) {
$aArgs = self::filterHiddenArgs($cellReference, $aArgs);
$subtotal = $subtotal - 100;
}
switch ($subtotal) {
case 1:
return Statistical::AVERAGE($aArgs);
case 2:
return Statistical::COUNT($aArgs);
case 3:
return Statistical::COUNTA($aArgs);
case 4:
return Statistical::MAX($aArgs);
case 5:
return Statistical::MIN($aArgs);
case 6:
return self::PRODUCT($aArgs);
case 7:
return Statistical::STDEV($aArgs);
case 8:
return Statistical::STDEVP($aArgs);
case 9:
//remove cells that contain the SUBTOTAL formula that we're going to pass to SUM
$aArgs = self::filterFormulaArgs($cellReference, $aArgs);
return self::SUM($aArgs);
case 10:
return Statistical::VARFunc($aArgs);
case 11:
return Statistical::VARP($aArgs);
}
}
return Functions::VALUE();
} |
Looking at how this is working in MS Excel,
Needs to apply to all subtotal types, not simply to type 9 |
Implemented code change on branch |
Resolved on develop branch |
This is:
What is the expected behavior?
Subtotal 9 in a group that has other subtotal 9 should excluded the totals of the other subtotals in the range
What is the current behavior?
Subtotal does not skip other subtotals and includes it like a sum
What are the steps to reproduce?
If you run the below then delete A8 in excel then undo. Excel with provide the correct total of 4
the below is producing 6
Which versions of PhpSpreadsheet and PHP are affected?
The text was updated successfully, but these errors were encountered: