Skip to content
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

Formula Error when using COUNTIF? #3911

Closed
2 of 8 tasks
roland-jungwirth opened this issue Feb 20, 2024 · 2 comments
Closed
2 of 8 tasks

Formula Error when using COUNTIF? #3911

roland-jungwirth opened this issue Feb 20, 2024 · 2 comments

Comments

@roland-jungwirth
Copy link

This is:

- [X] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

When using the formula =COUNTIF(A1:A19;$D1), the cell's value should calculate the number of times a value occurs in a range.

What is the current behavior?

The error "Formula Error: An unexpected error occurred".

What are the steps to reproduce?

Please provide a Minimal, Complete, and Verifiable example of code that exhibits the issue without relying on an external Excel file or a web server:

<?php

require __DIR__ . '/vendor/autoload.php';
$test_numbers = array( 41, 57, 51, 54, 49, 43, 35, 35, 44, 47, 48, 26, 57, 34, 61, 34, 28, 29, 41 );

// Set the headers to force a download of the Excel file
header( 'Content-Type: application/vnd.ms-excel' );
header( 'Content-Disposition: attachment; filename="test.xlsx"' );
header( 'Cache-Control: max-age=0' );

$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();

$columnArray = array_chunk( $test_numbers, 1 );
$spreadsheet->setActiveSheetIndex( 0 )->fromArray( $columnArray, 'A1' );

$spreadsheet->setActiveSheetIndex( 0 )->setCellValue( 'C1', '=COUNTIF(A1:A19;$D1)' );
$spreadsheet->setActiveSheetIndex( 0 )->setCellValue( 'D1', 41 );

// Create a writer and send the Excel file to the browser
$writer = new Xlsx( $spreadsheet );

ob_end_clean();
$writer->setIncludeCharts( TRUE );

$writer->save( 'php://output' );

If this is an issue with reading a specific spreadsheet file, then it may be appropriate to provide a sample file that demonstrates the problem; but please keep it as small as possible, and sanitize any confidential information before uploading.

What features do you think are causing the issue

  • Reader
  • Writer
  • Styles
  • Data Validations
  • Formula Calculations
  • Charts
  • AutoFilter
  • Form Elements

Does an issue affect all spreadsheet file formats? If not, which formats are affected?

Only tested with xlsx.

Which versions of PhpSpreadsheet and PHP are affected?

PHP 8.1, PhpSpreadsheet: whatever this version is: #3767

@oleibman
Copy link
Collaborator

$spreadsheet->setActiveSheetIndex( 0 )->setCellValue( 'C1', '=COUNTIF(A1:A19,$D1)' );

We are expecting a comma separator, not a semicolon, between A1:A19 and $D1.

@roland-jungwirth
Copy link
Author

Ah, that makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants