Skip to content

Invalid cell coordinate error #381

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

Closed
Plasmatron opened this issue Feb 19, 2018 · 9 comments
Closed

Invalid cell coordinate error #381

Plasmatron opened this issue Feb 19, 2018 · 9 comments
Labels

Comments

@Plasmatron
Copy link

Plasmatron commented Feb 19, 2018

This is:

- [ ] a bug report

What are the steps to reproduce?

When I load a template which has a formula e.g. =SUM(Sheet2!E:E) it causes an error. Other similar formulas don't cause the error like =SUM(Sheet2!E2:E27) or =SUM(E:E).

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();
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use PhpOffice\PhpSpreadsheet\IOFactory;
$reader=IOFactory::createReader('Xlsx');
$spreadsheet=$reader->load($file_path);
$writer=new Xlsx($spreadsheet);
$writer->save($file_path);


### Which versions of PhpSpreadsheet and PHP are affected?
@PowerKiKi
Copy link
Member

Please provide a MCVE without relying on an external to reproduce the issue.

@Plasmatron
Copy link
Author

  1. Create an excel spreadsheet with the formula =SUM(Sheet2!E:E) on cell A1 on Sheet1.
  2. Use earlier provided generic PHPSpreadsheet code - to open that newly created excel spreadsheet and then save it. It will be unable to save claiming an invalid cell coordinate error.

@fwilliamconceicao
Copy link

I having same issue today:

Invalid cell coordinate AAAC2 ["[object] (PhpOffice\PhpSpreadsheet\Exception(code: 0): Invalid cell coordinate AAAC2 at

@oleibman
Copy link
Collaborator

Cell coordinate AAAC2 is invalid. Excel does not permit columns beyond XFD (which is how Cell\AddressRange::MAX_COLUMN is defined).

@fwilliamconceicao
Copy link

Cell coordinate AAAC2 is invalid. Excel does not permit columns beyond XFD (which is how Cell\AddressRange::MAX_COLUMN is defined).

I do not understand how this issue is closed without any investigation.

But to reproduce this is very simple:

Just create a large. CSV (my case was with .csv extension) file with 800+ lines and at least 20 columns. You'll see it happening while you're trying to read.

@oleibman
Copy link
Collaborator

The issue was closed over 5 years ago. The fact that you added a comment to it 4 days ago did not reopen it. Nevertheless, based on the incomprehensibly small amount of information you supplied, PhpSpreadsheet was acting correctly, and I explained why. There was certainly no reason to reopen it based on that. You have now supplied new information which may or may not change my assessment. When I get a chance, I will try to use that information to see if I can duplicate your symptom. However, it will make things quicker if you can supply the CSV (or a program which generates it), and a program which fails in the manner you describe when PhpSpreadsheet tries to read it.

@oleibman
Copy link
Collaborator

The following code, based on your "reproduce" instructions above, performs hideously, but that's not what this issue is about.

use PhpOffice\PhpSpreadsheet\Reader\Csv;

$row = "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21\n";
$maxRows = 850000;
$filename = 'issue.381.csv';
echo "creating $filename\n";
$fh = fopen($filename, 'wb');
for ($i = 0; $i < $maxRows; ++$i) {
    if ($i % 10000 === 9999) {
        echo "writing row $i\n";
    }
    fwrite($fh, $row);
}
fclose($fh);
echo "file is written - starting read\n";
$reader = new Csv();
$spreadsheet = $reader->load($filename);
echo "read is complete\n";
$sheet = $spreadsheet->getActiveSheet();
var_dump($sheet->getCell('T99')->getValue()); // expect int(20)
var_dump($sheet->getCell('D810000')->getValue()); // expect int(4)

When the code finally completes, I do not see any exception messages, and the var_dumps show the expected results. So, there is apparently more to your problem than what you have posted so far. At any rate, when you do have a reproducible bug, please open a new issue, rather than adding on to this one.

oleibman added a commit to oleibman/PhpSpreadsheet that referenced this issue Oct 17, 2023
Investigating issue PHPOffice#381, a means was suggested to duplicated a problem, but no problem occurred ... except for performance. This involved a spreadsheet with a large number of cells, definitely not PhpSpreadsheet's strong point; even so, the program (entirely available in the issue) took a disastrous two or so hours to complete on my system. Looking at the Csv Reader code, several opportunities to cache results and avoid function calls jumped out, none of which seem to materially add to the maintenance burden of the program. Testing these changes resulted in a run time of about 20 minutes, still hardly a thing of beauty, but a huge improvement over the original and therefore worth proceeding with.
@fwilliamconceicao
Copy link

The following code, based on your "reproduce" instructions above, performs hideously, but that's not what this issue is about.

use PhpOffice\PhpSpreadsheet\Reader\Csv;

$row = "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21\n";
$maxRows = 850000;
$filename = 'issue.381.csv';
echo "creating $filename\n";
$fh = fopen($filename, 'wb');
for ($i = 0; $i < $maxRows; ++$i) {
    if ($i % 10000 === 9999) {
        echo "writing row $i\n";
    }
    fwrite($fh, $row);
}
fclose($fh);
echo "file is written - starting read\n";
$reader = new Csv();
$spreadsheet = $reader->load($filename);
echo "read is complete\n";
$sheet = $spreadsheet->getActiveSheet();
var_dump($sheet->getCell('T99')->getValue()); // expect int(20)
var_dump($sheet->getCell('D810000')->getValue()); // expect int(4)

When the code finally completes, I do not see any exception messages, and the var_dumps show the expected results. So, there is apparently more to your problem than what you have posted so far. At any rate, when you do have a reproducible bug, please open a new issue, rather than adding on to this one.

Hi,

I'm providing my file example (without the real data but with the right numbers of headers + cols) to contribute.

The attachment
ISSUE #381.csv
is my file.

@oleibman
Copy link
Collaborator

I still don't see a problem.

$filename = 'issue.381c.csv';
echo "starting read\n";
$reader = new Csv();
$spreadsheet = $reader->load($filename);
echo "read is complete\n";
$sheet = $spreadsheet->getActiveSheet();
var_dump($sheet->getCell('T99')->getValue()); // expect V98
var_dump($sheet->getCell('AR243')->getValue()); // last cell - expect V242

Program output:

starting read
read is complete
C:\git\issue.381c.php:14:
string(3) "V98"
C:\git\issue.381c.php:15:
string(4) "V242"

oleibman added a commit that referenced this issue Oct 18, 2023
* Performance Improvements for Csv Reader

Investigating issue #381, a means was suggested to duplicated a problem, but no problem occurred ... except for performance. This involved a spreadsheet with a large number of cells, definitely not PhpSpreadsheet's strong point; even so, the program (entirely available in the issue) took a disastrous two or so hours to complete on my system. Looking at the Csv Reader code, several opportunities to cache results and avoid function calls jumped out, none of which seem to materially add to the maintenance burden of the program. Testing these changes resulted in a run time of about 20 minutes, still hardly a thing of beauty, but a huge improvement over the original and therefore worth proceeding with.

* Redo CsvIssue2232Test

Test cases included duplicates, and didn't account for some things (e.g. French locale will treat both 'vrai' and 'true' as true).

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

No branches or pull requests

4 participants