Asked  7 Months ago    Answers:  5   Viewed   53 times

I'm in the process of using PHPExcel. One of the requirements is that I need to enable php_zip.

(...) if you need PHPExcel to handle .xlsx or .ods files you will need the zip extension...

I'm using PHP v5.3.5. and in my php.ini file, I have the following lines:

;extension=php_xmlrpc.dll
;extension=php_xsl.dll
;extension=php_zip.dll

If I remove the ; in the last line, and restart Wampserver, I get the following error message:

PHP Startup: Unable to load dynamic library 'I:/wamp/.../ext/php_zip.dll' - The specified module could not be found.

Reading the web, many says that as of PHP 5.3.0, php_zip is built-in.

If it is built then why is this line still in the configuration?
Do I get the error message because since it's built in, the file has been removed?

PS. Sorry if this is in the wrong forum, but not sure where else to put it.

 Answers

20

In fact, Zip is included by default. It is a bug that the line is still included.

Saturday, May 29, 2021
 
joostvandriel
answered 7 Months ago
36

The issue ended up being with how I understood the "at" matcher to work. Also, my example was not verbatim how it is in my unit test. I thought the "at" matcher counter worked on a per query basis, where it really works on a per object instance basis.

Example:

class MyClass {

    public function exists($foo) {
        return false;
    }

    public function find($foo) {
        return $foo;
    }
}

Incorrect:

class MyTest extends PHPUnit_Framework_TestCase
{

    public function testThis()
    {
        $mock = $this->getMock('MyClass');
        $mock->expects($this->at(0))
             ->method('exists')
             ->with($this->equalTo('foo'))
             ->will($this->returnValue(true));

        $mock->expects($this->at(0))
             ->method('find')
             ->with($this->equalTo('foo'))
             ->will($this->returnValue('foo'));

        $mock->expects($this->at(1))
             ->method('exists')
             ->with($this->equalTo('bar'))
             ->will($this->returnValue(false));

        $this->assertTrue($mock->exists("foo"));
        $this->assertEquals('foo', $mock->find('foo'));
        $this->assertFalse($mock->exists("bar"));
    }

}

Correct:

class MyTest extends PHPUnit_Framework_TestCase
{

    public function testThis()
    {
        $mock = $this->getMock('MyClass');
        $mock->expects($this->at(0))
             ->method('exists')
             ->with($this->equalTo('foo'))
             ->will($this->returnValue(true));

        $mock->expects($this->at(1))
             ->method('find')
             ->with($this->equalTo('foo'))
             ->will($this->returnValue('foo'));

        $mock->expects($this->at(2))
             ->method('exists')
             ->with($this->equalTo('bar'))
             ->will($this->returnValue(false));

        $this->assertTrue($mock->exists("foo"));
        $this->assertEquals('foo', $mock->find('foo'));
        $this->assertFalse($mock->exists("bar"));
    }

}
Saturday, May 29, 2021
 
Terry
answered 7 Months ago
33

EDIT I added a pull request with a fix: https://github.com/PHPOffice/PHPExcel/pull/251

This happens when you try to duplicate cell's style to the same cell; Take a look at this:

$phpe = new PHPExcel();
$sheet = $phpe->createSheet();

$sheet->setCellValue('A1', 'hi there') ;
$sheet->setCellValue('A2', 'hi again') ;

$sheet->duplicateStyle($sheet->getStyle('A1'), 'A2');

$writer = new PHPExcel_Writer_Excel2007($phpe);
$writer->save('./test.xlsx');

It will work just fine. BUT if I add another line like this:

$sheet->duplicateStyle($sheet->getStyle('A1'), 'A1');

then bang, infinite recursion starts after calling the save method

To fix your code, you should modify this part:

$sheet->duplicateStyle((($level == 0) ?  $this->styles['category'] : $this->styles['subcategory']), Cell::NUMBER . $row);

To something along the lines of:

$style = ($level == 0) ?  $this->styles['category'] : $this->styles['subcategory'];
$targetCoords = Cell::NUMBER . $row;
if($style->getActiveCell() != $targetCoords) {
    $sheet->duplicateStyle($style, $targetCoords);
}
Saturday, May 29, 2021
 
rblarsen
answered 7 Months ago
72

Certain spreadsheet file formats, such as OfficeOpenXML used as the default format by Excel 2007 and above, require ZipArchive. In most recent versions of PHP, ZipArchive is always available, but prior to PHP 5.3 it needed to be manually installed as a PHP extension.

As @briosheje says If you don't have ZipArchive installed/enabled for your PHP, then you can use

PHPExcel_Settings::setZipClass(PHPExcel_Settings::PCLZIP);

PCLZip is included in the PHPExcel distribution as an alternative to PHP's built-in ZipArchive class, though it is quite a bit slower. Enabling PCLZip allows you to work with zip-based spreadsheet formats even without ZipArchive.

However, when we first bundled PCLZip (originally in PHPExcel 1.7.6), it was only an option when writing zip-based formats, not when reading them. We changed that in PHPExcel 1.8.0, so enabling PCLZip now allows you to read zip-based formats as well as writing them.

The PHPEXcel Reader documentation details the different spreadsheet formats, and explains which ones are zip-based.

Monday, July 19, 2021
 
JackTheKnife
answered 5 Months ago
56

Since none of the solutions worked for me I did the following:

  1. Open Nautilus (Linux's file explorer) with root privileges: sudo nautlius.
  2. Navigate to the mysql directory: /opt/lampp/var/mysql.
  3. Delete the phpmyadmin folder. This is the phpmyadmin database in phpMyAdmin
  4. Copy the content of the create_tables.sql (found at /opt/lampp/phpmyadmin/sql) file to another one on the desktop called sql.sql
  5. Open the MySQL command line interface: /opt/lampp/bin/mysql -uroot -p
  6. Then in the mysql promp I ran the script to create the database phpmyadmin with source /home/user/Desktop/sql.sql

That solved the problem for me.

Saturday, July 31, 2021
 
sharjeel
answered 4 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share