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

COUNTIFS Formula has a prefix in Excel =_xlfn.countifs #3819

Closed
BenjaminG1983 opened this issue Dec 10, 2023 · 1 comment · Fixed by #3828
Closed

COUNTIFS Formula has a prefix in Excel =_xlfn.countifs #3819

BenjaminG1983 opened this issue Dec 10, 2023 · 1 comment · Fixed by #3828

Comments

@BenjaminG1983
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?

Create with PHP the formula:
$oWorkSheet->getCell([7, $iRow])->setValue("=COUNTIFS('XX'!K:K,A" . $iRow . ",'XX'!C:C,G3)");

What is the current behavior?

Formula in Excel =_xlfn.countifs($XX.K:K;A4;$XX.C:C;G3)
For COUNTIF - it replaced to ZÄHLENWENN (Germany)

What are the steps to reproduce?

  1. Create a formula with COUNTIFS in PHP
  2. Result in Excel, see stept before
    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';

// Create new Spreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();

// add code that show the issue here...
$spreadsheet->getCell([7, 1])->setValue("=COUNTIFS('XX'!K:K,A1,'XX'!C:C,G1)");

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
- [X] Writer
- [ ] Styles
- [ ] Data Validations
- [ ] Formula Calculations
- [ ] Charts
- [ ] AutoFilter
- [ ] Form Elements

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

### Which versions of PhpSpreadsheet and PHP are affected?
1.29.0
@oleibman
Copy link
Collaborator

oleibman commented Dec 13, 2023

I am not sure what your issue is. Starting with Excel 2010, Microsoft decided that new functions required prefix _xlfn. Starting with Office 365, it decided that some functions needed a second prefix _xlws. These are generally hidden from the end-user since the only time they are needed is when loading a file; if a required prefix is lacking at that time, it will show the cell's value as an error. The COUNTIF function was introduced before Excel 2010, so it doesn't have a prefix; the COUNTIFS function was introduced with 2019, so it does.

So, if you are just asking for an explanation, that's it. However, if you are having a problem because of this, possibly due to your different locale, please give more details on what the problem is.

Supplementary note - I believe our classification that COUNTIFS was introduced with 2019 was incorrect, and that it was available with 2007 and doesn't need a prefix; however the addition of xlfn would still be required for many other functions, e.g. MAXIFS. I will look into removing COUNTIFS from our list.

oleibman added a commit to oleibman/PhpSpreadsheet that referenced this issue Dec 13, 2023
It was on our list as "introduced in 2019". It was, in fact, available with Excel 2007 (https://support.microsoft.com/en-us/office/excel-functions-alphabetical-b3944572-255d-4efb-bb96-c6d90033e188#bm3), so does not require a prefix when writing it to a spreadsheet. Brought to my attention with issue PHPOffice#3819, although I'm not sure correcting this will entirely solve the user's problem.
oleibman added a commit to oleibman/PhpSpreadsheet that referenced this issue Dec 14, 2023
Fix PHPOffice#3819. Excel can add these prefixes (basically invisible to end-user). Formula translation in PhpSpreadsheet fails when dealing with these unexpected prefixes, and, even if it handled it correctly, the unexpected prefixes confuse the users. I have changed to strip those prefixes when translating to a locale. This is probably not perfect, but is almost certainly good enough. I could easily add the same change when translating from a locale to English, but I don't think there's a good use case for that, so am opting not to do so for now.

The documentation mentions `translateFormulaToLocale` and `translateFormulaToEnglish`. Neither of these exist; both names are preceded by an underscore. I have changed the code to match the documentation rather than vice versa, retaining deprecated versions of the underscored routines which merely invoke the non-underscored routines.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants