Anybody made PHPSpreadsheet work

Hi

Been looking at migrating existing PHPExcel Spreadsheet (blank) apps to PHPSpreadsheet.

I can’t even get the basics to work… create an empty spreadsheet as per the PHPSpreadsheet help page.

Elsewhere in the forum it says the way that SC implements the tool, the USE functions cant be used (They have to be at the start of a script I think), but the workaround seems confused (at least I couldn’t understand it :dizzy_face:

The HELP? item in the knowledge base is worse than useless… It has

  1. A link to an OLD version of PHPSpreadsheet
  2. A macro call (includesc_url_library) that as far as I know doesn’t exist
  3. All of the pictures are missing (presumably because of the dumb reorganisation of the forum a few months ago!)

I can get the lib to load, (I tried several different ways) but as soon as I try to use the first command:
$documento= new \PhpOffice\PhpSpreadsheet\Spreadsheet();

I get a syntax error within the Spreadsheet class. (I presume because the ‘use’ command in PHPSpreadsheet help, had to be deleted)

Code is:

require_once(’…/…/…/…’.$this->Ini->path_prod. ‘/third/phpspreadsheet/vendor/autoload.php’);

echo(“Hello
”);
//sc_include_library(“sys”,“PHPSpreadsheet”,“vendor/autoload.php”);

//includesc_url_library(“sys”,“PHPSpreadsheet”,“vendor/autoload.php”);

$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue(‘A1’, ‘Hello World !’);

$writer = new Xlsx($spreadsheet);
$writer->save(‘hello world.xlsx’);

Error is:

Parse error: syntax error, unexpected ‘=’ in C:\Program Files\NetMake\v9Jun18\wwwroot\scriptcase\prod\third\phpspreadsheet\vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Calculation\Calculation.php on line 2460

Can’t get much simpler than this… which begs the question why a similar simple example is not provided either in the knowledgebase or samples.

1 Like

Hi,
This works for me (library version and date [1.11.0] - 2020-03-02)
sc_include_library(“prj”, “Spreadsheet”, “vendor/autoload.php”,true,true);
$inputFileType = \PhpOffice\PhpSpreadsheet\IOFactory::identify($rutaXLS);
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
$objPHPExcel = $reader->load($rutaXLS);
$objPHPExcel->setActiveSheetIndex(1);
$objPHPExcel->setActiveSheetIndex(1)

Thanks for the help, but thats the wrong use-case. I’m trying to simply WRITE a spreadsheet, not READ it.
I notice some you’ve used PHPExcel variable names so I assume youve migrated this successfully.

My basic problem in the WRITE scenario is that the first line (Instantiate a new blank spreadsheet) fails with a syntax error (Within the PHPSpreadsheet class itself, not the calling code) and I can’t find any sensible help to track down whats going on, or what I need to do.

EDIT:
For anyone else struggling… I think the basic problem is that it requires PHP version 7.2 or newer to develop using PhpSpreadsheet. I have a standard 9.4 Scriptcase with PHP 7.0

I do intend to upgrade to 7.3, but the process with Scriptase seems inordinately complex and I don’t have time to do a complete upgrade and test all of my apps right now. Even when I do that on the IDE, I then have to test all of the other things on my server for compatibility with 7.3, so not a trivial task.

Hello, how are you?., i have same problem., please you can confirm if you have solved this issue.?

My EDIT, above indicates the likely cause (needs PHP 7.2), but I have not followed this through to a full solution as the upgrade would be too big a job for me right now.