Giter Site home page Giter Site logo

php_excel's Introduction

Description

This extension uses libXl library to provide API for generating or parsing all Excel files.

libxl is a high-performance mechanism for working with Excel files and is able to generate output readable on Blackberries, iPhone, Office Products, Numbers, etc...

Contributing

Read the information in the CONTRIBUTOR.md document.

Documentation

Please see the docs/ and the tests/ directory.

Resources

Installation

Linux

# change into php source files directory
cd php-5.x.x

# clone repository into php extension dir
git clone https://github.com/iliaal/php_excel.git ext/excel

# to build php7 module, you should use php7 git branch
cd ext/excel && git checkout php7 && cd ../..

# rebuild configure
./buildconf --force

# replace <PATH> with the file path to the extracted libxl files
# on a 32-bit platform use
./configure --with-excel --with-libxl-incdir=<PATH>/libxl-3.6.0.1/include_c --with-libxl-libdir=<PATH>/libxl-3.6.0.1/lib

# on a 64-bit platform use
./configure --with-excel --with-libxl-incdir=<PATH>/libxl-3.6.0.1/include_c --with-libxl-libdir=<PATH>/libxl-3.6.0.1/lib64

Windows

Pre-build packages for Windows can be downloaded here.

Getting started

<?php
    
// init excel work book as xlsx
$useXlsxFormat = true;
$xlBook = new \ExcelBook('<YOUR_LICENSE_NAME>', '<YOUR_LICENSE_KEY>', $useXlsxFormat);
$xlBook->setLocale('UTF-8');

// add sheet to work book
$xlSheet1 = $xlBook->addSheet('Sheet1');

// create a small sample data set
$dataset = [
    [1, 1500, 'John', 'Doe'],
    [2,  750, 'Jane', 'Doe']
];

// write data set to sheet
$row = 1;
foreach($dataset as $item){
    $xlSheet1->writeRow($row, $item);
    $row++;
}

// write sum formula under data set
$col = 1;
$xlSheet1->write($row, $col, '=SUM(B1:B3)');

// add second sheet to work book
$xlSheet2 = $xlBook->addSheet('Sheet2');

// add a date with specific date format to second sheet
$row = 1; $col = 0;
$date = new \DateTime('2014-08-02');
$dateFormat = new \ExcelFormat($xlBook);
$dateFormat->numberFormat(\ExcelFormat::NUMFORMAT_DATE);
$xlSheet2->write($row, $col, $date->getTimestamp(), $dateFormat, \ExcelFormat::AS_DATE);

// save workbook
$xlBook->save('test.xlsx');

optional php.ini settings

To prevent unveiling your credentials in your code you can save them in your php.ini file. They will be automatically fetched by the extension and you can pass null instead of your credentials new \ExcelBook(null, null, $useXlsxFormat).

; optional settings for excel extension
[excel]
excel.license_name="<YOUR_LICENSE_NAME>"
excel.license_key="<YOUR_LICENSE_KEY>"
excel.skip_empty=0

Known Issues

Formulas written but no values readable

Excel stores value and formula for each cell while LibXL stores only the formula. This means if you create an Excel sheet with php_excel and write a formula like =SUM(A1:B1) in cell C1 you can't read the value of the calculation by reading cell C1 in a later step. There has been observations that this can also affect the OS pre-view of Excel files. You can circumvent this by opening and saving the file directly in Excel or using the COM classes to open and save the Excel file via PHP. (In both cases Excel is required!)

multibyte characters in credentials

If your credentials does not work properly because of multibyte characters you can compile php_excel with --with-xml --with-libxml --with-iconv and your credentials will be automatically utf8_decoded() before using with LibXL.

If you compile php_excel as a shared extension on Linux you need to provide the path to the libxml directory. e.g. on Ubuntu you need to compile with --with-libxml-dir=/usr/include/libxml2.

Further reading

php_excel's People

Contributors

dmytroskr avatar do-io avatar iliaal avatar jacksonja avatar jan-e avatar johmue avatar jwestbrook avatar nicoder avatar pierrejoye avatar rgagnon24 avatar sebbrandt87 avatar selivan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php_excel's Issues

Apache segfault when accessing row 0 (column headers)

I have integrated this PHP module into our Apache server, running PHP 5.4.16, after compiling it against the LibXL version 3.5.4.1 library. The compilation completed just fine and the module loads successfully, but the Apache server crashes with a segmentation violation whenever we try to read the column headers (row 0). Other rows can be successfully retrieved from the file. Is this a known problem, or is it unique to our environment?

We can replicate this with a simple two line, 4 column spreadsheet.

Many thanks in advance...

Problem encoding

I try to write cell with accent, but my cells remain empty.

$str = "école";
$s->write(5, 5, $str);
$str = utf8_encode("école");
$s->write(5, 6, $str);
$str = utf8_decode("école");
$s->write(5, 7, $str);
$str = iconv('UTF-8', 'ASCII//TRANSLIT', 'école');
$s->write(5, 8, $str);
$str = iconv('UTF-8', 'Windows-1252//TRANSLIT', 'école');
$s->write(5, 9, $str);

Every cells are empty except the 5,8 which contain '?cole'

$x->setLocale('.1252');
$s = $x->addSheet("Sheet 1");
$str = "école";
$s->write(5, 5, $str);
$str = utf8_encode("école");
$s->write(5, 6, $str);
$str = utf8_decode("école");
$s->write(5, 7, $str);
$str = iconv('UTF-8', 'ASCII//TRANSLIT', 'école');
$s->write(5, 8, $str);
$str = iconv('UTF-8', 'Windows-1252//TRANSLIT', 'école');
$s->write(5, 9, $str);

Same thing with this case.
version : iliaal-php_excel-37e0730

Parsing/Reading Dates

Hello ilia, I have a problem reading dates from Excel files, Please help me by giving a sample code to parse a date format like this.

12/1/2013 04:30:33 and formatted like Dec 1, 2013 4:30:33

I like it to be Y-m-d Format but it gives me inaccurate result, I used date("Y-m-d", strtotime(DATEFROMEXCEL))

I also tried without strtotime, but it is still inaccurate.

Is it possible that instead to get a double or a unix time whatever that number it is "231241245" can i just get the whole string that is being inputted there?

Can't compile on RHEL 4.8, PHP 5.1.6

Hi,

I tried to compile extension on RHEL 4.8, PHP 5.1.6, but I'm getting error while compiling:

[user@dev1 excel-0.9.6]$ make
/bin/sh /home/user/excel-0.9.6/libtool --mode=compile gcc  -I. -I/home/user/excel-0.9.6 -DPHP_ATOM_INC -I/home/user/excel-0.9.6/include -I/home/user/excel-0.9.6/main -I/home/user/excel-0.9.6 -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/home/user/libxl-3.2.3/include  -DHAVE_CONFIG_H  -g -O2   -c /home/user/excel-0.9.6/excel.c -o excel.lo
 gcc -I. -I/home/user/excel-0.9.6 -DPHP_ATOM_INC -I/home/user/excel-0.9.6/include -I/home/user/excel-0.9.6/main -I/home/user/excel-0.9.6 -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/home/user/libxl-3.2.3/include -DHAVE_CONFIG_H -g -O2 -c /home/user/excel-0.9.6/excel.c  -fPIC -DPIC -o .libs/excel.o
/home/user/excel-0.9.6/excel.c:72: warning: parameter names (without types) in function declaration
/home/user/excel-0.9.6/excel.c: In function `PHP_GINIT_FUNCTION':
/home/user/excel-0.9.6/excel.c:5157: error: invalid type argument of `unary *'
/home/user/excel-0.9.6/excel.c:5157: error: incompatible type for argument 1 of `memset'
/home/user/excel-0.9.6/excel.c: At top level:
/home/user/excel-0.9.6/excel.c:5180: error: `excel' undeclared here (not in a function)
/home/user/excel-0.9.6/excel.c:5180: error: initializer element is not constant
/home/user/excel-0.9.6/excel.c:5180: error: (near initialization for `excel_module_entry.post_deactivate_func')
/home/user/excel-0.9.6/excel.c:5181: error: initializer element is not constant
/home/user/excel-0.9.6/excel.c:5181: error: (near initialization for `excel_module_entry.globals_id')
/home/user/excel-0.9.6/excel.c:5182: warning: initialization makes integer from pointer without a cast
/home/user/excel-0.9.6/excel.c:5183: warning: initialization makes integer from pointer without a cast
/home/user/excel-0.9.6/excel.c:5184: warning: excess elements in struct initializer
/home/user/excel-0.9.6/excel.c:5184: warning: (near initialization for `excel_module_entry')
/home/user/excel-0.9.6/excel.c:5184: warning: excess elements in struct initializer
/home/user/excel-0.9.6/excel.c:5184: warning: (near initialization for `excel_module_entry')
/home/user/excel-0.9.6/excel.c:5185: warning: excess elements in struct initializer
/home/user/excel-0.9.6/excel.c:5185: warning: (near initialization for `excel_module_entry')
make: *** [excel.lo] Greška 1

sheet->writeFormula

I'm sure I'm missing something, but there doesn't seem to be a sheet->writeFormula() function like there is in libXL, and doing something like

$s->write(5,1,"=sum(A1:A4)");

inserts it as a string, not a formula.

Doesn't compile with libxl-3.5.4.1

I solved the issue for myself, personally, by downloading libxl-3.4.1.4 - at which point it went without a problem. After configuring against 3.5.4.1 there were numerous errors running make.

I'd like to also take the opportunity to thank you for the library - its outstandingly fast, and easy to use. Appreciate it!

Unable to get calculated cell value for IF formula condition

I try to get calculated value for cell which contain IF condition, the read function return the formula string instead of actual value. This doesn't happen on other formula cell like SUM which working fine. Am I missing something here ?

FYI Im using the latest ver 0.9.8 with PHP 5.4.20 on windows platform.

Thanks!

wrapped format won't work

I can't get a multi-line cell working. The newline character "\n" seems to ge correctly interpreted and shows up in the Excel sheet, but it won't get wrapped.
I tried calling the ExcelFormat::wrap() method like e.g.:

$wrappedFormat = $book->addFormat();
$wrappedFormat->wrap(true);

$data = array('Date', "Foo\nBar");

// setting wrapped format directly in writeRow()
$sheet->writeRow(0, $data, 0, $wrappedFormat);

// setting wrapped format afterwards
$sheet->writeRow(1, $data);
$sheet->setCellFormat(1, 1, $wrappedFormat);

both won't work. Any idea?

tested on the following systems:

  • OS X 10.8.2, PHP 5.4.8, php_excel 0.9.7 (Macports), libxl 3.2.4 (Macports)
  • Debian Squeeze, PHP 5.4.8, php_excel 0.9.7 (latest from git master), libxl 3.3.1

Unable to load module

I am trying to install php_excel on an older testing server but running into issues.

Was able to compile the extension (after upgrading from GCC 3.4.4 to 3.6.4), but now get:

Error:
PHP Startup: Unable to load dynamic library '/usr/local/zend25/Core/lib/php/20060613/excel.so' - /lib/libgcc_s.so.1: version `GCC_4.2.0' not found (required by /usr/lib/libstdc++.so.6)

Is GCC 4.2 a requirement for the extension to work? (also weird since I compiled it with GCC 3.6.4)

System:
Apache/2.2.4 (Unix) mod_ssl/2.2.4 OpenSSL/0.9.8d Zend Core/2.5.0 PHP/5.2.4
Redhat Linux 2.6.9-22.ELsmp #1 SMP Mon Sep 19 18:32:14 EDT 2005 i686

Thanks

Reading Date.

Hi, I can't find a way to read the date with formatting on excel. am I missing something? thank you.

execl-php 0.9.6 does not work with Libxl 3.2.3

I have been trying to get php-excel working but having problems, it will compiles with no errors, but when we run the make test I get a php error

PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/modules/excel.so' - /usr/lib/php/modules/excel.so: undefined symbol: zend_parse_parameters_none in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/modules/excel.so' - /usr/lib/php/modules/excel.so: undefined symbol: zend_parse_parameters_none in Unknown on line 0

and all the tests fail, I managed to get a Libxl version 3.1.0 that compiles and runs without any problem with 0.9.6, but half the test fails (mainly formating ones).

it looks to me execl-php is tring to referance a function that is not in the the newer version of libxl

problems with special characters (german umlauts)

german umlauts won't be put into the excel sheets correctly.
tested with libxl directly, which works flawlessly, however, it's impossible to add umlauts to the excel files via the php-wrapper.

this is the code i tried to use:

<?
$x = new ExcelBook(NULL, NULL, TRUE);
$s = $x->addSheet("Sheet 1");
$s->write(1, 1, 'äüöß'); # wont work
$s->write(2, 2, 123); # echos 123 as expected
$s->write(3, 3, "äüöß"); # wont work
$s->write(4, 4, 'abc'); # abc as expected
$x->save("file.xlsx");
?>

Can't compile : excel module requires libxl >= 2.4.3

Hello,

I try to compile your module :

~/iliaal-php_excel-37e0730# phpize
Configuring for:
PHP Api Version: 20090626
Zend Module Api No: 20090626
Zend Extension Api No: 220090626
~/iliaal-php_excel-37e0730# ./configure --with-libxl-incdir=/root/libxl-3.2.3/include_c --with-libxl-libdir=/root/libxl-3.2.3/lib
checking... (lots of line)
checking whether to enable excel support... yes, shared
checking C include dir for libxl... yes, shared
checking lib dir for libxl... yes, shared
checking for excel includes... found in /root/libxl-3.2.3/include_c
checking for excel libraries... found in /root/libxl-3.2.3/lib
checking for xlCreateBookCA in -lxl... no
configure: error: excel module requires libxl >= 2.4.3

compiling failure

ext\excel-0.9.6\excel.c(3680) : error C2143: Syntaxfehler: Es fehlt ';' vor 'enu
m [tag]'

Something wrong in the sourcecode.

Sincerely
sebbrandt87

possible issue in readRow

hi Ilia,

..\pecl\php_excel\excel.c(2074) : warning C4244: '=' : conversion from 'long' to 'unsigned short', possible loss of data
..\pecl\php_excel\excel.c(2133) : warning C4244: '=' : conversion from 'long' to 'unsigned short', possible loss of data

not sure why you use unsigned short here while the function signature takes a signed integer:

static zend_bool php_excel_read_cell(int row, int col, zval *val, SheetHandle sheet, BookHandle book, FormatHandle *format)

and this variable is initialized using ling, could lead to some funny values :)

will not compile with php_excel 0.9.6 + /libxl 3.3.1

./configure --with-excel=../libxl-3.3.1 --with-libdir=../libxl-3.3.1/lib
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... ../libxl-3.3.1/lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu
checking for PHP prefix... /usr
checking for PHP includes... -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
checking for PHP extension directory... /usr/lib/php5/20090626+lfs
checking for PHP installed headers prefix... /usr/include/php5
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... no
checking for nawk... nawk
checking if nawk is broken... no
checking whether to enable excel support... yes, shared
checking C include dir for libxl... yes, shared
checking lib dir for libxl... yes, shared
checking for excel includes... not found
configure: error: Please reinstall the excel distribution

PHP Api Version: 20090626
Zend Module Api No: 20090626
Zend Extension Api No: 220090626

PHP 5.3.6-13ubuntu3.8 with Suhosin-Patch (cli) (built: Jun 13 2012 17:19:54)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
with Xdebug v2.2.1, Copyright (c) 2002-2012, by Derick Rethans

excel.so load issue

Hey Mate,

Wondering if you've seen this before?

PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/modules/excel.so' - /usr/lib/php/modules/excel.so: undefined symbol: xlBookSetKeyA in Unknown on line 0

Thanks,

Nathan

Unable to create module

Hello,

I'm trying to create the module but I keep getting to same error excel module requires libxl >= 2.4.3

php-excel: 0.9.1, extracted to excel-0.9.1
libxl: 3.1.0, extracted to libxl3.1.0
OS: Ubuntu 10.04 (x64)

From the excel-0.9.1 folder I perform:

  • phpize
  • ./configure --with-excel --with-libxl-libdir=../libxl-3.1.0/lib64 --with-libxl-incdir=../libxl-3.1.0/include_c

The result:

 checking for grep that handles long lines and -e... /bin/grep
 checking for egrep... /bin/grep -E
 checking for a sed that does not truncate output... /bin/sed
 checking for cc... cc
 checking whether the C compiler works... yes
 checking for C compiler default output file name... a.out
 checking for suffix of executables... 
 checking whether we are cross compiling... no
 checking for suffix of object files... o
 checking whether we are using the GNU C compiler... yes
 checking whether cc accepts -g... yes
 checking for cc option to accept ISO C89... none needed
 checking how to run the C preprocessor... cc -E
 checking for icc... no
 checking for suncc... no
 checking whether cc understands -c and -o together... yes
 checking for system library directory... lib
 checking if compiler supports -R... no
 checking if compiler supports -Wl,-rpath,... yes
 checking build system type... x86_64-unknown-linux-gnu
 checking host system type... x86_64-unknown-linux-gnu
 checking target system type... x86_64-unknown-linux-gnu
 checking for PHP prefix... /usr
 checking for PHP includes... -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib
 checking for PHP extension directory... /usr/lib/php5/20090626
 checking for PHP installed headers prefix... /usr/include/php5
 checking if debug is enabled... no
 checking if zts is enabled... no
 checking for re2c... no
 configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
 checking for gawk... gawk
 checking whether to enable excel support... yes, shared
 checking C include dir for libxl... yes, shared
 checking lib dir for libxl... yes, shared
 checking for excel includes... found in ../libxl-3.1.0/include_c
 checking for excel libraries... found in ../libxl-3.1.0/lib64/libxl.so
 checking for xlCreateBookCA in -lxl... no
 configure: error: excel module requires libxl >= 2.4.3

I have libxl 3.1.0, it found the library, but I still get the error that it's not above 2.4.3. What can be the cause of the problem?

Text literal #N/A read as number 42

Hi,

I'm reading from an Excel 2010 xlsx workbook where the values in the sheet have been copied from formulae and then pasted as values only. This is using PHP 5.3.6 and version 0.9.1 of the extension, compiled under Windows Server 2003, x86.

When I read() cells that now contain the text #N/A (not the actual Excel NA() error or formula any more), these are coming through into PHP as a numeric value, equal to 42 (ironically, the meaning of life).

Can you replicate this, or verify for similar patterns of text, eg #string perhaps?

Many thanks,
-Will

Template format overwritten

It isn't possible for me to use the format defined in a template file.
Everytime i write into a cell the definied format is vanished.

I can't define formats while building the export beacause at this time i dont know where i have to use which format.
eg. if the template contains borders, they are missing in cells which i have filled with text / numbers.

how can i use the format used in the template file?

by the way, good job iliaal.


Kell

lastCol() and lastRow()

Hi,

if I use lastCol() and lastRow() with an Excel sheet I get the maximum number of columns and rows which I think is not intended.

Thx
Johannes

Compilation fails with libxl 3.5.3.0

When trying to compile the extension with libxl 3.5.3.0, it fails.

./configure --with-excel=../libxl-3.5.3.0 --with-libxl-libdir=../libxl-3.5.3.0/lib --with-libxl-incdir=../libxl-3.5.3.0/include_c
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... i386-apple-darwin12.3.0
checking host system type... i386-apple-darwin12.3.0
checking target system type... i386-apple-darwin12.3.0
checking for PHP prefix... /usr/local/Cellar/php54/5.4.11
checking for PHP includes... -I/usr/local/Cellar/php54/5.4.11/include/php -I/usr/local/Cellar/php54/5.4.11/include/php/main -I/usr/local/Cellar/php54/5.4.11/include/php/TSRM -I/usr/local/Cellar/php54/5.4.11/include/php/Zend -I/usr/local/Cellar/php54/5.4.11/include/php/ext -I/usr/local/Cellar/php54/5.4.11/include/php/ext/date/lib
checking for PHP extension directory... /usr/local/Cellar/php54/5.4.11/lib/php/extensions/no-debug-non-zts-20100525
checking for PHP installed headers prefix... /usr/local/Cellar/php54/5.4.11/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... no
checking for nawk... no
checking for awk... awk
checking if awk is broken... no
checking whether to enable excel support... yes, shared
checking C include dir for libxl... yes, shared
checking lib dir for libxl... yes, shared
checking for excel includes... found in ../libxl-3.5.3.0/include_c
checking for excel libraries... not found
configure: error: Please reinstall the excel distribution

Option in writeRow() method to skip NULL values instead of writing blank cells

We've used PHPExcel before LibXL and the Excel files of LibXL were much larger in filesize (like 5 times bigger).

We've tracked it down to the writeRow() method, which loops over the data and calls writeCell() internally with the cell data provided. In your writeCell() you check for NULL values and you write them as blank cells (using LibXL's writeBlank()) instead of just skipping them. This results in the much larger files just for blank cells.

My suggestion would be to create an extra argument to the writeRow() method to check for NULL values and skip the cells or write them as blank cells.

I've solved it by manually looping over the data and check if the data is NULL and call your write() method directly. So skipping writeRow().

Problem with background color

$excel = new \ExcelBook(null, null, 1);
$excel->setRgbMode(true);
$sheet = $excel->addSheet("Worksheet");
$format = $excel->addFormat();
$color = $excel->colorPack(200, 217, 220);
$format->fillPattern(\ExcelFormat::FILLPATTERN_SOLID);
$format->patternBackgroundColor($color);
$sheet->write(1, 1, 'Test', $format);

The background of cell is black.

ExcelBook::packDate doesn't work for negative timestamps

I was using ExcelBook::packdate( strtime( "mm-dd-yyyy" ) ); to create dates in my Excel files; however, it did not work properly for any dates before the UNIX epoch. Simply setting the cell to a numeric value computed from the formulas at http://www.massyn.net/?p=17 and setting the format of the cell worked fine, however.

I see the the C source code is filtering out everything that is below 1, but I don't know enough about PHP extensions to understand what is going on.

Thanks for your work!

getSheet returning false

I manage to load the ExcelBook from the xlsx file but when I try to call getSheet, the return result is false instead of ExcelSheet object. The file consist of around 90k rows with 140 columns inside. This doesn't happen for file less than 90k rows...

FYI, im using PHP 5.4.20, libxl 3.5.40 and php_excel 1.0.0

make error

Hi,make exits with with the following:

root@SRV-IMPBDD-002:/usr/src/php_excel-0.9.9# make
/bin/bash /usr/src/php_excel-0.9.9/libtool --mode=compile cc  -I. -I/usr/src/php_excel-0.9.9 -DPHP_ATOM_INC -I/usr/src/php_excel-0.9.9/include -I/usr/src/php_excel-0.9.9/main -I/usr/src/php_excel-0.9.9 -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -I/usr/src/libxl-3.5.4.1/include_c  -DHAVE_CONFIG_H  -g -O2   -c /usr/src/php_excel-0.9.9/excel.c -o excel.lo
libtool: compile:  cc -I. -I/usr/src/php_excel-0.9.9 -DPHP_ATOM_INC -I/usr/src/php_excel-0.9.9/include -I/usr/src/php_excel-0.9.9/main -I/usr/src/php_excel-0.9.9 -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -I/usr/src/libxl-3.5.4.1/include_c -DHAVE_CONFIG_H -g -O2 -c /usr/src/php_excel-0.9.9/excel.c  -fPIC -DPIC -o .libs/excel.o
/usr/src/php_excel-0.9.9/excel.c:57: error: redeclaration of enumerator âPICTURETYPE_PNGâ
/usr/src/libxl-3.5.4.1/include_c/enum.h:69: note: previous definition of âPICTURETYPE_PNGâ was here
/usr/src/php_excel-0.9.9/excel.c:57: error: redeclaration of enumerator âPICTURETYPE_JPEGâ
/usr/src/libxl-3.5.4.1/include_c/enum.h:69: note: previous definition of âPICTURETYPE_JPEGâ was here
/usr/src/php_excel-0.9.9/excel.c:57: error: redeclaration of enumerator âPICTURETYPE_WMFâ
/usr/src/libxl-3.5.4.1/include_c/enum.h:69: note: previous definition of âPICTURETYPE_WMFâ was here
/usr/src/php_excel-0.9.9/excel.c:57: error: redeclaration of enumerator âPICTURETYPE_DIBâ
/usr/src/libxl-3.5.4.1/include_c/enum.h:69: note: previous definition of âPICTURETYPE_DIBâ was here
/usr/src/php_excel-0.9.9/excel.c:57: error: redeclaration of enumerator âPICTURETYPE_EMFâ
/usr/src/libxl-3.5.4.1/include_c/enum.h:69: note: previous definition of âPICTURETYPE_EMFâ was here
/usr/src/php_excel-0.9.9/excel.c:57: error: redeclaration of enumerator âPICTURETYPE_PICTâ
/usr/src/libxl-3.5.4.1/include_c/enum.h:70: note: previous definition of âPICTURETYPE_PICTâ was here
/usr/src/php_excel-0.9.9/excel.c:57: error: redeclaration of enumerator âPICTURETYPE_TIFFâ
/usr/src/libxl-3.5.4.1/include_c/enum.h:70: note: previous definition of âPICTURETYPE_TIFFâ was here
/usr/src/php_excel-0.9.9/excel.c:57: error: redeclaration of enumerator âPICTURETYPE_ERRORâ
/usr/src/libxl-3.5.4.1/include_c/enum.h:70: note: previous definition of âPICTURETYPE_ERRORâ was here
/usr/src/php_excel-0.9.9/excel.c: In function âzim_ExcelSheet_setNamedRangeâ:
/usr/src/php_excel-0.9.9/excel.c:3436: error: too few arguments to function âxlSheetSetNamedRangeAâ
/usr/src/php_excel-0.9.9/excel.c: In function âzim_ExcelSheet_delNamedRangeâ:
/usr/src/php_excel-0.9.9/excel.c:3460: error: too few arguments to function âxlSheetDelNamedRangeAâ
/usr/src/php_excel-0.9.9/excel.c: In function âzim_ExcelSheet_getNamedRangeâ:
/usr/src/php_excel-0.9.9/excel.c:3625: error: too few arguments to function âxlSheetGetNamedRangeAâ
/usr/src/php_excel-0.9.9/excel.c: In function âzim_ExcelSheet_getIndexRangeâ:
/usr/src/php_excel-0.9.9/excel.c:3650: error: too few arguments to function âxlSheetNamedRangeAâ
make: *** [excel.lo] Error 1

What can be the cause of the problem? thanks.

Library interface changed in LibXL v.3.5.4?

I have tried to compile the head and v0.9.8 revisions against the latest version of LibXL (currently v.3.5.4.1) and in both cases I am getting errors from the compiler that indicate that the interface of the library has changed. I have tried to mess with the code to get it to compile (with apparent success), but 20% of the unit tests fail (for related or unrelated reasons). I am a little out of my depth so I will just report this and hope that someone more knowledgeable can fix this ;)

My PHP version is 3.4.16 and I am working on a Debian 6.0.8 box, although I doubt that is significant.

Here are the errors I am getting (significant ones at the end):
/usr/src/php_excel/excel.c:57: error: redeclaration of enumerator 'PICTURETYPE_PNG'
/usr/local/lib/libxl-3.5.4.1/include/enum.h:69: note: previous definition of 'PICTURETYPE_PNG' was here
/usr/src/php_excel/excel.c:57: error: redeclaration of enumerator 'PICTURETYPE_JPEG'
/usr/local/lib/libxl-3.5.4.1/include/enum.h:69: note: previous definition of 'PICTURETYPE_JPEG' was here
/usr/src/php_excel/excel.c:57: error: redeclaration of enumerator 'PICTURETYPE_WMF'
/usr/local/lib/libxl-3.5.4.1/include/enum.h:69: note: previous definition of 'PICTURETYPE_WMF' was here
/usr/src/php_excel/excel.c:57: error: redeclaration of enumerator 'PICTURETYPE_DIB'
/usr/local/lib/libxl-3.5.4.1/include/enum.h:69: note: previous definition of 'PICTURETYPE_DIB' was here
/usr/src/php_excel/excel.c:57: error: redeclaration of enumerator 'PICTURETYPE_EMF'
/usr/local/lib/libxl-3.5.4.1/include/enum.h:69: note: previous definition of 'PICTURETYPE_EMF' was here
/usr/src/php_excel/excel.c:57: error: redeclaration of enumerator 'PICTURETYPE_PICT'
/usr/local/lib/libxl-3.5.4.1/include/enum.h:70: note: previous definition of 'PICTURETYPE_PICT' was here
/usr/src/php_excel/excel.c:57: error: redeclaration of enumerator 'PICTURETYPE_TIFF'
/usr/local/lib/libxl-3.5.4.1/include/enum.h:70: note: previous definition of 'PICTURETYPE_TIFF' was here
/usr/src/php_excel/excel.c:57: error: redeclaration of enumerator 'PICTURETYPE_ERROR'
/usr/local/lib/libxl-3.5.4.1/include/enum.h:70: note: previous definition of 'PICTURETYPE_ERROR' was here
/usr/src/php_excel/excel.c: In function 'zim_ExcelSheet_setNamedRange':
/usr/src/php_excel/excel.c:3397: error: too few arguments to function 'xlSheetSetNamedRangeA'
/usr/src/php_excel/excel.c: In function 'zim_ExcelSheet_delNamedRange':
/usr/src/php_excel/excel.c:3421: error: too few arguments to function 'xlSheetDelNamedRangeA'
/usr/src/php_excel/excel.c: In function 'zim_ExcelSheet_getNamedRange':
/usr/src/php_excel/excel.c:3586: error: too few arguments to function 'xlSheetGetNamedRangeA'
/usr/src/php_excel/excel.c: In function 'zim_ExcelSheet_getIndexRange':
/usr/src/php_excel/excel.c:3611: error: too few arguments to function 'xlSheetNamedRangeA'

Regards,
Eric Ritchie.

License not working with php >5.3.6 ?!

I am having trouble with the license infos being ignored/not working with php 5.3.8 and 5.3.9

Same application with exactly same settings works fine on 5.3.6 on a different server. I cant use 5.3.6 on this server as its Centos6 other is 5.

I tested the license directly with libXL examples and its working. So it must be some strange bug with the wrapper + php version

utf8 decode / encode

I think there is a problem with die lib, i have to utf8decode my values before i send it to the sheet cell.
Otherwise there are ASCII symbols in my xlsx.

Test 25 Fails

Test 25 is expecting image indexes 0 and 1 to be returned, yet on my install (x86_64 Fedora 12 w/ php 5.3.3) and libxl 3.1.0 it returns 1 and 2.

Should the test not be checking for the returned internal image indexes but rather just the error?

Custom date format definition (wrapper to xlBookAddCustomNumFormat)

I'm using php_excel to generate excel files in an international context, and I need to generate files with various regional options, including date formats.

The default date formats of libXl are not sufficient.
I wish to be able to use an equivalent to "xlBookAddCustomNumFormat" to be able to define my own date formats.
Example of date formats I need to be able to define :
2012-01-01
2012/01/01
01/01/2012
These format should not be depend of OS settings.

ExcelSheet::writeCol() - Data type argument

Let me just point out what a pleasure it is to work with Excel documents when such a good extensions has been made! Kudos to you, Ilia!

My request is more of a "Feature request" than issue, but I'd like to see a data type argument to the mentioned method in the future.
If you think Java (were they are really strict about data types), they have a good point in that each column should only contain the same data type. This really makes good sense, because everyone know that cells in the column "Price" is numbers, and not text.

So, instead of writing every cell as ExcelSheet::write (rowNumber, columnNumber, cell, null, datatype), it would be really cool to write the whole column like so:
ExcelSheet::writeCol (column, arrayOfCells, row, format, datatype).

readRow / writeRow with null value

I am running into a possible issue either with readRow() or writeRow(), where a row read with readRow() cannot be written back with writeRow(). It occurs when one of the cells being read has a value of null. I created a reproduce xlsx file at https://drive.google.com/uc?export=download&id=0B37DKbJklxg_RkxwbEg1TlRtMG8.

In the below script, $row is read in with readRow(). $row[0] has a value of null. The writeRow call returns false because of the null in $row[0].

Is there a way that this can be handled so that rows read in like this can be written back out? Thanks for your help.

<?php
$libxl = new ExcelBook('', '', true);

$libxl->loadFile('Book1.xlsx');

$worksheet = $libxl->getSheet(0);

$row = $worksheet->readRow(1);

var_dump($row);

var_dump($worksheet->writeRow(2, $row));

Huge file - high memory usage

Hi all,
This is more of a question than an issue (but it might turn out to be an issue).

I'm seeing surprisingly large memory usage when writing Excel files (xlsx). For example I have a file now which has 3.5 million rows and about 12 columns (4 sheets, each keeps up to 1 million rows). While building the file it eats up all the 16Gb memory I have in this linux server and then when it tries to save the file then it dies - I assume due to no memory left.

I'm curious, do others see similarly large memory usage when writing huge files?
Did anybody come up with a strategy to handle this, like writing out the file sheet by sheet or something?

Thanks

Unlicensed Libxl may cause segfaults

This bug should really be documented:

If you uses an unlicensed version of LibXl (for testing reasons), you should be aware that you should not loop through all the cells in your document.

I wrote a simple code to loop through all the cells in my sheet to set a preferred width for each column, but ended up with segmentation fault every time. This is because in unlicensed versions of LibXl, the first row contains text that says the software is unlicensed. The width is infinite...So I ended up with a while(true) loop basically.

This happened because I made use of the ExcelSheet::firstCol() and lastCol() methods.

xlSheetSetPicture(2) needs offset_x / offset_y since libxl 3.1.0

From the libxl changelog:

Version 3.1.0 (2010-11-16)

  - added offset_x and offset_y parameters in Sheet::setPicture() method

This is reflected in /include/libxl/SheetA.h:

void XLAPIENTRY xlSheetSetPictureA(SheetHandle handle, int row, int col, int pictureId, double scale, int offset_x, int offset_y);
void XLAPIENTRY xlSheetSetPicture2A(SheetHandle handle, int row, int col, int pictureId, int width, int height, int offset_x, int offset_y);

However on lines 2678 and 2696 only 5 arguments are given. By adding 2 zeroes I could compile php_exec.dll without fatal errors:

xlSheetSetPicture(sheet, row, col, pic_id, scale, 0, 0);
xlSheetSetPicture2(sheet, row, col, pic_id, w, h, 0, 0);

Possible error loading a file with a long path

Hello Iliaal, Pierre and others, first of all I would like to thank you all for your time for this wonderfull library, it really rocks.
I am having an issue while trying to load a file with a long path. Tested with the same file in different paths, and it loads perfectly from a small path.
I can upload the excel file if necessary. (Its just a simple excel 2003 file with 4 records).

System Description:

  • PHP Version 5.4.0 TS,VC9 ( http://windows.php.net/download/ )
  • Windows 2003 32 bits.
  • Apache 2.2.22 (Win 32).
  • php_excel version for php 5.4, downloaded it here:

http://stackoverflow.com/questions/6008152/compiling-php-excel-and-libxl-on-windows
http://www.php.net/~pierre/

php_excel-snap-20111201-5.4-ts.zip (2011-12-02 03:00 -0800)
MD5 (php_excel-snap-20111201-5.4-ts.zip) = 46dc4d2eddcda122dbba27d78c772253

These are the tests I have done:

Works perfectly with small path:

try
{
$x = new ExcelBook();
$spathfile = "C:\tbmdproducto2_testrepetidos.xls_2012-06-12_16-51-42.xls";
$x->loadfile($spathfile);
$sheet = $x->getSheet(); //returns ExcelSheet, perfect.
$dmaxrow = $sheet->lastRow();
}

Doesnt work with long path:

try
{
$x = new ExcelBook();
$x->loadfile($spathfile);
$sheet = $x->getSheet(); //returns false
$dmaxrow = $sheet->lastRow();
}

Eclipse debug:

"$spathfile" C:\symfony_web\sfprojects\dbvui\web\uploads\TbmdProducto\tbmdproducto2_testrepetidos.xls_2012-06-12_16-57-30.xls
length 112
[0..99]
[100..111]

By the way, is it there any function inside the library to get the internal version?

Thanks in advance.

Issues compiling v0.9.1+

I can compile version 0.9.0 on Ubuntu Server 10 using these instructions. However 0.9.1 and 0.9.5 tell me the following:

$ ./configure --with-excel=../libxl-3.2.0/ --with-libdir=../libxl-3.2.0/lib
....
checking lib dir for libxl... yes, shared
checking for excel includes... not found
configure: error: Please reinstall the excel distribution

writing utf-8 produces empty cells

When writing UTF-8 text into cells with $ExcelSheet->write($rowIndex, $colIndex, $value);

you get empty rows.

example strings "čž" will not be written

Copy data/formats from one book to another

Is it possible to copy the, say first 5 rows, of a specified sheet and write it into another with the exact same output? Or do I have to manually create the format in the new sheet?

I am thinking..

$data = $sheet->readRow ( ... );
$out = $sheet->writeRow ($data);

php class name

Hi,
Is it possible to change the name of the PHP class? ($x = new XLBook(); for example...)
I have conflicts with other PHP libraries already present.
Thank you!

High memory usage when creating a 16Mb xlsx file

Hi,
I have just installed libXL 3.5.0.0 on a SUSE linux server and trying to export a dataset (150k rows x 15 columns, no formatting) and seeing very high memory usage.
This 16Mb xlsx file runs up PHP to use 3.7Gb memory.

I have head that libXL is more efficient with memory than PHP_Excel when exporting lots of data, so I hope this is just some kind of an issue and not expected behavior.

UPDATE: please ignore, after further examining my code I realized that the high memory usage is mostly coming from the preparation of the data and not from the excel export itself.

Thanks,
Zoltan

ini settings do not work with unicode characters

If your libxl credentials include unicode characters with 2 bytes they will be declined. You have to work with a quirk like this:

$xlBook = new \ExcelBook(utf8_decode(ini_get('excel.license_name')), utf8_decode(ini_get('excel.license_key')));

Problem writing more than 65536 rows in Excel 2007 mode

Hello Ilia,

I’m trying to create an Excel 2007 (.xlsx) workbook with approximately 75000 rows. I’m using version 0.9.1 of the extention and LibXL for Linux 3.2.0. Unfortunately something goes wrong. After writing 65536 rows the write-function starts at row 1 agian. I made a simple example to illustrate my problem.

$doc = new ExcelBook("Free version","testing",true); // excel_2007 = true
if ($doc) {
    $sheet = $doc->addSheet("page1");
    $row   = 1;
    while($row < 100000) {
        $sheet->write($row, 2, 'row No. '.$row.'');
        $row++;
    }
    $doc->save('test.xlsx');
} 

Do you have any clues on how to solve this problem? Is it a bug? Excel 2007 should support over 1 million rows... I hope you can help me.

Thanx,
Roderik

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.