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

Xls Writer Cannot Parse TRUE When Supplied as a Function Argument #3369

Closed
1 of 8 tasks
oleibman opened this issue Feb 15, 2023 · 0 comments · Fixed by #3391
Closed
1 of 8 tasks

Xls Writer Cannot Parse TRUE When Supplied as a Function Argument #3369

oleibman opened this issue Feb 15, 2023 · 0 comments · Fixed by #3391

Comments

@oleibman
Copy link
Collaborator

This is:

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

What is the expected behavior?

A function argument of TRUE (and presumably FALSE) can be parsed by the Xls Writer so that the formula is reproduced faithfully when the spreadsheet is saved as Xls.

What is the current behavior?

Parser throws an Exception at the end of function fact. The writer still writes the cell, but with its calculated value rather than its formula. I can see that another regexp or two needs to be tested for this, but I have not yet figured out what should happen if the new regexes are matched. Note that TRUE is parsed correctly as just a cell value (cell A1), and that the TRUE() function is parsed correctly when supplied as an argument (cell A4). However, both cells A2 (TRUE is first argument) and A3 (TRUE is last argument) are written out as a value rather than a formula.

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';

use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xls;

$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->getCell('A1')->setValue(true);
$sheet->getCell('A2')->setValue('=AND(TRUE)');
$sheet->getCell('A3')->setValue('=AND(TRUE, 0)');
$sheet->getCell('A4')->setValue('=AND(TRUE())');
$writer = new Xls($spreadsheet);
$outfile = 'formulaerr2.xls';
$writer->save($outfile);
echo "Saved $outfile\n";

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, in particular Writer/Xls/Parser
  • Styles
  • Data Validations
  • Formula Calculations
  • Charts
  • AutoFilter
  • Form Elements

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

Only Xls is affected.

Which versions of PhpSpreadsheet and PHP are affected?

All.

oleibman added a commit to oleibman/PhpSpreadsheet that referenced this issue Feb 16, 2023
PR PHPOffice#3340 increased coverage in Reader Xls for most functions. Some of the omissions from that PR (see below) were intended from the start. However, the set of (BINOMDIST, EXPONDIST, GAMMADIST, NORMDIST, POISSON, WEIBULL, and FIXED) were not intended to be omitted; they just did not seem to work. Having had time to research, it appears that the problem is not those functions themselves, but rather the use of Boolean constants as function arguments (see issue PHPOffice#3369). Knowing that, it is possible to add those missing functions back in, just taking care to use `0` or `1` or `TRUE()` or `FALSE()` rather than boolean constants as arguments. No update to source or test code; just adding a few new cells to an Xls spreadsheet.

Functions still omitted because they return array results:
- GROWTH
- LINEST
- LOGEST
- MINVERSE
- MMULT
- TRANSPOSE
- TREND

Functions still omitted because they are not implemented in PhpSpreadsheet:
- BAHTTEXT
- CELL
- FREQUENCY
- GETPIVOTDATA
oleibman added a commit that referenced this issue Feb 16, 2023
PR #3340 increased coverage in Reader Xls for most functions. Some of the omissions from that PR (see below) were intended from the start. However, the set of (BINOMDIST, EXPONDIST, GAMMADIST, NORMDIST, POISSON, WEIBULL, and FIXED) were not intended to be omitted; they just did not seem to work. Having had time to research, it appears that the problem is not those functions themselves, but rather the use of Boolean constants as function arguments (see issue #3369). Knowing that, it is possible to add those missing functions back in, just taking care to use `0` or `1` or `TRUE()` or `FALSE()` rather than boolean constants as arguments. No update to source or test code; just adding a few new cells to an Xls spreadsheet.

Functions still omitted because they return array results:
- GROWTH
- LINEST
- LOGEST
- MINVERSE
- MMULT
- TRANSPOSE
- TREND

Functions still omitted because they are not implemented in PhpSpreadsheet:
- BAHTTEXT
- CELL
- FREQUENCY
- GETPIVOTDATA
oleibman added a commit to oleibman/PhpSpreadsheet that referenced this issue Feb 22, 2023
Fix PHPOffice#3369. The parser had failed to account for `TRUE` and `FALSE` when supplied as arguments to a function.

I had hoped to be able to do something about its inability to handle defined names as well. I failed. I think another section might need to be added to the Writer output which specifies the defined names. I haven't yet located any suitable documentation.
oleibman added a commit that referenced this issue Feb 23, 2023
Fix #3369. The parser had failed to account for `TRUE` and `FALSE` when supplied as arguments to a function.

I had hoped to be able to do something about its inability to handle defined names as well. I failed. I think another section might need to be added to the Writer output which specifies the defined names. I haven't yet located any suitable documentation.
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.

1 participant