-
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
Export Error after accessing Cell by name #154
Comments
Please provide a Minimal, Complete, and Verifiable example of code that exhibits this issue without relying on an external Excel file. |
I try to create a example without an externale sheet. But I think the problem is the writing of named areas. I PHPSpreadsheet it is not possible to write them in lower case. In a normale Excel Sheet it is possible. <?php
require_once 'global/thirdparty/PhpSpreadsheet/Autoloader.php';
use \PhpOffice\PhpSpreadsheet\Spreadsheet;
use \PhpOffice\PhpSpreadsheet\IOFactory;
use \PhpOffice\PhpSpreadsheet\NamedRange;
\PhpOffice\PhpSpreadsheet\Autoloader::register();
// Create new Spreadsheet object
$spreadsheet = new Spreadsheet();
$spreadsheet->setActiveSheetIndex(0);
// Define named ranges
$spreadsheet->addNamedRange( new NamedRange('Referent', $spreadsheet->getActiveSheet(), 'B1') );
// Add some data
$spreadsheet->getActiveSheet()->setCellValue('Referent', 'Hello');
// Save
$writer = IOFactory::createWriter($spreadsheet, "Excel2007");
$tempfile = tempnam(ini_get("upload_tmp_dir") . "/", "xlsx");
$writer->save($tempfile);
// Return Spreadsheet
ob_clean();
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment; filename="test.xlsx"');
header('Content-Length: ' . filesize($tempfile));
readfile($tempfile);
unlink($tempfile);
die(); |
Cannot reproduce with latest version of develop branch. The following code will write and reload correctly a named ranged with CamelCase: <?php
require __DIR__ . '/vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\NamedRange;
use PhpOffice\PhpSpreadsheet\IOFactory;
// Create new Spreadsheet object
$spreadsheet = new Spreadsheet();
// Define named ranges
$spreadsheet->addNamedRange(new NamedRange('Referent', $spreadsheet->getActiveSheet(), 'B1'));
// Add some data
$spreadsheet->getActiveSheet()->setCellValue('Referent', 'Hello');
// Save
$filename = 'test.xlsx';
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
$writer->save($filename);
// Reload and check result
$reloadedSpreadsheet = IOFactory::load($filename);
var_dump($reloadedSpreadsheet->getActiveSheet()->getCell('B1')->getCalculatedValue());
var_dump($reloadedSpreadsheet->getActiveSheet()->getCell('Referent')->getCalculatedValue()); The output will correctly be:
|
I am using the access by name to write content to fields. With older versions like PHPExcel 1.7.4. this was no problem.
Now you will get this error:
The text was updated successfully, but these errors were encountered: