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

Cannot load xltx template with conditional formatting or table used anywhere #21

Closed
Max-Kolodezniy opened this issue Oct 4, 2016 · 1 comment
Milestone

Comments

@Max-Kolodezniy
Copy link
Contributor

Max-Kolodezniy commented Oct 4, 2016

Hi to all!

Im trying to open existing template for avoid building workbook from scratch.
It's impossible to load the template if conditional style or table was used. Source templates attached templates.zip

<?php
/*
 * @file PhpSpreadsheet-master/samples/test.php
 */

require __DIR__ . '/Header.php';

// $template = __DIR__ . '/../template_no_issues.xltx';
// $template = __DIR__ . '/../template_bug_table.xltx';
$template = __DIR__ . '/../template_bug_conditional_formatting.xltx';
$output = __DIR__ . '/../workbook_' . date('d_m_Y_H_i_s') . '.xlsx';

// Create temporary file that will be read
$helper->log('Create new Spreadsheet object from ' . $template . ' template');
$callStartTime = microtime(true);
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($template);
$helper->logRead('Excel2007', $template, $callStartTime);

// Export to Excel2007 (.xlsx)
$helper->log('Write to Excel format');
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Excel2007');
$callStartTime = microtime(true);
$writer->save($output);
$helper->logWrite($writer, $output, $callStartTime);

Error log:

[04-Oct-2016 12:08:37 UTC] PHP Catchable fatal error:  Argument 2 passed to PhpOffice\PhpSpreadsheet\Reader\Excel2007::readStyle() must be an instance of stdClass, instance of SimpleXMLElement given, called in /home/vagrant/vhosts/test/PhpSpreadsheet-master/src/PhpSpreadsheet/Reader/Excel2007.php on line 648 and defined in /home/vagrant/vhosts/test/PhpSpreadsheet-master/src/PhpSpreadsheet/Reader/Excel2007.php on line 1898
[04-Oct-2016 12:08:37 UTC] PHP Stack trace:
[04-Oct-2016 12:08:37 UTC] PHP   1. {main}() /home/vagrant/vhosts/test/PhpSpreadsheet-master/samples/test.php:0
[04-Oct-2016 12:08:37 UTC] PHP   2. PhpOffice\PhpSpreadsheet\IOFactory::load() /home/vagrant/vhosts/test/PhpSpreadsheet-master/samples/test.php:26
[04-Oct-2016 12:08:37 UTC] PHP   3. PhpOffice\PhpSpreadsheet\Reader\Excel2007->load() /home/vagrant/vhosts/test/PhpSpreadsheet-master/src/PhpSpreadsheet/IOFactory.php:175
[04-Oct-2016 12:08:37 UTC] PHP   4. PhpOffice\PhpSpreadsheet\Reader\Excel2007::readStyle() /home/vagrant/vhosts/test/PhpSpreadsheet-master/src/PhpSpreadsheet/Reader/Excel2007.php:648

Environment: PHP 5.6.24 on Centos

@PowerKiKi
Copy link
Member

Thanks for reporting. It's fixed on develop branch.

@PowerKiKi PowerKiKi modified the milestone: 2.0 Oct 5, 2016
@PowerKiKi PowerKiKi mentioned this issue Oct 21, 2016
Mirocow pushed a commit to Mirocow/PhpSpreadsheet that referenced this issue Jan 16, 2017
Previously it crashed when loading an file containing conditional formatting

FIX PHPOffice#21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants