From 5d9dac27426421e0ace11f5f482ed1d9410ad936 Mon Sep 17 00:00:00 2001 From: Johannes Mueller Date: Wed, 12 Nov 2014 10:34:30 +0100 Subject: [PATCH 01/68] updated ChangeLog --- ChangeLog | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5cb0d35..0d57e50 100644 --- a/ChangeLog +++ b/ChangeLog @@ -17,13 +17,16 @@ * Added data type argument for ExcelSheet::writeCol() (see issue #29) * Fixed bug in ExcelSheet::read() (see issue #86) * Fixed bug in ExcelBook::setDefaultFont() (see issue #66) - * Added autofit handling for ExcelBook::setColWidth() + * Added autofit support for ExcelBook::setColWidth() * Added implicit formula recognition on ExcelSheet::write() operations (prefix formula with '=') * Added multibyte support for license name and license key (see issue #60 and README) * Added default date format when writing dates * Added ExcelSheet::__construct(ExcelBook $book, $name) for customized ExcelSheets - * Updated documentation - * Fixed typo -> changed excel.ini_skip_empty to excel.skip_emtpy + * Removed final keyword for ExcelFormat::__construct(ExcelBook $book) + * Removed invalid PAPER_* constants in ExcelSheet + * Removed invalid COLOR_* constants in ExcelFormat + * Updated documentation and README + * Changed php.ini variable name: excel.ini_skip_empty --> excel.skip_emtpy [2014-06-03] - Version 1.0 * Fixed issue #63 writing for NULL values using writeRow() From 6a7dfd0f8bf840605b480a407bd87bfd5fa4aadf Mon Sep 17 00:00:00 2001 From: Johannes Mueller Date: Fri, 6 Feb 2015 10:09:29 +0100 Subject: [PATCH 02/68] added tests for ExcelBook::setLocale(), ExcelBook::save() and ExcelBook::loadFile() --- tests/087.phpt | 17 +++++++++++++++++ tests/088.phpt | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 tests/087.phpt create mode 100644 tests/088.phpt diff --git a/tests/087.phpt b/tests/087.phpt new file mode 100644 index 0000000..9a128f5 --- /dev/null +++ b/tests/087.phpt @@ -0,0 +1,17 @@ +--TEST-- +test Book::setLocale() +--SKIPIF-- + +--FILE-- +setLocale('UTF-8'); + +$sheet = $book->addSheet('Sheet1'); + +echo 'OK'; + +?> +--EXPECT-- +OK diff --git a/tests/088.phpt b/tests/088.phpt new file mode 100644 index 0000000..f411cb6 --- /dev/null +++ b/tests/088.phpt @@ -0,0 +1,34 @@ +--TEST-- +test Book::save() and Book::loadFile() +--SKIPIF-- + +--FILE-- +addSheet('Sheet1'); +$sheet->write(1, 1, 'foo'); +$book->save($tmp_filename); + +$book = new ExcelBook(); +$book->loadFile($tmp_filename); +$sheet = $book->getSheet(0); + +var_dump($sheet->read(1, 1)); + +echo 'OK'; + +?> +--CLEAN-- + +--EXPECT-- +string(3) "foo" +OK From 2f9238fb851c9cba84f07d23628cc24c6aeaed3d Mon Sep 17 00:00:00 2001 From: Johannes Mueller Date: Fri, 6 Feb 2015 10:09:49 +0100 Subject: [PATCH 03/68] added github language formatting to README --- README.markdown | 124 +++++++++++++++++++++++++----------------------- 1 file changed, 65 insertions(+), 59 deletions(-) diff --git a/README.markdown b/README.markdown index fad9908..ab093cd 100644 --- a/README.markdown +++ b/README.markdown @@ -20,67 +20,71 @@ Please see the ```docs/``` and the ```tests/``` directory. ### 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 - - // rebuild configure - ./buildconf --force - - // replace with the file path to the extracted libxl files - // on a 32-bit platform use - ./configure --with-excel --with-libxl-incdir=/libxl-3.6.0.1/include_c --with-libxl-libdir=/libxl-3.6.0.1/lib - - // on a 64-bit platform use - ./configure --with-excel --with-libxl-incdir=/libxl-3.6.0.1/include_c --with-libxl-libdir=/libxl-3.6.0.1/lib64 +``` shell +# 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 + +# rebuild configure +./buildconf --force + +# replace with the file path to the extracted libxl files +# on a 32-bit platform use +./configure --with-excel --with-libxl-incdir=/libxl-3.6.0.1/include_c --with-libxl-libdir=/libxl-3.6.0.1/lib + +# on a 64-bit platform use +./configure --with-excel --with-libxl-incdir=/libxl-3.6.0.1/include_c --with-libxl-libdir=/libxl-3.6.0.1/lib64 +``` + ### Windows Pre-build packages for Windows can be downloaded [here](http://windows.php.net/downloads/pecl/snaps/excel). ## Getting started - ', '', $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'); +``` php +', '', $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 @@ -88,11 +92,13 @@ To prevent unvealing your credentials in your code you can save them in your php 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="" - excel.license_key="" - excel.skip_empty=0 +``` ini +; optional settings for excel extension +[excel] +excel.license_name="" +excel.license_key="" +excel.skip_empty=0 +``` ## Known Issues From 200be96bd61ccc3e325f7ab7368798aef1db4918 Mon Sep 17 00:00:00 2001 From: Johannes Mueller Date: Fri, 6 Feb 2015 10:16:56 +0100 Subject: [PATCH 04/68] added ./libxl/ sub dir to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index ffd5744..66f52a1 100644 --- a/.gitignore +++ b/.gitignore @@ -64,3 +64,4 @@ tests/*/*/*.diff tests/*/*/*.php tests/*/*/*.exp tmp-php.ini +libxl/* From e830fb33bf58b7b965afafa1d15a6347ce39962c Mon Sep 17 00:00:00 2001 From: Johannes Mueller Date: Fri, 6 Feb 2015 10:34:22 +0100 Subject: [PATCH 05/68] added PHP warnings on read/write errors --- ChangeLog | 1 + excel.c | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 7d53414..690c1c4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -23,6 +23,7 @@ * Added multibyte support for license name and license key (see issue #60 and README) * Added default date format when writing dates * Added ExcelSheet::__construct(ExcelBook $book, $name) for customized ExcelSheets + * Added warnings on read/write errors * Removed final keyword for ExcelFormat::__construct(ExcelBook $book) * Removed invalid PAPER_* constants in ExcelSheet * Removed invalid COLOR_* constants in ExcelFormat diff --git a/excel.c b/excel.c index 79d73e8..a4e2c5a 100644 --- a/excel.c +++ b/excel.c @@ -2251,6 +2251,7 @@ EXCEL_METHOD(Sheet, readRow) if (!php_excel_read_cell(row, lc, value, sheet, book, &format, read_formula)) { zval_ptr_dtor(&value); zval_dtor(return_value); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to read cell in row %d, column %d with error '%s'", row, lc, xlBookErrorMessage(book)); RETURN_FALSE; } else { add_next_index_zval(return_value, value); @@ -2311,6 +2312,7 @@ EXCEL_METHOD(Sheet, readCol) if (!php_excel_read_cell(lc, col, value, sheet, book, &format, read_formula)) { zval_ptr_dtor(&value); zval_dtor(return_value); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to read cell in row %d, column %d with error '%s'", lc, col, xlBookErrorMessage(book)); RETURN_FALSE; } else { add_next_index_zval(return_value, value); @@ -2345,6 +2347,7 @@ EXCEL_METHOD(Sheet, read) } if (!php_excel_read_cell(row, col, return_value, sheet, book, &format, read_formula)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to read cell in row %d, column %d with error '%s'", row, col, xlBookErrorMessage(book)); RETURN_FALSE; } @@ -2447,7 +2450,12 @@ EXCEL_METHOD(Sheet, write) FORMAT_FROM_OBJECT(format, oformat); } - RETURN_BOOL(php_excel_write_cell(sheet, book, row, col, data, oformat ? format : 0, dtype TSRMLS_CC)); + if (!php_excel_write_cell(sheet, book, row, col, data, oformat ? format : 0, dtype TSRMLS_CC)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to write cell in row %d, column %d with error '%s'", row, col, xlBookErrorMessage(book)); + RETURN_FALSE; + } + + RETURN_TRUE; } /* }}} */ @@ -2492,6 +2500,7 @@ EXCEL_METHOD(Sheet, writeRow) zend_hash_move_forward_ex(Z_ARRVAL_P(data), &pos)) { if (!php_excel_write_cell(sheet, book, row, i++, *element, oformat ? format : 0, -1 TSRMLS_CC)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to write cell in row %d, column %d with error '%s'", row, i-1, xlBookErrorMessage(book)); RETURN_FALSE; } } @@ -2542,6 +2551,7 @@ EXCEL_METHOD(Sheet, writeCol) zend_hash_move_forward_ex(Z_ARRVAL_P(data), &pos)) { if (!php_excel_write_cell(sheet, book, i++, col, *element, oformat ? format : 0, dtype TSRMLS_CC)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to write cell in row %d, column %d with error '%s'", i-1, col, xlBookErrorMessage(book)); RETURN_FALSE; } } From aaea6f9dae5ea8d2af1272e2788bd038de9fffd0 Mon Sep 17 00:00:00 2001 From: Johannes Mueller Date: Fri, 6 Feb 2015 10:35:31 +0100 Subject: [PATCH 06/68] changed formatting: removed double spaces and replaced with in pre-compiler definitions --- excel.c | 324 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 162 insertions(+), 162 deletions(-) diff --git a/excel.c b/excel.c index a4e2c5a..b746508 100644 --- a/excel.c +++ b/excel.c @@ -92,7 +92,7 @@ PHP_INI_END() ce.create_object = excel_object_new_ ## c_name; \ excel_ce_ ## c_name = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC); \ memcpy(&excel_object_handlers_ ## c_name, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); \ - excel_object_handlers_ ## c_name.clone_obj = clone; \ + excel_object_handlers_ ## c_name.clone_obj = clone; \ } zend_class_entry *excel_ce_book, *excel_ce_sheet, *excel_ce_format, *excel_ce_font; @@ -1466,7 +1466,7 @@ EXCEL_METHOD(Book, colorUnpack) #endif /* {{{ proto int ExcelFont::size([int size]) - Get or set the font size */ + Get or set the font size */ EXCEL_METHOD(Font, size) { zval *object = getThis(); @@ -1488,7 +1488,7 @@ EXCEL_METHOD(Font, size) /* }}} */ /* {{{ proto bool ExcelFont::italics([bool italics]) - Get or set the if italics are enabled */ + Get or set the if italics are enabled */ EXCEL_METHOD(Font, italics) { zval *object = getThis(); @@ -1510,7 +1510,7 @@ EXCEL_METHOD(Font, italics) /* }}} */ /* {{{ proto bool ExcelFont::strike([bool strike]) - Get or set the font strike-through */ + Get or set the font strike-through */ EXCEL_METHOD(Font, strike) { zval *object = getThis(); @@ -1532,7 +1532,7 @@ EXCEL_METHOD(Font, strike) /* }}} */ /* {{{ proto bool ExcelFont::bold([bool bold]) - Get or set the font bold */ + Get or set the font bold */ EXCEL_METHOD(Font, bold) { zval *object = getThis(); @@ -1554,7 +1554,7 @@ EXCEL_METHOD(Font, bold) /* }}} */ /* {{{ proto int ExcelFont::color([int color]) - Get or set the font color */ + Get or set the font color */ EXCEL_METHOD(Font, color) { zval *object = getThis(); @@ -1576,7 +1576,7 @@ EXCEL_METHOD(Font, color) /* }}} */ /* {{{ proto int ExcelFont::mode([int mode]) - Get or set the font mode */ + Get or set the font mode */ EXCEL_METHOD(Font, mode) { zval *object = getThis(); @@ -1598,7 +1598,7 @@ EXCEL_METHOD(Font, mode) /* }}} */ /* {{{ proto int ExcelFont::underline([int underline_style]) - Get or set the font underline style */ + Get or set the font underline style */ EXCEL_METHOD(Font, underline) { zval *object = getThis(); @@ -1620,7 +1620,7 @@ EXCEL_METHOD(Font, underline) /* }}} */ /* {{{ proto string ExcelFont::name([string name]) - Get or set the font name */ + Get or set the font name */ EXCEL_METHOD(Font, name) { zval *object = getThis(); @@ -1764,42 +1764,42 @@ EXCEL_METHOD(Format, getFont) } /* }}} */ -#define PHP_EXCEL_LONG_FORMAT_OPTION(func_name, write_only) \ - { \ - FormatHandle format; \ - zval *object = getThis(); \ - long data; \ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &data) == FAILURE) { \ - RETURN_FALSE; \ - } \ - FORMAT_FROM_OBJECT(format, object); \ - if (ZEND_NUM_ARGS()) { \ - xlFormatSet ## func_name (format, data); \ - } \ - if (!write_only) { \ - RETURN_LONG(xlFormat ## func_name (format)); \ - } else { \ - RETURN_TRUE; \ - } \ - } - -#define PHP_EXCEL_BOOL_FORMAT_OPTION(func_name) \ - { \ - FormatHandle format; \ - zval *object = getThis(); \ - zend_bool data; \ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &data) == FAILURE) { \ - RETURN_FALSE; \ - } \ - FORMAT_FROM_OBJECT(format, object); \ - if (ZEND_NUM_ARGS()) { \ - xlFormatSet ## func_name (format, data); \ - } \ - RETURN_BOOL(xlFormat ## func_name (format)); \ +#define PHP_EXCEL_LONG_FORMAT_OPTION(func_name, write_only) \ + { \ + FormatHandle format; \ + zval *object = getThis(); \ + long data; \ + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &data) == FAILURE) { \ + RETURN_FALSE; \ + } \ + FORMAT_FROM_OBJECT(format, object); \ + if (ZEND_NUM_ARGS()) { \ + xlFormatSet ## func_name (format, data); \ + } \ + if (!write_only) { \ + RETURN_LONG(xlFormat ## func_name (format)); \ + } else { \ + RETURN_TRUE; \ + } \ + } + +#define PHP_EXCEL_BOOL_FORMAT_OPTION(func_name) \ + { \ + FormatHandle format; \ + zval *object = getThis(); \ + zend_bool data; \ + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &data) == FAILURE) { \ + RETURN_FALSE; \ + } \ + FORMAT_FROM_OBJECT(format, object); \ + if (ZEND_NUM_ARGS()) { \ + xlFormatSet ## func_name (format, data); \ + } \ + RETURN_BOOL(xlFormat ## func_name (format)); \ } /* {{{ proto int ExcelFormat::numberFormat([int format]) - Get or set the cell number format */ + Get or set the cell number format */ EXCEL_METHOD(Format, numberFormat) { PHP_EXCEL_LONG_FORMAT_OPTION(NumFormat, 0); @@ -1807,7 +1807,7 @@ EXCEL_METHOD(Format, numberFormat) /* }}} */ /* {{{ proto int ExcelFormat::horizontalAlign([int align_mode]) - Get or set the cell horizontal alignment */ + Get or set the cell horizontal alignment */ EXCEL_METHOD(Format, horizontalAlign) { PHP_EXCEL_LONG_FORMAT_OPTION(AlignH, 0); @@ -1815,7 +1815,7 @@ EXCEL_METHOD(Format, horizontalAlign) /* }}} */ /* {{{ proto int ExcelFormat::verticalAlign([int align_mode]) - Get or set the cell vertical alignment */ + Get or set the cell vertical alignment */ EXCEL_METHOD(Format, verticalAlign) { PHP_EXCEL_LONG_FORMAT_OPTION(AlignV, 0); @@ -1823,7 +1823,7 @@ EXCEL_METHOD(Format, verticalAlign) /* }}} */ /* {{{ proto bool ExcelFormat::wrap([bool wrap]) - Get or set the cell wrapping */ + Get or set the cell wrapping */ EXCEL_METHOD(Format, wrap) { PHP_EXCEL_BOOL_FORMAT_OPTION(Wrap); @@ -1831,7 +1831,7 @@ EXCEL_METHOD(Format, wrap) /* }}} */ /* {{{ proto int ExcelFormat::rotate([int angle]) - Get or set the cell data rotation */ + Get or set the cell data rotation */ EXCEL_METHOD(Format, rotate) { FormatHandle format; @@ -1857,7 +1857,7 @@ EXCEL_METHOD(Format, rotate) /* }}} */ /* {{{ proto int ExcelFormat::indent([int indent]) - Get or set the cell text indentation level */ + Get or set the cell text indentation level */ EXCEL_METHOD(Format, indent) { FormatHandle format; @@ -2560,16 +2560,16 @@ EXCEL_METHOD(Sheet, writeCol) } /* }}} */ -#define PHP_EXCEL_SHEET_GET_BOOL_STATE(func_name) \ - { \ - SheetHandle sheet; \ - zval *object = getThis(); \ - long r, c; \ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &r, &c) == FAILURE) { \ - RETURN_FALSE; \ - } \ - SHEET_FROM_OBJECT(sheet, object); \ - RETURN_BOOL(xlSheet ## func_name (sheet, r, c)); \ +#define PHP_EXCEL_SHEET_GET_BOOL_STATE(func_name) \ + { \ + SheetHandle sheet; \ + zval *object = getThis(); \ + long r, c; \ + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &r, &c) == FAILURE) { \ + RETURN_FALSE; \ + } \ + SHEET_FROM_OBJECT(sheet, object); \ + RETURN_BOOL(xlSheet ## func_name (sheet, r, c)); \ } /* {{{ proto bool ExcelSheet::isFormula(int row, int column) @@ -2642,16 +2642,16 @@ EXCEL_METHOD(Sheet, removeCol) } /* }}} */ -#define PHP_EXCEL_SHEET_GET_DOUBLE_STATE(func_name) \ - { \ - SheetHandle sheet; \ - zval *object = getThis(); \ - long val; \ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &val) == FAILURE) { \ - RETURN_FALSE; \ - } \ - SHEET_FROM_OBJECT(sheet, object); \ - RETURN_DOUBLE(xlSheet ## func_name (sheet, val)); \ +#define PHP_EXCEL_SHEET_GET_DOUBLE_STATE(func_name) \ + { \ + SheetHandle sheet; \ + zval *object = getThis(); \ + long val; \ + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &val) == FAILURE) { \ + RETURN_FALSE; \ + } \ + SHEET_FROM_OBJECT(sheet, object); \ + RETURN_DOUBLE(xlSheet ## func_name (sheet, val)); \ } /* {{{ proto double ExcelSheet::colWidth(int column) @@ -2929,17 +2929,17 @@ EXCEL_METHOD(Sheet, addPictureDim) /* }}} */ #endif -#define PHP_EXCEL_SHEET_SET_BREAK(func_name) \ - { \ - SheetHandle sheet; \ - zval *object = getThis(); \ - long val; \ +#define PHP_EXCEL_SHEET_SET_BREAK(func_name) \ + { \ + SheetHandle sheet; \ + zval *object = getThis(); \ + long val; \ zend_bool brk; \ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lb", &val, &brk) == FAILURE) { \ - RETURN_FALSE; \ - } \ - SHEET_FROM_OBJECT(sheet, object); \ - RETURN_BOOL(xlSheet ## func_name (sheet, val, brk)); \ + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lb", &val, &brk) == FAILURE) { \ + RETURN_FALSE; \ + } \ + SHEET_FROM_OBJECT(sheet, object); \ + RETURN_BOOL(xlSheet ## func_name (sheet, val, brk)); \ } /* {{{ proto bool ExcelSheet::horPageBreak(int row, bool break) @@ -2976,17 +2976,17 @@ EXCEL_METHOD(Sheet, splitSheet) } /* }}} */ -#define PHP_EXCEL_SHEET_GROUP(func_name) \ - { \ - SheetHandle sheet; \ - zval *object = getThis(); \ - long s, e; \ +#define PHP_EXCEL_SHEET_GROUP(func_name) \ + { \ + SheetHandle sheet; \ + zval *object = getThis(); \ + long s, e; \ zend_bool brk = 0; \ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll|b", &s, &e, &brk) == FAILURE) { \ - RETURN_FALSE; \ - } \ - SHEET_FROM_OBJECT(sheet, object); \ - RETURN_BOOL(xlSheet ## func_name (sheet, s, e, brk)); \ + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll|b", &s, &e, &brk) == FAILURE) { \ + RETURN_FALSE; \ + } \ + SHEET_FROM_OBJECT(sheet, object); \ + RETURN_BOOL(xlSheet ## func_name (sheet, s, e, brk)); \ } /* {{{ proto bool ExcelSheet::groupRows(int start_row, int end_row [, bool collapse]) @@ -3046,51 +3046,51 @@ EXCEL_METHOD(Sheet, copy) #define PE_RETURN_IS_DOUBLE RETURN_DOUBLE #define PE_RETURN_IS_STRING(data) if (data) { RETURN_STRING((char *)data, 1) } else { RETURN_NULL(); } -#define PHP_EXCEL_INFO(func_name, type) \ -{ \ - SheetHandle sheet; \ - zval *object = getThis(); \ - if (ZEND_NUM_ARGS()) { \ - RETURN_FALSE; \ - } \ - SHEET_FROM_OBJECT(sheet, object); \ - PE_RETURN_ ## type (xlSheet ## func_name (sheet)); \ -} - -#define PHP_EXCEL_SET_BOOL_VAL(func_name) \ - { \ - SheetHandle sheet; \ - zval *object = getThis(); \ - zend_bool val; \ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &val) == FAILURE) { \ - RETURN_FALSE; \ - } \ - SHEET_FROM_OBJECT(sheet, object); \ - xlSheet ## func_name (sheet, val); \ - } - -#define PHP_EXCEL_SET_LONG_VAL(func_name) \ - { \ - SheetHandle sheet; \ - zval *object = getThis(); \ - long val; \ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &val) == FAILURE) { \ - RETURN_FALSE; \ - } \ - SHEET_FROM_OBJECT(sheet, object); \ - xlSheet ## func_name (sheet, val); \ - } - -#define PHP_EXCEL_SET_DOUBLE_VAL(func_name) \ - { \ - SheetHandle sheet; \ - zval *object = getThis(); \ - double val; \ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &val) == FAILURE) { \ - RETURN_FALSE; \ - } \ - SHEET_FROM_OBJECT(sheet, object); \ - xlSheet ## func_name (sheet, val); \ +#define PHP_EXCEL_INFO(func_name, type) \ +{ \ + SheetHandle sheet; \ + zval *object = getThis(); \ + if (ZEND_NUM_ARGS()) { \ + RETURN_FALSE; \ + } \ + SHEET_FROM_OBJECT(sheet, object); \ + PE_RETURN_ ## type (xlSheet ## func_name (sheet)); \ +} + +#define PHP_EXCEL_SET_BOOL_VAL(func_name) \ + { \ + SheetHandle sheet; \ + zval *object = getThis(); \ + zend_bool val; \ + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &val) == FAILURE) { \ + RETURN_FALSE; \ + } \ + SHEET_FROM_OBJECT(sheet, object); \ + xlSheet ## func_name (sheet, val); \ + } + +#define PHP_EXCEL_SET_LONG_VAL(func_name) \ + { \ + SheetHandle sheet; \ + zval *object = getThis(); \ + long val; \ + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &val) == FAILURE) { \ + RETURN_FALSE; \ + } \ + SHEET_FROM_OBJECT(sheet, object); \ + xlSheet ## func_name (sheet, val); \ + } + +#define PHP_EXCEL_SET_DOUBLE_VAL(func_name) \ + { \ + SheetHandle sheet; \ + zval *object = getThis(); \ + double val; \ + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &val) == FAILURE) { \ + RETURN_FALSE; \ + } \ + SHEET_FROM_OBJECT(sheet, object); \ + xlSheet ## func_name (sheet, val); \ } /* {{{ proto int ExcelSheet::firstRow() @@ -3371,18 +3371,18 @@ EXCEL_METHOD(Sheet, footer) } /* }}} */ -#define PHP_EXCEL_SET_HF(func_name) \ - { \ - SheetHandle sheet; \ - zval *object = getThis(); \ - char *val; \ - int val_len; \ - double margin; \ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sd", &val, &val_len, &margin) == FAILURE || val_len > 255) { \ - RETURN_FALSE; \ - } \ - SHEET_FROM_OBJECT(sheet, object); \ - RETURN_BOOL(xlSheet ## func_name (sheet, val, margin)); \ +#define PHP_EXCEL_SET_HF(func_name) \ + { \ + SheetHandle sheet; \ + zval *object = getThis(); \ + char *val; \ + int val_len; \ + double margin; \ + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sd", &val, &val_len, &margin) == FAILURE || val_len > 255) { \ + RETURN_FALSE; \ + } \ + SHEET_FROM_OBJECT(sheet, object); \ + RETURN_BOOL(xlSheet ## func_name (sheet, val, margin)); \ } /* {{{ proto bool ExcelSheet::setHeader(string header, double margin) @@ -3631,21 +3631,21 @@ EXCEL_METHOD(Sheet, delNamedRange) } /* }}} */ -#define PHP_EXCEL_SHEET_PRINT_AREA(func_name) \ - { \ - SheetHandle sheet; \ - zval *object = getThis(); \ - long s, e; \ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &s, &e) == FAILURE) { \ - RETURN_FALSE; \ - } \ - if (s > e) { \ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The range start is greater than the end."); \ - RETURN_FALSE; \ - } \ - SHEET_FROM_OBJECT(sheet, object); \ - xlSheet ## func_name (sheet, s, e); \ - RETURN_TRUE; \ +#define PHP_EXCEL_SHEET_PRINT_AREA(func_name) \ + { \ + SheetHandle sheet; \ + zval *object = getThis(); \ + long s, e; \ + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &s, &e) == FAILURE) { \ + RETURN_FALSE; \ + } \ + if (s > e) { \ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "The range start is greater than the end."); \ + RETURN_FALSE; \ + } \ + SHEET_FROM_OBJECT(sheet, object); \ + xlSheet ## func_name (sheet, s, e); \ + RETURN_TRUE; \ } /* {{{ proto bool ExcelSheet::setPrintRepeatRows(int rowFirst, int rowLast) @@ -3827,7 +3827,7 @@ EXCEL_METHOD(Sheet, getIndexRange) #if LIBXL_VERSION >= 0x03050401 int hidden; long scope_id = SCOPE_WORKBOOK; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &index, &scope_id) == FAILURE) { RETURN_FALSE; } @@ -4309,7 +4309,7 @@ EXCEL_METHOD(Sheet, hyperlink) SHEET_FROM_OBJECT(sheet, object); s = xlSheetHyperlink(sheet, index, &rowFirst, &rowLast, &colFirst, &colLast); - + if (!s) { RETURN_FALSE; } @@ -4359,7 +4359,7 @@ EXCEL_METHOD(Sheet, addHyperlink) } SHEET_FROM_OBJECT(sheet, object); - + xlSheetAddHyperlink(sheet, val, row_first, row_last, col_first, col_last); RETURN_TRUE; } From 84f1b2e01ca4fab2e1bd384d44bbd40951112ce5 Mon Sep 17 00:00:00 2001 From: Johannes Mueller Date: Fri, 6 Feb 2015 14:14:43 +0100 Subject: [PATCH 07/68] ported extension to PHP7; requires LibXL >3.6.0; removed code fallbacks for older LibXL versions and older PHP versions --- excel.c | 1484 ++++++++++++++++-------------------------------- tests/002.phpt | 2 + tests/053.phpt | 88 +-- 3 files changed, 535 insertions(+), 1039 deletions(-) diff --git a/excel.c b/excel.c index b746508..9382394 100644 --- a/excel.c +++ b/excel.c @@ -35,6 +35,16 @@ #include "php_excel.h" #include "zend_exceptions.h" +// support for LibXL v 3.6.0+ +#ifndef LIBXL_VERSION +#pragma message ("LibXL version 3.6.0+ required") +#endif + +// support for LibXL v 3.6.0+ +#if LIBXL_VERSION < 0x03060000 +#pragma message ("LibXL version 3.6.0+ required") +#endif + static long xlFormatBorder(FormatHandle f) { return 1; @@ -44,26 +54,6 @@ static long xlFormatBorderColor(FormatHandle f) return 1; } -/* work-around for missing headers in LibXL */ - -#ifndef LIBXL_VERSION - -#define xlSheetSetProtect xlSheetSetProtectA -#ifndef HAVE_LIBXL_243_PLUS -#define xlSheetProtect xlSheetProtectA -#endif - -#endif - -#if LIBXL_VERSION >= 0x03020000 -#define xlBookSetRefR1C1 xlBookSetRefR1C1A -#define xlBookRefR1C1 xlBookRefR1C1A -#endif - -#if LIBXL_VERSION >= 0x03020000 && LIBXL_VERSION < 0x03050401 -enum libXLPictureType {PICTURETYPE_PNG, PICTURETYPE_JPEG, PICTURETYPE_WMF, PICTURETYPE_DIB, PICTURETYPE_EMF, PICTURETYPE_PICT, PICTURETYPE_TIFF, PICTURETYPE_ERROR = 0xFF}; -#endif - #define PHP_EXCEL_DATE 1 #define PHP_EXCEL_FORMULA 2 #define PHP_EXCEL_NUMERIC_STRING 3 @@ -90,9 +80,11 @@ PHP_INI_END() zend_class_entry ce; \ INIT_CLASS_ENTRY(ce, "Excel" # name, excel_funcs_ ## c_name); \ ce.create_object = excel_object_new_ ## c_name; \ - excel_ce_ ## c_name = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC); \ + excel_ce_ ## c_name = zend_register_internal_class_ex(&ce, NULL); \ memcpy(&excel_object_handlers_ ## c_name, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); \ - excel_object_handlers_ ## c_name.clone_obj = clone; \ + excel_object_handlers_ ## c_name .offset = XtOffsetOf(excel_ ## c_name ## _object, std); \ + excel_object_handlers_ ## c_name .free_obj = excel_ ## c_name ## _object_free_storage; \ + excel_object_handlers_ ## c_name .clone_obj = clone; \ } zend_class_entry *excel_ce_book, *excel_ce_sheet, *excel_ce_format, *excel_ce_font; @@ -107,12 +99,18 @@ typedef struct _excel_book_object { BookHandle book; } excel_book_object; +static inline excel_book_object *php_excel_book_object_fetch_object(zend_object *obj) { + return (excel_book_object *)((char *)(obj) - XtOffsetOf(excel_book_object, std)); +} + +#define Z_EXCEL_BOOK_OBJ_P(zv) php_excel_book_object_fetch_object(Z_OBJ_P(zv)); + #define BOOK_FROM_OBJECT(book, object) \ { \ - excel_book_object *obj = (excel_book_object*) zend_object_store_get_object(object TSRMLS_CC); \ + excel_book_object *obj = Z_EXCEL_BOOK_OBJ_P(object); \ book = obj->book; \ if (!book) { \ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The book wasn't initialized"); \ + php_error_docref(NULL, E_WARNING, "The book wasn't initialized"); \ RETURN_FALSE; \ } \ } @@ -123,49 +121,60 @@ typedef struct _excel_sheet_object { BookHandle book; } excel_sheet_object; +static inline excel_sheet_object *php_excel_sheet_object_fetch_object(zend_object *obj) { + return (excel_sheet_object *)((char *)(obj) - XtOffsetOf(excel_sheet_object, std)); +} + +#define Z_EXCEL_SHEET_OBJ_P(zv) php_excel_sheet_object_fetch_object(Z_OBJ_P(zv)); + #define SHEET_FROM_OBJECT(sheet, object) \ { \ - excel_sheet_object *obj = (excel_sheet_object*) zend_object_store_get_object(object TSRMLS_CC); \ + excel_sheet_object *obj = Z_EXCEL_SHEET_OBJ_P(object); \ sheet = obj->sheet; \ if (!sheet) { \ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The sheet wasn't initialized"); \ + php_error_docref(NULL, E_WARNING, "The sheet wasn't initialized"); \ RETURN_FALSE; \ } \ } #define SHEET_AND_BOOK_FROM_OBJECT(sheet, book, object) \ { \ - excel_sheet_object *obj = (excel_sheet_object*) zend_object_store_get_object(object TSRMLS_CC); \ + excel_sheet_object *obj = Z_EXCEL_SHEET_OBJ_P(object); \ sheet = obj->sheet; \ book = obj->book; \ if (!sheet) { \ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The sheet wasn't initialized"); \ + php_error_docref(NULL, E_WARNING, "The sheet wasn't initialized"); \ RETURN_FALSE; \ } \ } +typedef struct _excel_font_object { + zend_object std; + FontHandle font; + BookHandle book; +} excel_font_object; + +static inline excel_font_object *php_excel_font_object_fetch_object(zend_object *obj) { + return (excel_font_object *)((char *)(obj) - XtOffsetOf(excel_font_object, std)); +} +#define Z_EXCEL_FONT_OBJ_P(zv) php_excel_font_object_fetch_object(Z_OBJ_P(zv)); + #define FONT_FROM_OBJECT(font, object) \ { \ - excel_font_object *obj = (excel_font_object*) zend_object_store_get_object(object TSRMLS_CC); \ + excel_font_object *obj = Z_EXCEL_FONT_OBJ_P(object); \ font = obj->font; \ if (!font) { \ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The font wasn't initialized"); \ + php_error_docref(NULL, E_WARNING, "The font wasn't initialized"); \ RETURN_FALSE; \ } \ } -typedef struct _excel_font_object { - zend_object std; - FontHandle font; - BookHandle book; -} excel_font_object; - #define FORMAT_FROM_OBJECT(format, object) \ { \ - excel_format_object *obj = (excel_format_object*) zend_object_store_get_object(object TSRMLS_CC); \ + excel_format_object *obj = Z_EXCEL_FORMAT_OBJ_P(object); \ format = obj->format; \ if (!format) { \ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The format wasn't initialized"); \ + php_error_docref(NULL, E_WARNING, "The format wasn't initialized"); \ RETURN_FALSE; \ } \ } @@ -176,214 +185,170 @@ typedef struct _excel_format_object { BookHandle book; } excel_format_object; -static void excel_book_object_free_storage(void *object TSRMLS_DC) -{ - excel_book_object *intern = (excel_book_object *)object; +static inline excel_format_object *php_excel_format_object_fetch_object(zend_object *obj) { + return (excel_format_object *)((char *)(obj) - XtOffsetOf(excel_format_object, std)); +} +#define Z_EXCEL_FORMAT_OBJ_P(zv) php_excel_format_object_fetch_object(Z_OBJ_P(zv)); - zend_object_std_dtor(&intern->std TSRMLS_CC); +static void excel_book_object_free_storage(zend_object *object) +{ + excel_book_object *intern = php_excel_book_object_fetch_object(object); + zend_object_std_dtor(&intern->std); if (intern->book) { xlBookRelease(intern->book); intern->book = NULL; } - - efree(object); } -static zend_object_value excel_object_new_book(zend_class_entry *class_type TSRMLS_DC) +static zend_object *excel_object_new_book(zend_class_entry *class_type) { excel_book_object *intern; - zend_object_value retval; - intern = emalloc(sizeof(excel_book_object)); - memset(intern, 0, sizeof(excel_book_object)); + intern = ecalloc(1, + sizeof(excel_book_object) + + sizeof(zval) * (class_type->default_properties_count - 1)); - zend_object_std_init(&intern->std, class_type TSRMLS_CC); -#ifdef ZEND_ENGINE_2_4 + zend_object_std_init(&intern->std, class_type); object_properties_init(&intern->std, class_type); -#else -{ - zval *tmp; - zend_hash_copy(intern->std.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); -} -#endif - intern->book = xlCreateBook(); - (&retval)->handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t) excel_book_object_free_storage, NULL TSRMLS_CC); - (&retval)->handlers = &excel_object_handlers_book; + intern->book = xlCreateBook(); + intern->std.handlers = &excel_object_handlers_book; - return retval; + return &intern->std; } -static void excel_sheet_object_free_storage(void *object TSRMLS_DC) +static void excel_sheet_object_free_storage(zend_object *object) { - excel_sheet_object *intern = (excel_sheet_object *)object; - - zend_object_std_dtor(&intern->std TSRMLS_CC); - - efree(object); + excel_sheet_object *intern = php_excel_sheet_object_fetch_object(object); + zend_object_std_dtor(&intern->std); } -static zend_object_value excel_object_new_sheet(zend_class_entry *class_type TSRMLS_DC) +static zend_object *excel_object_new_sheet(zend_class_entry *class_type) { excel_sheet_object *intern; - zend_object_value retval; - intern = emalloc(sizeof(excel_sheet_object)); - memset(intern, 0, sizeof(excel_sheet_object)); - zend_object_std_init(&intern->std, class_type TSRMLS_CC); -#ifdef ZEND_ENGINE_2_4 + intern = ecalloc(1, + sizeof(excel_sheet_object) + + sizeof(zval) * (class_type->default_properties_count - 1)); + + zend_object_std_init(&intern->std, class_type); object_properties_init(&intern->std, class_type); -#else - { - zval *tmp; - zend_hash_copy(intern->std.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - } -#endif - (&retval)->handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t) excel_sheet_object_free_storage, NULL TSRMLS_CC); - (&retval)->handlers = &excel_object_handlers_sheet; - return retval; + intern->std.handlers = &excel_object_handlers_sheet; + + return &intern->std; } -static void excel_font_object_free_storage(void *object TSRMLS_DC) +static void excel_font_object_free_storage(zend_object *object) { - excel_font_object *intern = (excel_font_object *)object; - - zend_object_std_dtor(&intern->std TSRMLS_CC); - - efree(object); + excel_font_object *intern = php_excel_font_object_fetch_object(object); + zend_object_std_dtor(&intern->std); } #define REGISTER_EXCEL_CLASS_CONST_LONG(class_name, const_name, value) \ - zend_declare_class_constant_long(excel_ce_ ## class_name, const_name, sizeof(const_name)-1, (long)value TSRMLS_CC); + zend_declare_class_constant_long(excel_ce_ ## class_name, const_name, sizeof(const_name)-1, (long)value); -static zend_object_value excel_object_new_font_ex(zend_class_entry *class_type, excel_font_object **ptr TSRMLS_DC) +static zend_object *excel_object_new_font_ex(zend_class_entry *class_type, excel_font_object **ptr) { excel_font_object *intern; - zend_object_value retval; - intern = emalloc(sizeof(excel_font_object)); - memset(intern, 0, sizeof(excel_font_object)); + intern = ecalloc(1, + sizeof(excel_font_object) + + sizeof(zval) * (class_type->default_properties_count - 1)); + if (ptr) { *ptr = intern; } - zend_object_std_init(&intern->std, class_type TSRMLS_CC); -#ifdef ZEND_ENGINE_2_4 + zend_object_std_init(&intern->std, class_type); object_properties_init(&intern->std, class_type); -#else - { - zval *tmp; - zend_hash_copy(intern->std.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - } -#endif - (&retval)->handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t) excel_font_object_free_storage, NULL TSRMLS_CC); - (&retval)->handlers = &excel_object_handlers_font; - return retval; + intern->std.handlers = &excel_object_handlers_font; + + return &intern->std; } -static zend_object_value excel_object_new_font(zend_class_entry *class_type TSRMLS_DC) +static zend_object *excel_object_new_font(zend_class_entry *class_type) { - return excel_object_new_font_ex(class_type, NULL TSRMLS_CC); + return excel_object_new_font_ex(class_type, NULL); } -static zend_object_value excel_font_object_clone(zval *this_ptr TSRMLS_DC) +static zend_object *excel_font_object_clone(zval *this_ptr) { - excel_font_object *new_obj = NULL; - excel_font_object *old_obj = (excel_font_object *) zend_object_store_get_object(this_ptr TSRMLS_CC); - zend_object_value new_ov = excel_object_new_font_ex(old_obj->std.ce, &new_obj TSRMLS_CC); + zend_object *new_ov; FontHandle font; + excel_font_object *new_obj = NULL; + excel_font_object *old_obj = Z_EXCEL_FONT_OBJ_P(this_ptr); + new_ov = excel_object_new_font_ex(old_obj->std.ce, &new_obj); + font = xlBookAddFont(old_obj->book, old_obj->font); if (!font) { - zend_throw_exception(NULL, "Failed to copy font", 0 TSRMLS_CC); + zend_throw_exception(NULL, "Failed to copy font", 0); } else { new_obj->book = old_obj->book; new_obj->font = font; } - zend_objects_clone_members(&new_obj->std, new_ov, &old_obj->std, Z_OBJ_HANDLE_P(this_ptr) TSRMLS_CC); + zend_objects_clone_members(&new_obj->std, &old_obj->std); return new_ov; } -static void excel_format_object_free_storage(void *object TSRMLS_DC) +static void excel_format_object_free_storage(zend_object *object) { - excel_format_object *intern = (excel_format_object *)object; - - zend_object_std_dtor(&intern->std TSRMLS_CC); - - efree(object); + excel_format_object *intern = php_excel_format_object_fetch_object(object); + zend_object_std_dtor(&intern->std); } -static zend_object_value excel_object_new_format_ex(zend_class_entry *class_type, excel_format_object **ptr TSRMLS_DC) +static zend_object *excel_object_new_format_ex(zend_class_entry *class_type, excel_format_object **ptr) { excel_format_object *intern; - zend_object_value retval; - intern = emalloc(sizeof(excel_format_object)); - memset(intern, 0, sizeof(excel_format_object)); + intern = ecalloc(1, + sizeof(excel_format_object) + + sizeof(zval) * (class_type->default_properties_count - 1)); + if (ptr) { *ptr = intern; } - zend_object_std_init(&intern->std, class_type TSRMLS_CC); -#ifdef ZEND_ENGINE_2_4 + zend_object_std_init(&intern->std, class_type); object_properties_init(&intern->std, class_type); -#else - { - zval *tmp; - zend_hash_copy(intern->std.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - } -#endif - (&retval)->handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t) excel_format_object_free_storage, NULL TSRMLS_CC); - (&retval)->handlers = &excel_object_handlers_format; - return retval; + intern->std.handlers = &excel_object_handlers_format; + + return &intern->std; } -static zend_object_value excel_object_new_format(zend_class_entry *class_type TSRMLS_DC) +static zend_object *excel_object_new_format(zend_class_entry *class_type) { - return excel_object_new_format_ex(class_type, NULL TSRMLS_CC); + return excel_object_new_format_ex(class_type, NULL); } -static zend_object_value excel_format_object_clone(zval *this_ptr TSRMLS_DC) +static zend_object *excel_format_object_clone(zval *this_ptr) { - excel_format_object *new_obj = NULL; - excel_format_object *old_obj = (excel_format_object *) zend_object_store_get_object(this_ptr TSRMLS_CC); - zend_object_value new_ov = excel_object_new_format_ex(old_obj->std.ce, &new_obj TSRMLS_CC); + zend_object *new_ov; FormatHandle format; + excel_format_object *new_obj = NULL; + excel_format_object *old_obj = Z_EXCEL_FORMAT_OBJ_P(this_ptr); + new_ov = excel_object_new_format_ex(old_obj->std.ce, &new_obj); + format = xlBookAddFormat(old_obj->book, old_obj->format); if (!format) { - zend_throw_exception(NULL, "Failed to copy format", 0 TSRMLS_CC); + zend_throw_exception(NULL, "Failed to copy format", 0); } else { new_obj->book = old_obj->book; new_obj->format = format; } - zend_objects_clone_members(&new_obj->std, new_ov, &old_obj->std, Z_OBJ_HANDLE_P(this_ptr) TSRMLS_CC); + zend_objects_clone_members(&new_obj->std, &old_obj->std); return new_ov; } -#if LIBXL_VERSION <= 0x03010000 -static wchar_t * _php_excel_to_wide(const char *string, size_t len, size_t *out_len) -{ - wchar_t *buf = safe_emalloc(len, sizeof(wchar_t), 0); - - *out_len = mbstowcs(buf, string, len); - if (*out_len == (size_t) -1) { - efree(buf); - return NULL; - } - - return erealloc(buf, (*out_len + 1) * sizeof(wchar_t)); -} -#endif - #define EXCEL_METHOD(class_name, function_name) \ PHP_METHOD(Excel ## class_name, function_name) @@ -393,20 +358,19 @@ EXCEL_METHOD(Book, load) { BookHandle book; zval *object = getThis(); - char *data; - int data_len; + zend_string *data_zs = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &data, &data_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &data_zs) == FAILURE) { RETURN_FALSE; } - if (!data_len) { + if (!data_zs || data_zs->len < 1) { RETURN_FALSE; } BOOK_FROM_OBJECT(book, object); - RETURN_BOOL(xlBookLoadRaw(book, data, data_len)); + RETURN_BOOL(xlBookLoadRaw(book, data_zs->val, data_zs->len)); } /* }}} */ @@ -416,36 +380,36 @@ EXCEL_METHOD(Book, loadFile) { BookHandle book; zval *object = getThis(); - char *filename; - int filename_len; + zend_string *filename_zs = NULL; php_stream *stream; - int len; - char *contents; + zend_string *contents; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &filename_zs) == FAILURE) { RETURN_FALSE; } - if (!filename_len) { + if (!filename_zs || filename_zs->len < 1) { RETURN_FALSE; } BOOK_FROM_OBJECT(book, object); - stream = php_stream_open_wrapper(filename, "rb", ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL); + stream = php_stream_open_wrapper(filename_zs->val, "rb", ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL); + if (!stream) { RETURN_FALSE; } - len = php_stream_copy_to_mem(stream, &contents, PHP_STREAM_COPY_ALL, 0); + contents = php_stream_copy_to_mem(stream, PHP_STREAM_COPY_ALL, 0); php_stream_close(stream); - if (len < 1) { + if (!contents || contents->len < 1) { + zend_string_release(contents); RETURN_FALSE; } - RETVAL_BOOL(xlBookLoadRaw(book, contents, len)); - efree(contents); + RETVAL_BOOL(xlBookLoadRaw(book, contents->val, contents->len)); + zend_string_release(contents); } /* }}} */ @@ -455,38 +419,38 @@ EXCEL_METHOD(Book, save) { BookHandle book; zval *object = getThis(); - char *filename = NULL; - int filename_len; + zend_string *filename_zs = NULL; unsigned int len = 0; char *contents = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &filename, &filename_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|S", &filename_zs) == FAILURE) { RETURN_FALSE; } BOOK_FROM_OBJECT(book, object); - if (!xlBookSaveRaw(book, (const char **)&contents, &len)) { + if (!xlBookSaveRaw(book, (const char **) &contents, &len)) { RETURN_FALSE; } - if (filename) { + if (filename_zs && filename_zs->len > 0) { int numbytes; - php_stream *stream = php_stream_open_wrapper(filename, "wb", ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL); + php_stream *stream = php_stream_open_wrapper(filename_zs->val, "wb", ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL); if (!stream) { RETURN_FALSE; } if ((numbytes = php_stream_write(stream, contents, len)) != len) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Only %d of %d bytes written, possibly out of free disk space", numbytes, len); + php_error_docref(NULL, E_WARNING, "Only %d of %d bytes written, possibly out of free disk space", numbytes, len); + php_stream_close(stream); RETURN_FALSE; } php_stream_close(stream); RETURN_TRUE; } else { - RETURN_STRINGL(contents, len, 1); + RETURN_STRINGL(contents, len); } } @@ -502,7 +466,7 @@ EXCEL_METHOD(Book, getSheet) SheetHandle sh; excel_sheet_object *fo; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &sheet) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &sheet) == FAILURE) { RETURN_FALSE; } @@ -516,11 +480,8 @@ EXCEL_METHOD(Book, getSheet) RETURN_FALSE; } - Z_TYPE_P(return_value) = IS_OBJECT; - object_init_ex(return_value, excel_ce_sheet); - Z_SET_REFCOUNT_P(return_value, 1); - Z_SET_ISREF_P(return_value); - fo = (excel_sheet_object *) zend_object_store_get_object(return_value TSRMLS_CC); + ZVAL_OBJ(return_value, excel_object_new_sheet(excel_ce_sheet)); + fo = Z_EXCEL_SHEET_OBJ_P(return_value); fo->sheet = sh; fo->book = book; } @@ -532,19 +493,18 @@ EXCEL_METHOD(Book, getSheetByName) { BookHandle book; zval *object = getThis(); - char *sheet_name; - int sheet_name_len; + zend_string *sheet_name_zs = NULL; long sheet; excel_sheet_object *fo; long sheet_count; zend_bool case_s = 0; const char *s; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &sheet_name, &sheet_name_len, &case_s) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|b", &sheet_name_zs, &case_s) == FAILURE) { RETURN_FALSE; } - if (sheet_name_len == 0) { + if (!sheet_name_zs || sheet_name_zs->len < 1) { RETURN_FALSE; } @@ -556,15 +516,11 @@ EXCEL_METHOD(Book, getSheetByName) if (sh) { s = xlSheetName(sh); if (s) { - if ((case_s && !strcasecmp(s, sheet_name)) || (!case_s && !strcmp(s, sheet_name))) { - Z_TYPE_P(return_value) = IS_OBJECT; - object_init_ex(return_value, excel_ce_sheet); - Z_SET_REFCOUNT_P(return_value, 1); - Z_SET_ISREF_P(return_value); - fo = (excel_sheet_object *) zend_object_store_get_object(return_value TSRMLS_CC); + if ((case_s && !strcasecmp(s, sheet_name_zs->val)) || (!case_s && !strcmp(s, sheet_name_zs->val))) { + ZVAL_OBJ(return_value, excel_object_new_sheet(excel_ce_sheet)); + fo = Z_EXCEL_SHEET_OBJ_P(return_value); fo->sheet = sh; fo->book = book; - return; } } @@ -583,7 +539,7 @@ EXCEL_METHOD(Book, deleteSheet) zval *object = getThis(); long sheet; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &sheet) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &sheet) == FAILURE) { RETURN_FALSE; } @@ -606,7 +562,7 @@ EXCEL_METHOD(Book, activeSheet) long sheet = -1; long res; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &sheet) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &sheet) == FAILURE) { RETURN_FALSE; } @@ -633,30 +589,25 @@ EXCEL_METHOD(Book, addSheet) zval *object = getThis(); SheetHandle sh; excel_sheet_object *fo; - char *name; - int name_len; + zend_string *name_zs = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &name_zs) == FAILURE) { RETURN_FALSE; } - BOOK_FROM_OBJECT(book, object); + if (!name_zs || name_zs->len < 1) { + RETURN_FALSE; + } -#ifdef LIBXL_VERSION - sh = xlBookAddSheet(book, name, 0); -#else - sh = xlBookAddSheet(book, name); -#endif + BOOK_FROM_OBJECT(book, object); + sh = xlBookAddSheet(book, name_zs->val, 0); if (!sh) { RETURN_FALSE; } - Z_TYPE_P(return_value) = IS_OBJECT; - object_init_ex(return_value, excel_ce_sheet); - Z_SET_REFCOUNT_P(return_value, 1); - Z_SET_ISREF_P(return_value); - fo = (excel_sheet_object *) zend_object_store_get_object(return_value TSRMLS_CC); + ZVAL_OBJ(return_value, excel_object_new_sheet(excel_ce_sheet)); + fo = Z_EXCEL_SHEET_OBJ_P(return_value); fo->sheet = sh; fo->book = book; } @@ -670,14 +621,11 @@ EXCEL_METHOD(Book, copySheet) zval *object = getThis(); SheetHandle sh; excel_sheet_object *fo; - char *name; - int name_len; + zend_string *name_zs = NULL; long num; -#ifdef LIBXL_VERSION SheetHandle osh; -#endif - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl", &name, &name_len, &num) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sl", &name_zs, &num) == FAILURE) { RETURN_FALSE; } @@ -685,26 +633,23 @@ EXCEL_METHOD(Book, copySheet) RETURN_FALSE; } + if (!name_zs || name_zs->len < 1) { + RETURN_FALSE; + } + BOOK_FROM_OBJECT(book, object); -#ifdef LIBXL_VERSION if (!(osh = xlBookGetSheet(book, num))) { RETURN_FALSE; } - sh = xlBookAddSheet(book, name, osh); -#else - sh = xlBookCopySheet(book, name, num); -#endif + sh = xlBookAddSheet(book, name_zs->val, osh); if (!sh) { RETURN_FALSE; } - Z_TYPE_P(return_value) = IS_OBJECT; - object_init_ex(return_value, excel_ce_sheet); - Z_SET_REFCOUNT_P(return_value, 1); - Z_SET_ISREF_P(return_value); - fo = (excel_sheet_object *) zend_object_store_get_object(return_value TSRMLS_CC); + ZVAL_OBJ(return_value, excel_object_new_sheet(excel_ce_sheet)); + fo = Z_EXCEL_SHEET_OBJ_P(return_value); fo->sheet = sh; fo->book = book; } @@ -746,10 +691,10 @@ EXCEL_METHOD(Book, getError) if (!strcmp(err, "ok")) { RETURN_FALSE; } else { - RETURN_STRING(err, 1); + RETURN_STRING(err); } } else { - RETURN_STRING("Unknown Error", 1); + RETURN_STRING("Unknown Error"); } } /* }}} */ @@ -765,7 +710,7 @@ EXCEL_METHOD(Book, addFont) excel_font_object *fo; zval *fob = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|O", &fob, excel_ce_font) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|O", &fob, excel_ce_font) == FAILURE) { RETURN_FALSE; } @@ -779,11 +724,8 @@ EXCEL_METHOD(Book, addFont) RETURN_FALSE; } - Z_TYPE_P(return_value) = IS_OBJECT; - object_init_ex(return_value, excel_ce_font); - Z_SET_REFCOUNT_P(return_value, 1); - Z_SET_ISREF_P(return_value); - fo = (excel_font_object *) zend_object_store_get_object(return_value TSRMLS_CC); + ZVAL_OBJ(return_value, excel_object_new_font(excel_ce_font)); + fo = Z_EXCEL_FONT_OBJ_P(return_value); fo->font = nfont; fo->book = book; } @@ -800,7 +742,7 @@ EXCEL_METHOD(Book, addFormat) excel_format_object *fo; zval *fob = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|O", &fob, excel_ce_format) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|O", &fob, excel_ce_format) == FAILURE) { RETURN_FALSE; } @@ -814,17 +756,13 @@ EXCEL_METHOD(Book, addFormat) RETURN_FALSE; } - Z_TYPE_P(return_value) = IS_OBJECT; - object_init_ex(return_value, excel_ce_format); - Z_SET_REFCOUNT_P(return_value, 1); - Z_SET_ISREF_P(return_value); - fo = (excel_format_object *) zend_object_store_get_object(return_value TSRMLS_CC); + ZVAL_OBJ(return_value, excel_object_new_format(excel_ce_format)); + fo = Z_EXCEL_FORMAT_OBJ_P(return_value); fo->format = nformat; fo->book = book; } /* }}} */ -#ifdef HAVE_LIBXL_243_PLUS /* {{{ proto array ExcelBook::getAllFormats() Get an array of all ExcelFormat objects used inside a document. */ EXCEL_METHOD(Book, getAllFormats) @@ -852,23 +790,18 @@ EXCEL_METHOD(Book, getAllFormats) if ((format = xlBookFormat(book, c))) { excel_format_object *fo; - zval *value; - - MAKE_STD_ZVAL(value); - Z_TYPE_P(value) = IS_OBJECT; - object_init_ex(value, excel_ce_format); - Z_SET_REFCOUNT_P(value, 1); - Z_SET_ISREF_P(value); - fo = (excel_format_object *) zend_object_store_get_object(value TSRMLS_CC); + zval value; + + ZVAL_OBJ(&value, excel_object_new_format(excel_ce_format)); + fo = Z_EXCEL_FORMAT_OBJ_P(&value); fo->format = format; fo->book = book; - add_next_index_zval(return_value, value); + add_next_index_zval(return_value, &value); } } } /* }}} */ -#endif /* {{{ proto int ExcelBook::addCustomFormat(string format) Create a custom cell format */ @@ -876,21 +809,20 @@ EXCEL_METHOD(Book, addCustomFormat) { BookHandle book; zval *object = getThis(); - char *format; - int format_len; + zend_string *format_zs = NULL; int id; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &format, &format_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &format_zs) == FAILURE) { RETURN_FALSE; } - if (!format_len) { + if (!format_zs || format_zs->len < 1) { RETURN_FALSE; } BOOK_FROM_OBJECT(book, object); - if (!(id = xlBookAddCustomNumFormat(book, format))) { + if (!(id = xlBookAddCustomNumFormat(book, format_zs->val))) { RETURN_FALSE; } RETURN_LONG(id); @@ -906,7 +838,7 @@ EXCEL_METHOD(Book, getCustomFormat) long id; char *data; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &id) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &id) == FAILURE) { RETURN_FALSE; } @@ -919,7 +851,7 @@ EXCEL_METHOD(Book, getCustomFormat) if (!(data = (char *)xlBookCustomNumFormat(book, id))) { RETURN_FALSE; } - RETURN_STRING(data, 1); + RETURN_STRING(data); } /* }}} */ @@ -934,11 +866,7 @@ static double _php_excel_date_pack(BookHandle book, long ts) tm.tm_year += 1900; tm.tm_mon += 1; - return xlBookDatePack(book, tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec -#ifdef HAVE_LIBXL_243_PLUS - , 0 -#endif - ); + return xlBookDatePack(book, tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, 0); } /* {{{ proto float ExcelBook::packDate(int timestamp) @@ -950,7 +878,7 @@ EXCEL_METHOD(Book, packDate) long ts; double dt; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &ts) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &ts) == FAILURE) { RETURN_FALSE; } @@ -969,11 +897,7 @@ EXCEL_METHOD(Book, packDate) static double _php_excel_date_pack_values(BookHandle book, int year, int month, int day, int hour, int min, int sec) { - return xlBookDatePack(book, year, month, day, hour, min, sec -#ifdef HAVE_LIBXL_243_PLUS - , 0 -#endif - ); + return xlBookDatePack(book, year, month, day, hour, min, sec, 0); } /* {{{ proto float ExcelBook::packDateValues(int year, int month, int day, int hour, int minute, int second) @@ -985,27 +909,27 @@ EXCEL_METHOD(Book, packDateValues) long year, month, day, hour, min, sec; double dt; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llllll", &year, &month, &day, &hour, &min, &sec) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "llllll", &year, &month, &day, &hour, &min, &sec) == FAILURE) { RETURN_FALSE; } if (year < 1) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid '%ld' value for year", year); + php_error_docref(NULL, E_WARNING, "Invalid '%ld' value for year", year); RETURN_FALSE; } else if (month < 1 || month > 12) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid '%ld' value for month", month); + php_error_docref(NULL, E_WARNING, "Invalid '%ld' value for month", month); RETURN_FALSE; } else if (day < 1 || day > 31) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid '%ld' value for day", day); + php_error_docref(NULL, E_WARNING, "Invalid '%ld' value for day", day); RETURN_FALSE; } else if (hour < 0 || hour > 23) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid '%ld' value for hour", hour); + php_error_docref(NULL, E_WARNING, "Invalid '%ld' value for hour", hour); RETURN_FALSE; } else if (min < 0 || min > 59) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid '%ld' value for minute", min); + php_error_docref(NULL, E_WARNING, "Invalid '%ld' value for minute", min); RETURN_FALSE; } else if (sec < 0 || sec > 59) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid '%ld' value for second", sec); + php_error_docref(NULL, E_WARNING, "Invalid '%ld' value for second", sec); RETURN_FALSE; } @@ -1021,24 +945,9 @@ EXCEL_METHOD(Book, packDateValues) static long _php_excel_date_unpack(BookHandle book, double dt) { struct tm tm = {0}; -#ifdef HAVE_LIBXL_243_PLUS -#if LIBXL_VERSION >= 0x03010000 int msec; -#else - unsigned short msec; -#endif -#endif -#if LIBXL_VERSION >= 0x03010000 - if (!xlBookDateUnpack(book, dt, (int *) &(tm.tm_year), (int *) &(tm.tm_mon), (int *) &(tm.tm_mday), (int *) &(tm.tm_hour), (int *) &(tm.tm_min), (int *) &(tm.tm_sec) -#else - if (!xlBookDateUnpack(book, dt, (short unsigned int *) &(tm.tm_year), (short unsigned int *) &(tm.tm_mon), (short unsigned int *) &(tm.tm_mday), - (short unsigned int *) &(tm.tm_hour), (short unsigned int *) &(tm.tm_min), (short unsigned int *) &(tm.tm_sec) -#endif -#ifdef HAVE_LIBXL_243_PLUS - , &msec -#endif - )) { + if (!xlBookDateUnpack(book, dt, (int *) &(tm.tm_year), (int *) &(tm.tm_mon), (int *) &(tm.tm_mday), (int *) &(tm.tm_hour), (int *) &(tm.tm_min), (int *) &(tm.tm_sec), &msec)) { return -1; } @@ -1058,7 +967,7 @@ EXCEL_METHOD(Book, unpackDate) double dt; time_t t; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &dt) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "d", &dt) == FAILURE) { RETURN_FALSE; } @@ -1075,7 +984,6 @@ EXCEL_METHOD(Book, unpackDate) } /* }}} */ -#if LIBXL_VERSION >= 0x03050300 /* {{{ proto bool ExcelBook::isDate1904() Returns whether the 1904 date system is active: true - 1904 date system, false - 1900 date system */ EXCEL_METHOD(Book, isDate1904) @@ -1101,7 +1009,7 @@ EXCEL_METHOD(Book, setDate1904) zval *object = getThis(); zend_bool date_type; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &date_type) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "b", &date_type) == FAILURE) { RETURN_FALSE; } @@ -1112,7 +1020,6 @@ EXCEL_METHOD(Book, setDate1904) RETURN_TRUE; } /* }}} */ -#endif /* {{{ proto int ExcelBook::getActiveSheet() Get the active sheet inside a file. */ @@ -1138,11 +1045,7 @@ EXCEL_METHOD(Book, getDefaultFont) BookHandle book; zval *object = getThis(); const char *font; -#if LIBXL_VERSION >= 0x03010000 int font_size; -#else - unsigned short font_size; -#endif if (ZEND_NUM_ARGS()) { RETURN_FALSE; @@ -1155,7 +1058,7 @@ EXCEL_METHOD(Book, getDefaultFont) } array_init(return_value); - add_assoc_string(return_value, "font", (char *)font, 1); + add_assoc_string(return_value, "font", (char *)font); add_assoc_long(return_value, "font_size", font_size); } /* }}} */ @@ -1166,17 +1069,20 @@ EXCEL_METHOD(Book, setDefaultFont) { BookHandle book; zval *object = getThis(); - char *font; - int font_len; long font_size; + zend_string *font_zs = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sl", &font_zs, &font_size) == FAILURE || font_size < 1) { + RETURN_FALSE; + } - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl", &font, &font_len, &font_size) == FAILURE || font_size < 1) { + if (!font_zs || font_zs->len < 1) { RETURN_FALSE; } BOOK_FROM_OBJECT(book, object); - xlBookSetDefaultFont(book, font, (int)font_size); + xlBookSetDefaultFont(book, font_zs->val, (int)font_size); } /* }}} */ @@ -1186,16 +1092,19 @@ EXCEL_METHOD(Book, setLocale) { BookHandle book; zval *object = getThis(); - char *locale; - int locale_len; + zend_string *locale_zs = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &locale, &locale_len) == FAILURE || locale_len < 1) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &locale_zs) == FAILURE) { + RETURN_FALSE; + } + + if (!locale_zs || locale_zs->len < 1) { RETURN_FALSE; } BOOK_FROM_OBJECT(book, object); - xlBookSetLocale(book, locale); + xlBookSetLocale(book, locale_zs->val); } /* }}} */ @@ -1207,81 +1116,51 @@ EXCEL_METHOD(Book, __construct) zval *object = getThis(); char *name = NULL, *key; int name_len = 0, key_len = 0; -#if LIBXL_VERSION <= 0x03010000 - wchar_t *nw, *kw; - size_t nw_l, kw_l; -#endif -#if defined(HAVE_XML) && defined(EXCEL_WITH_LIBXML) - char *namep, *keyp; - int plen; -#endif - -#ifdef LIBXL_VERSION + zend_string *name_zs = NULL, *key_zs = NULL; zend_bool new_excel = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ssb", &name, &name_len, &key, &key_len, &new_excel) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|SSb", &name_zs, &key_zs, &new_excel) == FAILURE) { RETURN_FALSE; } -#else - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ss", &name, &name_len, &key, &key_len) == FAILURE) { - RETURN_FALSE; + + if (INI_STR("excel.license_name") && INI_STR("excel.license_key")) { + name = INI_STR("excel.license_name"); + name_len = strlen(name); + key = INI_STR("excel.license_key"); + key_len = strlen(key); + } + + if (name_zs && name_zs->len > 0 && key_zs && key_zs->len > 0) { + name = name_zs->val; + name_len = (int) name_zs->len; + key = key_zs->val; + key_len = (int) key_zs->len; + } + +#if defined(HAVE_XML) && defined(EXCEL_WITH_LIBXML) + if (name_len > 0 && key_len > 0) { + name_zs = xml_utf8_decode((const XML_Char *) name, name_len, "ISO-8859-1"); + key_zs = xml_utf8_decode((const XML_Char *) key, key_len, "ISO-8859-1"); } #endif - if (!name_len) { - if (INI_STR("excel.license_name") && INI_STR("excel.license_key")) { - name = INI_STR("excel.license_name"); - name_len = strlen(name); - key = INI_STR("excel.license_key"); - key_len = strlen(key); - } else { -#ifndef LIBXL_VERSION - return; -#endif - } + + if (!name_zs || name_zs->len < 1 || !key_zs || key_zs->len < 1) { + RETURN_FALSE; } BOOK_FROM_OBJECT(book, object); -#ifdef LIBXL_VERSION + if (new_excel) { - excel_book_object *obj = (excel_book_object*) zend_object_store_get_object(object TSRMLS_CC); + excel_book_object *obj = (excel_book_object*) Z_EXCEL_BOOK_OBJ_P(object); if ((book = xlCreateXMLBook())) { xlBookRelease(obj->book); obj->book = book; } else { RETURN_FALSE; } - if (!name_len && !key_len) { - return; - } - } -#endif - if (!name_len || !key_len) { - RETURN_FALSE; - } -#if LIBXL_VERSION <= 0x03010000 - if (!(nw = _php_excel_to_wide(name, name_len + 1, &nw_l))) { - RETURN_FALSE; - } - if (!(kw = _php_excel_to_wide(key, key_len + 1, &kw_l))) { - efree(nw); - RETURN_FALSE; } - xlBookSetKey(book, nw, kw); - efree(nw); - efree(kw); -#else - -#if defined(HAVE_XML) && defined(EXCEL_WITH_LIBXML) - namep = xml_utf8_decode((const XML_Char *) name, name_len, &plen, (const XML_Char *)"ISO-8859-1"); - keyp = xml_utf8_decode((const XML_Char *) key, key_len, &plen, (const XML_Char *)"ISO-8859-1"); - xlBookSetKey(book, namep, keyp); - efree(namep); - efree(keyp); -#else - xlBookSetKey(book, name, key); -#endif -#endif + xlBookSetKey(book, name_zs->val, key_zs->val); } /* }}} */ @@ -1293,7 +1172,7 @@ EXCEL_METHOD(Book, setActiveSheet) zval *object = getThis(); long id; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &id) == FAILURE || id < 0) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &id) == FAILURE || id < 0) { RETURN_FALSE; } @@ -1306,46 +1185,46 @@ EXCEL_METHOD(Book, setActiveSheet) static void php_excel_add_picture(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{ */ { - char *data; - int data_len; + zend_string *data_zs = NULL; BookHandle book; zval *object = getThis(); int ret; + php_stream *stream; + zend_string *contents; - BOOK_FROM_OBJECT(book, object); + if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &data_zs) == FAILURE) { + RETURN_FALSE; + } - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &data, &data_len) == FAILURE) { + if (!data_zs || data_zs->len < 1) { RETURN_FALSE; } + BOOK_FROM_OBJECT(book, object); + if (mode == 1) { - ret = xlBookAddPicture2(book, data, data_len); + ret = xlBookAddPicture2(book, data_zs->val, data_zs->len); } else { - php_stream *stream = php_stream_open_wrapper(data, "rb", ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL); - int len; - char *contents; + stream = php_stream_open_wrapper(data_zs->val, "rb", ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL); if (!stream) { RETURN_FALSE; } - len = php_stream_copy_to_mem(stream, &contents, PHP_STREAM_COPY_ALL, 0); + contents = php_stream_copy_to_mem(stream, PHP_STREAM_COPY_ALL, 0); php_stream_close(stream); - if (len < 1) { + if (!contents || contents->len < 1) { + zend_string_release(contents); RETURN_FALSE; } - ret = xlBookAddPicture2(book, contents, len); - efree(contents); + ret = xlBookAddPicture2(book, contents->val, contents->len); + zend_string_release(contents); } if (ret == -1) { RETURN_FALSE; } else { -#if LIBXL_VERSION >= 0x03020200 && LIBXL_VERSION < 0x03020300 - /* work-around for a bug inside libxl 3.2.2 */ - ret -= 1; -#endif RETURN_LONG(ret); } } @@ -1366,7 +1245,6 @@ EXCEL_METHOD(Book, addPictureFromString) } /* }}} */ -#ifdef LIBXL_VERSION /* {{{ proto bool ExcelBook::rgbMode() Returns whether the RGB mode is active. */ EXCEL_METHOD(Book, rgbMode) @@ -1392,7 +1270,7 @@ EXCEL_METHOD(Book, setRGBMode) zval *object = getThis(); zend_bool val; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &val) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "b", &val) == FAILURE) { RETURN_FALSE; } @@ -1410,18 +1288,18 @@ EXCEL_METHOD(Book, colorPack) zval *object = getThis(); long r, g, b; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll", &r, &g, &b) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "lll", &r, &g, &b) == FAILURE) { RETURN_FALSE; } if (r < 0 || r > 255) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid '%ld' value for color red", r); + php_error_docref(NULL, E_WARNING, "Invalid '%ld' value for color red", r); RETURN_FALSE; } else if (g < 0 || g > 255) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid '%ld' value for color green", g); + php_error_docref(NULL, E_WARNING, "Invalid '%ld' value for color green", g); RETURN_FALSE; } else if (b < 0 || b > 255) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid '%ld' value for color blue", b); + php_error_docref(NULL, E_WARNING, "Invalid '%ld' value for color blue", b); RETURN_FALSE; } @@ -1437,19 +1315,15 @@ EXCEL_METHOD(Book, colorUnpack) { BookHandle book; zval *object = getThis(); -#if LIBXL_VERSION >= 0x03010000 int r, g, b; -#else - unsigned short r, g, b; -#endif long color; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &color) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &color) == FAILURE) { RETURN_FALSE; } if (color <= 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid '%ld' value for color code", color); + php_error_docref(NULL, E_WARNING, "Invalid '%ld' value for color code", color); RETURN_FALSE; } @@ -1463,7 +1337,6 @@ EXCEL_METHOD(Book, colorUnpack) add_assoc_long(return_value, "blue", b); } /* }}} */ -#endif /* {{{ proto int ExcelFont::size([int size]) Get or set the font size */ @@ -1473,7 +1346,7 @@ EXCEL_METHOD(Font, size) FontHandle font; long size = -1; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &size) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &size) == FAILURE) { RETURN_FALSE; } @@ -1495,7 +1368,7 @@ EXCEL_METHOD(Font, italics) FontHandle font; zend_bool italics; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &italics) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &italics) == FAILURE) { RETURN_FALSE; } @@ -1517,7 +1390,7 @@ EXCEL_METHOD(Font, strike) FontHandle font; zend_bool strike; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &strike) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &strike) == FAILURE) { RETURN_FALSE; } @@ -1539,7 +1412,7 @@ EXCEL_METHOD(Font, bold) FontHandle font; zend_bool bold; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &bold) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &bold) == FAILURE) { RETURN_FALSE; } @@ -1561,7 +1434,7 @@ EXCEL_METHOD(Font, color) FontHandle font; long color; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &color) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &color) == FAILURE) { RETURN_FALSE; } @@ -1583,7 +1456,7 @@ EXCEL_METHOD(Font, mode) FontHandle font; long mode; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &mode) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &mode) == FAILURE) { RETURN_FALSE; } @@ -1605,7 +1478,7 @@ EXCEL_METHOD(Font, underline) FontHandle font; long underline; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &underline) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &underline) == FAILURE) { RETURN_FALSE; } @@ -1625,20 +1498,19 @@ EXCEL_METHOD(Font, name) { zval *object = getThis(); FontHandle font; - char *name = NULL; - int name_len; + zend_string *name_zs = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &name, &name_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|S", &name_zs) == FAILURE) { RETURN_FALSE; } FONT_FROM_OBJECT(font, object); - if (name) { - xlFontSetName(font, name); + if (name_zs) { + xlFontSetName(font, name_zs->val); } - RETURN_STRING((char *)xlFontName(font), 1); + RETURN_STRING((char *)xlFontName(font)); } /* }}} */ @@ -1653,7 +1525,7 @@ EXCEL_METHOD(Format, __construct) zval *zbook; PHP_EXCEL_ERROR_HANDLING(); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &zbook, excel_ce_book) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &zbook, excel_ce_book) == FAILURE) { PHP_EXCEL_RESTORE_ERRORS(); return; } @@ -1661,7 +1533,7 @@ EXCEL_METHOD(Format, __construct) BOOK_FROM_OBJECT(book, zbook); - obj = (excel_format_object*) zend_object_store_get_object(object TSRMLS_CC); + obj = Z_EXCEL_FORMAT_OBJ_P(object); format = xlBookAddFormat(book, NULL); if (!format) { @@ -1684,7 +1556,7 @@ EXCEL_METHOD(Font, __construct) zval *zbook; PHP_EXCEL_ERROR_HANDLING(); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &zbook, excel_ce_book) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &zbook, excel_ce_book) == FAILURE) { PHP_EXCEL_RESTORE_ERRORS(); return; } @@ -1692,7 +1564,7 @@ EXCEL_METHOD(Font, __construct) BOOK_FROM_OBJECT(book, zbook); - obj = (excel_font_object*) zend_object_store_get_object(object TSRMLS_CC); + obj = Z_EXCEL_FONT_OBJ_P(object); font = xlBookAddFont(book, NULL); if (!font) { @@ -1713,7 +1585,7 @@ EXCEL_METHOD(Format, setFont) FontHandle font; zval *zfont; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &zfont, excel_ce_font) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &zfont, excel_ce_font) == FAILURE) { RETURN_FALSE; } @@ -1735,11 +1607,11 @@ EXCEL_METHOD(Format, getFont) zval *object = getThis(); FontHandle font; excel_font_object *fo; - excel_format_object *obj = (excel_format_object*) zend_object_store_get_object(object TSRMLS_CC); + excel_format_object *obj = Z_EXCEL_FORMAT_OBJ_P(object); format = obj->format; if (!format) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The format wasn't initialized"); + php_error_docref(NULL, E_WARNING, "The format wasn't initialized"); RETURN_FALSE; } @@ -1754,11 +1626,8 @@ EXCEL_METHOD(Format, getFont) RETURN_FALSE; } - Z_TYPE_P(return_value) = IS_OBJECT; - object_init_ex(return_value, excel_ce_font); - Z_SET_REFCOUNT_P(return_value, 1); - Z_SET_ISREF_P(return_value); - fo = (excel_font_object *) zend_object_store_get_object(return_value TSRMLS_CC); + ZVAL_OBJ(return_value, excel_object_new_sheet(excel_ce_font)); + fo = Z_EXCEL_FONT_OBJ_P(return_value); fo->font = font; fo->book = obj->book; } @@ -1769,7 +1638,7 @@ EXCEL_METHOD(Format, getFont) FormatHandle format; \ zval *object = getThis(); \ long data; \ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &data) == FAILURE) { \ + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &data) == FAILURE) { \ RETURN_FALSE; \ } \ FORMAT_FROM_OBJECT(format, object); \ @@ -1788,7 +1657,7 @@ EXCEL_METHOD(Format, getFont) FormatHandle format; \ zval *object = getThis(); \ zend_bool data; \ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &data) == FAILURE) { \ + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &data) == FAILURE) { \ RETURN_FALSE; \ } \ FORMAT_FROM_OBJECT(format, object); \ @@ -1838,7 +1707,7 @@ EXCEL_METHOD(Format, rotate) zval *object = getThis(); long angle; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &angle) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &angle) == FAILURE) { RETURN_FALSE; } @@ -1846,7 +1715,7 @@ EXCEL_METHOD(Format, rotate) if (ZEND_NUM_ARGS()) { if (angle < 0 || (angle > 180 && angle != 255)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Rotation can be a number between 0 and 180 or 255"); + php_error_docref(NULL, E_WARNING, "Rotation can be a number between 0 and 180 or 255"); RETURN_FALSE; } xlFormatSetRotation(format, angle); @@ -1864,7 +1733,7 @@ EXCEL_METHOD(Format, indent) zval *object = getThis(); long indent; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &indent) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &indent) == FAILURE) { RETURN_FALSE; } @@ -1872,7 +1741,7 @@ EXCEL_METHOD(Format, indent) if (ZEND_NUM_ARGS()) { if (indent < 0 || indent > 15) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Text indentation level must be less than or equal to 15"); + php_error_docref(NULL, E_WARNING, "Text indentation level must be less than or equal to 15"); RETURN_FALSE; } xlFormatSetIndent(format, indent); @@ -2034,26 +1903,25 @@ EXCEL_METHOD(Sheet, __construct) SheetHandle sh; zval *object = getThis(); excel_sheet_object *obj; - zval *zbook; - char *name; - int name_len; + zval *zbook = NULL; + zend_string *name_zs = NULL; PHP_EXCEL_ERROR_HANDLING(); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Os", &zbook, excel_ce_book, &name, &name_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OS", &zbook, excel_ce_book, &name_zs) == FAILURE) { PHP_EXCEL_RESTORE_ERRORS(); return; } PHP_EXCEL_RESTORE_ERRORS(); + if (!zbook || !name_zs || name_zs->len < 1) { + RETURN_FALSE; + } + BOOK_FROM_OBJECT(book, zbook); - obj = (excel_sheet_object*) zend_object_store_get_object(object TSRMLS_CC); + obj = Z_EXCEL_SHEET_OBJ_P(object); -#ifdef LIBXL_VERSION - sh = xlBookAddSheet(book, name, 0); -#else - sh = xlBookAddSheet(book, name); -#endif + sh = xlBookAddSheet(book, name_zs->val, 0); if (!sh) { RETURN_FALSE; @@ -2072,7 +1940,7 @@ EXCEL_METHOD(Sheet, cellType) SheetHandle sheet; long row, col; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &row, &col) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll", &row, &col) == FAILURE) { RETURN_FALSE; } @@ -2092,7 +1960,7 @@ EXCEL_METHOD(Sheet, cellFormat) long row, col; excel_format_object *fo; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &row, &col) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll", &row, &col) == FAILURE) { RETURN_FALSE; } @@ -2100,16 +1968,12 @@ EXCEL_METHOD(Sheet, cellFormat) format = xlSheetCellFormat(sheet, row, col); - Z_TYPE_P(return_value) = IS_OBJECT; - object_init_ex(return_value, excel_ce_format); - Z_SET_REFCOUNT_P(return_value, 1); - Z_SET_ISREF_P(return_value); - fo = (excel_format_object *) zend_object_store_get_object(return_value TSRMLS_CC); + ZVAL_OBJ(return_value, excel_object_new_format(excel_ce_format)); + fo = Z_EXCEL_FORMAT_OBJ_P(return_value); fo->format = format; } /* }}} */ -#ifdef HAVE_LIBXL_243_PLUS /* {{{ proto void ExcelFormat ExcelSheet::setCellFormat(int row, int column, ExcelFormat format) Set cell format */ EXCEL_METHOD(Sheet, setCellFormat) @@ -2120,7 +1984,7 @@ EXCEL_METHOD(Sheet, setCellFormat) zval *oformat; long row, col; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llo", &row, &col, &oformat, excel_ce_format) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "llo", &row, &col, &oformat, excel_ce_format) == FAILURE) { RETURN_FALSE; } @@ -2130,15 +1994,14 @@ EXCEL_METHOD(Sheet, setCellFormat) xlSheetSetCellFormat(sheet, row, col, format); } /* }}} */ -#endif -static zend_bool php_excel_read_cell(int row, int col, zval *val, SheetHandle sheet, BookHandle book, FormatHandle *format, zend_bool read_formula) +zend_bool php_excel_read_cell(int row, int col, zval *val, SheetHandle sheet, BookHandle book, FormatHandle *format, zend_bool read_formula) { const char *s; if (read_formula && xlSheetIsFormula(sheet, row, col)) { s = xlSheetReadFormula(sheet, row, col, format); if (s) { - ZVAL_STRING(val, (char *)s, 1); + ZVAL_STRING(val, (char *)s); return 1; } else { return 0; @@ -2161,11 +2024,7 @@ static zend_bool php_excel_read_cell(int row, int col, zval *val, SheetHandle sh case CELLTYPE_NUMBER: { double d = xlSheetReadNum(sheet, row, col, format); -#if LIBXL_VERSION <= 0x03010000 - if (xlSheetIsDate(sheet, row, col) && xlFormatNumFormat(*format) < 100) { -#else if (xlSheetIsDate(sheet, row, col)) { -#endif long dt = _php_excel_date_unpack(book, d); if (dt == -1) { return 0; @@ -2182,7 +2041,7 @@ static zend_bool php_excel_read_cell(int row, int col, zval *val, SheetHandle sh case CELLTYPE_STRING: { s = xlSheetReadStr(sheet, row, col, format); if (s) { - ZVAL_STRING(val, (char *)s, 1); + ZVAL_STRING(val, (char *)s); return 1; } else { return 0; @@ -2214,20 +2073,20 @@ EXCEL_METHOD(Sheet, readRow) BookHandle book; zend_bool read_formula = 1; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|llb", &row, &col_start, &col_end, &read_formula) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|llb", &row, &col_start, &col_end, &read_formula) == FAILURE) { RETURN_FALSE; } SHEET_AND_BOOK_FROM_OBJECT(sheet, book, object); if (row < 0 || row > xlSheetLastRow(sheet)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid row number '%ld'", row); + php_error_docref(NULL, E_WARNING, "Invalid row number '%ld'", row); RETURN_FALSE; } lc = xlSheetLastCol(sheet); if (col_start < 0 || col_start > lc) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid starting column number '%ld'", col_start); + php_error_docref(NULL, E_WARNING, "Invalid starting column number '%ld'", col_start); RETURN_FALSE; } @@ -2236,7 +2095,7 @@ EXCEL_METHOD(Sheet, readRow) } if (col_end < col_start || col_end > lc) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid ending column number '%ld'", col_end); + php_error_docref(NULL, E_WARNING, "Invalid ending column number '%ld'", col_end); RETURN_FALSE; } @@ -2244,17 +2103,16 @@ EXCEL_METHOD(Sheet, readRow) array_init(return_value); while (lc < (col_end + 1)) { - zval *value; + zval value; FormatHandle format = NULL; - MAKE_STD_ZVAL(value); - if (!php_excel_read_cell(row, lc, value, sheet, book, &format, read_formula)) { + if (!php_excel_read_cell(row, lc, &value, sheet, book, &format, read_formula)) { zval_ptr_dtor(&value); zval_dtor(return_value); - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to read cell in row %d, column %d with error '%s'", row, lc, xlBookErrorMessage(book)); + php_error_docref(NULL, E_WARNING, "Failed to read cell in row %d, column %d with error '%s'", row, lc, xlBookErrorMessage(book)); RETURN_FALSE; } else { - add_next_index_zval(return_value, value); + add_next_index_zval(return_value, &value); } lc++; @@ -2275,20 +2133,20 @@ EXCEL_METHOD(Sheet, readCol) BookHandle book; zend_bool read_formula = 1; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|ll", &col, &row_start, &row_end, &read_formula) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|ll", &col, &row_start, &row_end, &read_formula) == FAILURE) { RETURN_FALSE; } SHEET_AND_BOOK_FROM_OBJECT(sheet, book, object); if (col < 0 || col > xlSheetLastCol(sheet)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid column number '%ld'", col); + php_error_docref(NULL, E_WARNING, "Invalid column number '%ld'", col); RETURN_FALSE; } lc = xlSheetLastRow(sheet); if (row_start < 0 || row_start > lc) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid starting row number '%ld'", row_start); + php_error_docref(NULL, E_WARNING, "Invalid starting row number '%ld'", row_start); RETURN_FALSE; } @@ -2297,7 +2155,7 @@ EXCEL_METHOD(Sheet, readCol) } if (row_end < row_start || row_end > lc) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid ending row number '%ld'", row_end); + php_error_docref(NULL, E_WARNING, "Invalid ending row number '%ld'", row_end); RETURN_FALSE; } @@ -2305,17 +2163,16 @@ EXCEL_METHOD(Sheet, readCol) array_init(return_value); while (lc < (row_end + 1)) { - zval *value; + zval value; FormatHandle format = NULL; - MAKE_STD_ZVAL(value); - if (!php_excel_read_cell(lc, col, value, sheet, book, &format, read_formula)) { + if (!php_excel_read_cell(lc, col, &value, sheet, book, &format, read_formula)) { zval_ptr_dtor(&value); zval_dtor(return_value); - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to read cell in row %d, column %d with error '%s'", lc, col, xlBookErrorMessage(book)); + php_error_docref(NULL, E_WARNING, "Failed to read cell in row %d, column %d with error '%s'", lc, col, xlBookErrorMessage(book)); RETURN_FALSE; } else { - add_next_index_zval(return_value, value); + add_next_index_zval(return_value, &value); } lc++; @@ -2335,7 +2192,7 @@ EXCEL_METHOD(Sheet, read) FormatHandle format = NULL; zend_bool read_formula = 1; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll|z/b", &row, &col, &oformat, &read_formula) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll|z/b", &row, &col, &oformat, &read_formula) == FAILURE) { RETURN_FALSE; } @@ -2347,23 +2204,24 @@ EXCEL_METHOD(Sheet, read) } if (!php_excel_read_cell(row, col, return_value, sheet, book, &format, read_formula)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to read cell in row %d, column %d with error '%s'", row, col, xlBookErrorMessage(book)); + php_error_docref(NULL, E_WARNING, "Failed to read cell in row %d, column %d with error '%s'", row, col, xlBookErrorMessage(book)); RETURN_FALSE; } if (oformat) { excel_format_object *fo; - Z_TYPE_P(oformat) = IS_OBJECT; - object_init_ex(oformat, excel_ce_format); - fo = (excel_format_object *) zend_object_store_get_object(oformat TSRMLS_CC); + ZVAL_OBJ(oformat, excel_object_new_format(excel_ce_format)); + fo = Z_EXCEL_FORMAT_OBJ_P(oformat); fo->format = format; } } /* }}} */ -static zend_bool php_excel_write_cell(SheetHandle sheet, BookHandle book, int row, int col, zval *data, FormatHandle format, long dtype TSRMLS_DC) +zend_bool php_excel_write_cell(SheetHandle sheet, BookHandle book, int row, int col, zval *data, FormatHandle format, long dtype) { + zend_string *data_zs; + switch (Z_TYPE_P(data)) { case IS_NULL: if (INI_INT("excel.skip_empty") > 0) { @@ -2397,6 +2255,8 @@ static zend_bool php_excel_write_cell(SheetHandle sheet, BookHandle book, int ro return xlSheetWriteNum(sheet, row, col, Z_DVAL_P(data), format); case IS_STRING: + data_zs = Z_STR_P(data); + if (Z_STRLEN_P(data) > 0 && '=' == Z_STRVAL_P(data)[0]) { dtype = PHP_EXCEL_FORMULA; } @@ -2418,11 +2278,14 @@ static zend_bool php_excel_write_cell(SheetHandle sheet, BookHandle book, int ro if (Z_STRLEN_P(data) == 0 && INI_INT("excel.skip_empty") == 2) { return 1; } - return xlSheetWriteStr(sheet, row, col, Z_STRVAL_P(data), format); + return xlSheetWriteStr(sheet, row, col, (const char*) data_zs->val, format); } - case IS_BOOL: - return xlSheetWriteBool(sheet, row, col, Z_BVAL_P(data), format); + case IS_TRUE: + return xlSheetWriteBool(sheet, row, col, 1, format); + + case IS_FALSE: + return xlSheetWriteBool(sheet, row, col, 0, format); } return 0; @@ -2441,7 +2304,7 @@ EXCEL_METHOD(Sheet, write) long dtype = -1; zval *data; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llz|O!l", &row, &col, &data, &oformat, excel_ce_format, &dtype) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "llz|O!l", &row, &col, &data, &oformat, excel_ce_format, &dtype) == FAILURE) { RETURN_FALSE; } @@ -2450,8 +2313,8 @@ EXCEL_METHOD(Sheet, write) FORMAT_FROM_OBJECT(format, oformat); } - if (!php_excel_write_cell(sheet, book, row, col, data, oformat ? format : 0, dtype TSRMLS_CC)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to write cell in row %d, column %d with error '%s'", row, col, xlBookErrorMessage(book)); + if (!php_excel_write_cell(sheet, book, row, col, data, oformat ? format : 0, dtype)) { + php_error_docref(NULL, E_WARNING, "Failed to write cell in row %d, column %d with error '%s'", row, col, xlBookErrorMessage(book)); RETURN_FALSE; } @@ -2470,11 +2333,10 @@ EXCEL_METHOD(Sheet, writeRow) long row, col = 0; zval *oformat = NULL; zval *data; - HashPosition pos; - zval **element; + zval *element; long i; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la|lO", &row, &data, &col, &oformat, excel_ce_format) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "la|lO", &row, &data, &col, &oformat, excel_ce_format) == FAILURE) { RETURN_FALSE; } @@ -2484,26 +2346,23 @@ EXCEL_METHOD(Sheet, writeRow) } if (row < 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid row number '%ld'", row); + php_error_docref(NULL, E_WARNING, "Invalid row number '%ld'", row); RETURN_FALSE; } if (col < 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid starting column number '%ld'", col); + php_error_docref(NULL, E_WARNING, "Invalid starting column number '%ld'", col); RETURN_FALSE; } i = col; - for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(data), &pos); - zend_hash_get_current_data_ex(Z_ARRVAL_P(data), (void **) &element, &pos) == SUCCESS; - zend_hash_move_forward_ex(Z_ARRVAL_P(data), &pos)) { - - if (!php_excel_write_cell(sheet, book, row, i++, *element, oformat ? format : 0, -1 TSRMLS_CC)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to write cell in row %d, column %d with error '%s'", row, i-1, xlBookErrorMessage(book)); + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(data), element) { + if (!php_excel_write_cell(sheet, book, row, i++, element, (oformat ? format : 0), -1)) { + php_error_docref(NULL, E_WARNING, "Failed to write cell in row %d, column %d with error '%s'", row, i-1, xlBookErrorMessage(book)); RETURN_FALSE; } - } + } ZEND_HASH_FOREACH_END(); RETURN_TRUE; } @@ -2520,12 +2379,11 @@ EXCEL_METHOD(Sheet, writeCol) long row = 0, col; zval *oformat = NULL; zval *data; - HashPosition pos; - zval **element; + zval *element; long i; long dtype = -1; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la|lO!l", &col, &data, &row, &oformat, excel_ce_format, &dtype) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "la|lO!l", &col, &data, &row, &oformat, excel_ce_format, &dtype) == FAILURE) { RETURN_FALSE; } @@ -2535,26 +2393,23 @@ EXCEL_METHOD(Sheet, writeCol) } if (col < 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid column number '%ld'", col); + php_error_docref(NULL, E_WARNING, "Invalid column number '%ld'", col); RETURN_FALSE; } if (row < 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid starting row number '%ld'", row); + php_error_docref(NULL, E_WARNING, "Invalid starting row number '%ld'", row); RETURN_FALSE; } i = row; - for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(data), &pos); - zend_hash_get_current_data_ex(Z_ARRVAL_P(data), (void **) &element, &pos) == SUCCESS; - zend_hash_move_forward_ex(Z_ARRVAL_P(data), &pos)) { - - if (!php_excel_write_cell(sheet, book, i++, col, *element, oformat ? format : 0, dtype TSRMLS_CC)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to write cell in row %d, column %d with error '%s'", i-1, col, xlBookErrorMessage(book)); + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(data), element) { + if (!php_excel_write_cell(sheet, book, i++, col, element, oformat ? format : 0, dtype)) { + php_error_docref(NULL, E_WARNING, "Failed to write cell in row %d, column %d with error '%s'", i-1, col, xlBookErrorMessage(book)); RETURN_FALSE; } - } + } ZEND_HASH_FOREACH_END(); RETURN_TRUE; } @@ -2565,7 +2420,7 @@ EXCEL_METHOD(Sheet, writeCol) SheetHandle sheet; \ zval *object = getThis(); \ long r, c; \ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &r, &c) == FAILURE) { \ + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll", &r, &c) == FAILURE) { \ RETURN_FALSE; \ } \ SHEET_FROM_OBJECT(sheet, object); \ @@ -2586,13 +2441,9 @@ EXCEL_METHOD(Sheet, isDate) { zval *object = getThis(); long r, c; -#if LIBXL_VERSION <= 0x03010000 - double d; - FormatHandle format = NULL; -#endif SheetHandle sheet; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &r, &c) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll", &r, &c) == FAILURE) { RETURN_FALSE; } @@ -2601,12 +2452,8 @@ EXCEL_METHOD(Sheet, isDate) if (xlSheetCellType(sheet, r, c) != CELLTYPE_NUMBER) { RETURN_FALSE; } -#if LIBXL_VERSION <= 0x03010000 - d = xlSheetReadNum(sheet, r, c, &format); - RETURN_BOOL(xlSheetIsDate(sheet, r, c) && (!format || (xlFormatNumFormat(format) < 100))); -#else + RETURN_BOOL(xlSheetIsDate(sheet, r, c)); -#endif } /* }}} */ @@ -2647,7 +2494,7 @@ EXCEL_METHOD(Sheet, removeCol) SheetHandle sheet; \ zval *object = getThis(); \ long val; \ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &val) == FAILURE) { \ + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &val) == FAILURE) { \ RETURN_FALSE; \ } \ SHEET_FROM_OBJECT(sheet, object); \ @@ -2679,7 +2526,7 @@ EXCEL_METHOD(Sheet, readComment) const char *s; long r, c; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &r, &c) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll", &r, &c) == FAILURE) { RETURN_FALSE; } @@ -2689,7 +2536,7 @@ EXCEL_METHOD(Sheet, readComment) if (!s) { RETURN_FALSE; } - RETURN_STRING((char *)s, 1); + RETURN_STRING((char *)s); } /* }}} */ @@ -2699,17 +2546,20 @@ EXCEL_METHOD(Sheet, writeComment) { SheetHandle sheet; zval *object = getThis(); - char *val, *auth; - int val_len, auth_len; + zend_string *val_zs = NULL, *auth_zs = NULL; long r, c, w, h; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llssll", &r, &c, &val, &val_len, &auth, &auth_len, &w, &h) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "llSSll", &r, &c, &val_zs, &auth_zs, &w, &h) == FAILURE) { + RETURN_FALSE; + } + + if (!val_zs || val_zs->len < 1 || !auth_zs || auth_zs->len < 1) { RETURN_FALSE; } SHEET_FROM_OBJECT(sheet, object); - xlSheetWriteComment(sheet, r, c, val, auth, w, h); + xlSheetWriteComment(sheet, r, c, val_zs->val, auth_zs->val, w, h); } /* }}} */ @@ -2725,7 +2575,7 @@ EXCEL_METHOD(Sheet, setColWidth) zval *f = NULL; zend_bool h = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lld|bz/", &s, &e, &width, &h, &f) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "lld|bz/", &s, &e, &width, &h, &f) == FAILURE) { RETURN_FALSE; } @@ -2736,13 +2586,13 @@ EXCEL_METHOD(Sheet, setColWidth) } if (e < s) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Start cell is greater then end cell"); + php_error_docref(NULL, E_WARNING, "Start cell is greater then end cell"); RETURN_FALSE; } else if (s < 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Start cell cannot be less then 0"); + php_error_docref(NULL, E_WARNING, "Start cell cannot be less then 0"); RETURN_FALSE; } else if (width < -1) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Width cannot be less then -1"); + php_error_docref(NULL, E_WARNING, "Width cannot be less then -1"); RETURN_FALSE; } @@ -2762,7 +2612,7 @@ EXCEL_METHOD(Sheet, setRowHeight) zval *f = NULL; zend_bool h = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ld|z/b", &row, &height, &f, &h) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ld|z/b", &row, &height, &f, &h) == FAILURE) { RETURN_FALSE; } @@ -2773,10 +2623,10 @@ EXCEL_METHOD(Sheet, setRowHeight) } if (row < 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Row number cannot be less then 0"); + php_error_docref(NULL, E_WARNING, "Row number cannot be less then 0"); RETURN_FALSE; } else if (height < 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Height cannot be less then 0"); + php_error_docref(NULL, E_WARNING, "Height cannot be less then 0"); RETURN_FALSE; } @@ -2791,13 +2641,9 @@ EXCEL_METHOD(Sheet, getMerge) SheetHandle sheet; zval *object = getThis(); long row, col; -#if LIBXL_VERSION >= 0x03010000 int rowFirst, rowLast, colFirst, colLast; -#else - unsigned short rowFirst, rowLast, colFirst, colLast; -#endif - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &row, &col) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll", &row, &col) == FAILURE) { RETURN_FALSE; } @@ -2823,7 +2669,7 @@ EXCEL_METHOD(Sheet, setMerge) zval *object = getThis(); long row_s, col_s, row_e, col_e; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llll", &row_s, &row_e, &col_s, &col_e) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "llll", &row_s, &row_e, &col_s, &col_e) == FAILURE) { RETURN_FALSE; } @@ -2841,7 +2687,7 @@ EXCEL_METHOD(Sheet, deleteMerge) zval *object = getThis(); long row, col; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &row, &col) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll", &row, &col) == FAILURE) { RETURN_FALSE; } @@ -2851,7 +2697,6 @@ EXCEL_METHOD(Sheet, deleteMerge) } /* }}} */ -#if LIBXL_VERSION >= 0x03040000 /* {{{ proto void ExcelSheet::addPictureScaled(int row, int column, int pic_id, double scale [, int x_offset [, int y_offset]]) Insert picture into a cell with a set scale */ EXCEL_METHOD(Sheet, addPictureScaled) @@ -2862,7 +2707,7 @@ EXCEL_METHOD(Sheet, addPictureScaled) long x_offset = 0, y_offset = 0; double scale; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llld|ll", &row, &col, &pic_id, &scale, &x_offset, &y_offset) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "llld|ll", &row, &col, &pic_id, &scale, &x_offset, &y_offset) == FAILURE) { RETURN_FALSE; } @@ -2881,7 +2726,7 @@ EXCEL_METHOD(Sheet, addPictureDim) long row, col, pic_id, w, h; long x_offset = 0, y_offset = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lllll", &row, &col, &pic_id, &w, &h, &x_offset, &y_offset) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "lllll", &row, &col, &pic_id, &w, &h, &x_offset, &y_offset) == FAILURE) { RETURN_FALSE; } @@ -2890,44 +2735,6 @@ EXCEL_METHOD(Sheet, addPictureDim) xlSheetSetPicture2(sheet, row, col, pic_id, w, h, x_offset, y_offset); } /* }}} */ -#else -/* {{{ proto void ExcelSheet::addPictureScaled(int row, int column, int pic_id, double scale) - Insert picture into a cell with a set scale */ -EXCEL_METHOD(Sheet, addPictureScaled) -{ - SheetHandle sheet; - zval *object = getThis(); - long row, col, pic_id; - double scale; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llld", &row, &col, &pic_id, &scale) == FAILURE) { - RETURN_FALSE; - } - - SHEET_FROM_OBJECT(sheet, object); - - xlSheetSetPicture(sheet, row, col, pic_id, scale); -} -/* }}} */ - -/* {{{ proto void ExcelSheet::addPictureDim(int row, int column, int pic_id, int width, int height) - Insert picture into a cell with a given dimensions */ -EXCEL_METHOD(Sheet, addPictureDim) -{ - SheetHandle sheet; - zval *object = getThis(); - long row, col, pic_id, w, h; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lllll", &row, &col, &pic_id, &w, &h) == FAILURE) { - RETURN_FALSE; - } - - SHEET_FROM_OBJECT(sheet, object); - - xlSheetSetPicture2(sheet, row, col, pic_id, w, h); -} -/* }}} */ -#endif #define PHP_EXCEL_SHEET_SET_BREAK(func_name) \ { \ @@ -2935,7 +2742,7 @@ EXCEL_METHOD(Sheet, addPictureDim) zval *object = getThis(); \ long val; \ zend_bool brk; \ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lb", &val, &brk) == FAILURE) { \ + if (zend_parse_parameters(ZEND_NUM_ARGS(), "lb", &val, &brk) == FAILURE) { \ RETURN_FALSE; \ } \ SHEET_FROM_OBJECT(sheet, object); \ @@ -2966,7 +2773,7 @@ EXCEL_METHOD(Sheet, splitSheet) zval *object = getThis(); long row, col; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &row, &col) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll", &row, &col) == FAILURE) { RETURN_FALSE; } @@ -2982,7 +2789,7 @@ EXCEL_METHOD(Sheet, splitSheet) zval *object = getThis(); \ long s, e; \ zend_bool brk = 0; \ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll|b", &s, &e, &brk) == FAILURE) { \ + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll|b", &s, &e, &brk) == FAILURE) { \ RETURN_FALSE; \ } \ SHEET_FROM_OBJECT(sheet, object); \ @@ -3013,7 +2820,7 @@ EXCEL_METHOD(Sheet, clear) zval *object = getThis(); long row_s, col_s, col_e, row_e; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llll", &row_s, &row_e, &col_s, &col_e) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "llll", &row_s, &row_e, &col_s, &col_e) == FAILURE) { RETURN_FALSE; } @@ -3031,7 +2838,7 @@ EXCEL_METHOD(Sheet, copy) zval *object = getThis(); long row, col, to_row, to_col; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llll", &row, &col, &to_row, &to_col) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "llll", &row, &col, &to_row, &to_col) == FAILURE) { RETURN_FALSE; } @@ -3044,7 +2851,7 @@ EXCEL_METHOD(Sheet, copy) #define PE_RETURN_IS_LONG RETURN_LONG #define PE_RETURN_IS_BOOL RETURN_BOOL #define PE_RETURN_IS_DOUBLE RETURN_DOUBLE -#define PE_RETURN_IS_STRING(data) if (data) { RETURN_STRING((char *)data, 1) } else { RETURN_NULL(); } +#define PE_RETURN_IS_STRING(data) if (data) { RETURN_STRING((char *)data) } else { RETURN_NULL(); } #define PHP_EXCEL_INFO(func_name, type) \ { \ @@ -3062,7 +2869,7 @@ EXCEL_METHOD(Sheet, copy) SheetHandle sheet; \ zval *object = getThis(); \ zend_bool val; \ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &val) == FAILURE) { \ + if (zend_parse_parameters(ZEND_NUM_ARGS(), "b", &val) == FAILURE) { \ RETURN_FALSE; \ } \ SHEET_FROM_OBJECT(sheet, object); \ @@ -3074,7 +2881,7 @@ EXCEL_METHOD(Sheet, copy) SheetHandle sheet; \ zval *object = getThis(); \ long val; \ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &val) == FAILURE) { \ + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &val) == FAILURE) { \ RETURN_FALSE; \ } \ SHEET_FROM_OBJECT(sheet, object); \ @@ -3086,7 +2893,7 @@ EXCEL_METHOD(Sheet, copy) SheetHandle sheet; \ zval *object = getThis(); \ double val; \ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &val) == FAILURE) { \ + if (zend_parse_parameters(ZEND_NUM_ARGS(), "d", &val) == FAILURE) { \ RETURN_FALSE; \ } \ SHEET_FROM_OBJECT(sheet, object); \ @@ -3149,7 +2956,6 @@ EXCEL_METHOD(Sheet, setDisplayGridlines) } /* }}} */ -#if LIBXL_VERSION >= 0x03020300 /* {{{ proto bool ExcelSheet::setHidden(bool value) Hides/unhides the sheet. */ EXCEL_METHOD(Sheet, setHidden) @@ -3158,7 +2964,7 @@ EXCEL_METHOD(Sheet, setHidden) zval *object = getThis(); zend_bool val; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &val) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "b", &val) == FAILURE) { RETURN_FALSE; } @@ -3184,9 +2990,7 @@ EXCEL_METHOD(Sheet, isHidden) RETURN_BOOL(xlSheetHidden(sheet)); } /* }}} */ -#endif -#if LIBXL_VERSION >= 0x03020400 /* {{{ proto array ExcelSheet::getTopLeftView() Extracts the first visible row and the leftmost visible column of the sheet. */ EXCEL_METHOD(Sheet, getTopLeftView) @@ -3217,7 +3021,7 @@ EXCEL_METHOD(Sheet, setTopLeftView) zval *object = getThis(); long r,c; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &r, &c) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll", &r, &c) == FAILURE) { RETURN_FALSE; } @@ -3238,7 +3042,7 @@ EXCEL_METHOD(Sheet, rowColToAddr) long row, col; const char *cel_ref; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll|bb", &row, &col, &row_relative, &col_relative) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll|bb", &row, &col, &row_relative, &col_relative) == FAILURE) { RETURN_FALSE; } @@ -3248,7 +3052,7 @@ EXCEL_METHOD(Sheet, rowColToAddr) if (!cel_ref) { RETURN_FALSE; } - RETURN_STRING(cel_ref, 1); + RETURN_STRING(cel_ref); } /* }}} */ @@ -3258,22 +3062,21 @@ EXCEL_METHOD(Sheet, addrToRowCol) { SheetHandle sheet; zval *object = getThis(); - char *cell_reference; - int cell_reference_len; + zend_string *cell_reference_zs = NULL; int row = 0, col = 0, rowRelative = 0, colRelative = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &cell_reference, &cell_reference_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &cell_reference_zs) == FAILURE) { RETURN_FALSE; } - if (!cell_reference_len) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cell reference cannot be empty"); + if (!cell_reference_zs || cell_reference_zs->len < 1) { + php_error_docref(NULL, E_WARNING, "Cell reference cannot be empty"); RETURN_FALSE; } SHEET_FROM_OBJECT(sheet, object); - xlSheetAddrToRowCol(sheet, cell_reference, &row, &col, &rowRelative, &colRelative); + xlSheetAddrToRowCol(sheet, cell_reference_zs->val, &row, &col, &rowRelative, &colRelative); array_init(return_value); add_assoc_long(return_value, "row", row); add_assoc_long(return_value, "column", col); @@ -3281,7 +3084,6 @@ EXCEL_METHOD(Sheet, addrToRowCol) add_assoc_bool(return_value, "row_relative", rowRelative); } /* }}} */ -#endif /* {{{ proto void ExcelSheet::setPrintGridlines(bool value) Sets gridlines for printing */ @@ -3375,14 +3177,16 @@ EXCEL_METHOD(Sheet, footer) { \ SheetHandle sheet; \ zval *object = getThis(); \ - char *val; \ - int val_len; \ + zend_string *val_zs = NULL; \ double margin; \ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sd", &val, &val_len, &margin) == FAILURE || val_len > 255) { \ + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sd", &val_zs, &margin) == FAILURE) { \ + RETURN_FALSE; \ + } \ + if (!val_zs || val_zs->len > 255) { \ RETURN_FALSE; \ } \ SHEET_FROM_OBJECT(sheet, object); \ - RETURN_BOOL(xlSheet ## func_name (sheet, val, margin)); \ + RETURN_BOOL(xlSheet ## func_name (sheet, val_zs->val, margin)); \ } /* {{{ proto bool ExcelSheet::setHeader(string header, double margin) @@ -3543,20 +3347,22 @@ EXCEL_METHOD(Sheet, setName) { SheetHandle sheet; zval *object = getThis(); - char *val; - int val_len; + zend_string *val_zs = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &val, &val_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &val_zs) == FAILURE) { + RETURN_FALSE; + } + + if (!val_zs) { RETURN_FALSE; } SHEET_FROM_OBJECT(sheet, object); - xlSheetSetName(sheet, val); + xlSheetSetName(sheet, val_zs->val); } /* }}} */ -#if LIBXL_VERSION >= 0x03010000 /* {{{ proto bool ExcelSheet::setNamedRange(string name, int row, int col, int to_row, int to_col [, int scope_id]) Create a named range */ EXCEL_METHOD(Sheet, setNamedRange) @@ -3564,37 +3370,29 @@ EXCEL_METHOD(Sheet, setNamedRange) SheetHandle sheet; zval *object = getThis(); long row, to_row, col, to_col; - char *name; - int name_len; -#if LIBXL_VERSION >= 0x03050401 + zend_string *name_zs = NULL; long scope_id = SCOPE_WORKBOOK; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sllll|l", &name, &name_len, &row, &to_row, &col, &to_col, &scope_id) == FAILURE) { -#else - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sllll", &name, &name_len, &row, &to_row, &col, &to_col) == FAILURE) { -#endif + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sllll|l", &name_zs, &row, &to_row, &col, &to_col, &scope_id) == FAILURE) { RETURN_FALSE; } - if (!name_len) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The range name cannot be empty."); + if (!name_zs || name_zs->len < 1) { + php_error_docref(NULL, E_WARNING, "The range name cannot be empty."); RETURN_FALSE; } + if (row > to_row) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The range row start cannot be greater than row end."); + php_error_docref(NULL, E_WARNING, "The range row start cannot be greater than row end."); RETURN_FALSE; } else if (col > to_col) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The range column start cannot be greater than column end."); + php_error_docref(NULL, E_WARNING, "The range column start cannot be greater than column end."); RETURN_FALSE; } SHEET_FROM_OBJECT(sheet, object); -#if LIBXL_VERSION >= 0x03050401 - RETURN_BOOL(xlSheetSetNamedRange(sheet, name, row, to_row, col, to_col, scope_id)); -#else - RETURN_BOOL(xlSheetSetNamedRange(sheet, name, row, to_row, col, to_col)); -#endif + RETURN_BOOL(xlSheetSetNamedRange(sheet, name_zs->val, row, to_row, col, to_col, scope_id)); } /* }}} */ @@ -3604,30 +3402,21 @@ EXCEL_METHOD(Sheet, delNamedRange) { SheetHandle sheet; zval *object = getThis(); - char *val; - int val_len; -#if LIBXL_VERSION >= 0x03050401 + zend_string *val_zs = NULL; long scope_id = SCOPE_WORKBOOK; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &val, &val_len, &scope_id) == FAILURE) { -#else - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &val, &val_len) == FAILURE) { -#endif + if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|l", &val_zs, &scope_id) == FAILURE) { RETURN_FALSE; } - if (!val_len) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The range name cannot be empty."); + if (!val_zs || val_zs->len < 1) { + php_error_docref(NULL, E_WARNING, "The range name cannot be empty."); RETURN_FALSE; } SHEET_FROM_OBJECT(sheet, object); -#if LIBXL_VERSION >= 0x03050401 - RETURN_BOOL(xlSheetDelNamedRange(sheet, val, scope_id)); -#else - RETURN_BOOL(xlSheetDelNamedRange(sheet, val)); -#endif + RETURN_BOOL(xlSheetDelNamedRange(sheet, val_zs->val, scope_id)); } /* }}} */ @@ -3636,11 +3425,11 @@ EXCEL_METHOD(Sheet, delNamedRange) SheetHandle sheet; \ zval *object = getThis(); \ long s, e; \ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &s, &e) == FAILURE) { \ + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll", &s, &e) == FAILURE) { \ RETURN_FALSE; \ } \ if (s > e) { \ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The range start is greater than the end."); \ + php_error_docref(NULL, E_WARNING, "The range start is greater than the end."); \ RETURN_FALSE; \ } \ SHEET_FROM_OBJECT(sheet, object); \ @@ -3688,7 +3477,7 @@ EXCEL_METHOD(Sheet, setGroupSummaryBelow) zval *object = getThis(); zend_bool val; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &val) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "b", &val) == FAILURE) { RETURN_FALSE; } @@ -3723,7 +3512,7 @@ EXCEL_METHOD(Sheet, setGroupSummaryRight) zval *object = getThis(); zend_bool val; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &val) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "b", &val) == FAILURE) { RETURN_FALSE; } @@ -3734,7 +3523,6 @@ EXCEL_METHOD(Sheet, setGroupSummaryRight) } /* }}} */ -#if LIBXL_VERSION >= 0x03020000 /* {{{ proto bool ExcelSheet::setPrintFit(int wPages, int hPages) Fits sheet width and sheet height to wPages and hPages respectively. */ EXCEL_METHOD(Sheet, setPrintFit) @@ -3743,7 +3531,7 @@ EXCEL_METHOD(Sheet, setPrintFit) zval *object = getThis(); long wPages, hPages; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &wPages, &hPages) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll", &wPages, &hPages) == FAILURE) { RETURN_FALSE; } @@ -3783,34 +3571,28 @@ EXCEL_METHOD(Sheet, getNamedRange) { SheetHandle sheet; zval *object = getThis(); - char *name; - int name_len; + zend_string *name_zs = NULL; int rf, rl, cf, cl; -#if LIBXL_VERSION >= 0x03050401 long scope_id = SCOPE_WORKBOOK; int hidden = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &name, &name_len, &scope_id) == FAILURE) { -#else - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { -#endif + if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|l", &name_zs, &scope_id) == FAILURE) { + RETURN_FALSE; + } + + if (!name_zs || name_zs->len < 1) { RETURN_FALSE; } SHEET_FROM_OBJECT(sheet, object); -#if LIBXL_VERSION >= 0x03050401 - if (xlSheetGetNamedRange(sheet, name, &rf, &rl, &cf, &cl, scope_id, &hidden)) { -#else - if (xlSheetGetNamedRange(sheet, name, &rf, &rl, &cf, &cl)) { -#endif + + if (xlSheetGetNamedRange(sheet, name_zs->val, &rf, &rl, &cf, &cl, scope_id, &hidden)) { array_init(return_value); add_assoc_long(return_value, "row_first", rf); add_assoc_long(return_value, "row_last", rl); add_assoc_long(return_value, "col_first", cf); add_assoc_long(return_value, "col_last", cl); -#if LIBXL_VERSION >= 0x03050401 add_assoc_bool(return_value, "hidden", hidden); -#endif } else { RETURN_FALSE; } @@ -3824,34 +3606,22 @@ EXCEL_METHOD(Sheet, getIndexRange) zval *object = getThis(); long index; int rf, rl, cf, cl; -#if LIBXL_VERSION >= 0x03050401 - int hidden; + int hidden = 0; long scope_id = SCOPE_WORKBOOK; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &index, &scope_id) == FAILURE) { - RETURN_FALSE; - } -#else - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|l", &index, &scope_id) == FAILURE) { RETURN_FALSE; } -#endif SHEET_FROM_OBJECT(sheet, object); -#if LIBXL_VERSION >= 0x03050401 if (xlSheetNamedRange(sheet, (int)index, &rf, &rl, &cf, &cl, (int *)&scope_id, &hidden)) { -#else - if (xlSheetNamedRange(sheet, (int)index, &rf, &rl, &cf, &cl)) { -#endif array_init(return_value); add_assoc_long(return_value, "row_first", rf); add_assoc_long(return_value, "row_last", rl); add_assoc_long(return_value, "col_first", cf); add_assoc_long(return_value, "col_last", cl); -#if LIBXL_VERSION >= 0x03050401 add_assoc_bool(return_value, "hidden", hidden); add_assoc_long(return_value, "scope", scope_id); -#endif } else { RETURN_FALSE; } @@ -3882,7 +3652,7 @@ EXCEL_METHOD(Sheet, getVerPageBreak) zval *object = getThis(); long index; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) { RETURN_FALSE; } @@ -3915,7 +3685,7 @@ EXCEL_METHOD(Sheet, getHorPageBreak) zval *object = getThis(); long index; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) { RETURN_FALSE; } @@ -3950,7 +3720,7 @@ EXCEL_METHOD(Sheet, getPictureInfo) int rowTop, colLeft, rowBottom, colRight, width, height, offset_x, offset_y; int pic_index; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) { RETURN_FALSE; } @@ -4022,7 +3792,7 @@ EXCEL_METHOD(Book, getRefR1C1) } BOOK_FROM_OBJECT(book, object); - RETURN_BOOL(xlBookRefR1C1(book)); + RETURN_BOOL(xlBookRefR1C1A(book)); } /* }}} */ @@ -4034,12 +3804,12 @@ EXCEL_METHOD(Book, setRefR1C1) zval *object = getThis(); zend_bool active; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &active) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "b", &active) == FAILURE) { RETURN_FALSE; } BOOK_FROM_OBJECT(book, object); - xlBookSetRefR1C1(book, (int)active); + xlBookSetRefR1C1A(book, (int)active); } /* }}} */ @@ -4055,7 +3825,7 @@ EXCEL_METHOD(Book, getPicture) unsigned int buf_len; enum PictureType {PICTURETYPE_PNG, PICTURETYPE_JPEG, PICTURETYPE_WMF, PICTURETYPE_DIB, PICTURETYPE_EMF, PICTURETYPE_PICT, PICTURETYPE_TIFF, PICTURETYPE_ERROR = 0xFF}; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) { RETURN_FALSE; } @@ -4066,7 +3836,7 @@ EXCEL_METHOD(Book, getPicture) } array_init(return_value); - add_assoc_stringl(return_value, "data", (char *)buf, buf_len, 1); + add_assoc_stringl(return_value, "data", (char *)buf, buf_len); add_assoc_long(return_value, "type", type); } /* }}} */ @@ -4096,39 +3866,36 @@ EXCEL_METHOD(Book, insertSheet) zval *shz = NULL; SheetHandle sh, sheet; excel_sheet_object *fo; - char *name; - int name_len; + zend_string *name_zs = NULL; long index; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls|o", &index, &name, &name_len, &shz) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "lS|o", &index, &name_zs, &shz) == FAILURE) { + RETURN_FALSE; + } + + if (!name_zs || name_zs->len < 1) { RETURN_FALSE; } BOOK_FROM_OBJECT(book, object); if (shz) { SHEET_FROM_OBJECT(sheet, shz); - if (!(sh = xlBookInsertSheet(book, index, name, sheet))) { + if (!(sh = xlBookInsertSheet(book, index, name_zs->val, sheet))) { RETURN_FALSE; } } else { - if (!(sh = xlBookInsertSheet(book, index, name, 0))) { + if (!(sh = xlBookInsertSheet(book, index, name_zs->val, 0))) { RETURN_FALSE; } } - Z_TYPE_P(return_value) = IS_OBJECT; - object_init_ex(return_value, excel_ce_sheet); - Z_SET_REFCOUNT_P(return_value, 1); - Z_SET_ISREF_P(return_value); - fo = (excel_sheet_object *) zend_object_store_get_object(return_value TSRMLS_CC); + ZVAL_OBJ(return_value, excel_object_new_sheet(excel_ce_sheet)); + fo = Z_EXCEL_SHEET_OBJ_P(return_value); fo->sheet = sh; fo->book = book; } /* }}} */ -#endif - -#if LIBXL_VERSION >= 0x03050401 /* {{{ proto bool ExcelBook::isTemplate() Returns whether the workbook is template. */ EXCEL_METHOD(Book, isTemplate) @@ -4153,7 +3920,7 @@ EXCEL_METHOD(Book, setTemplate) zval *object = getThis(); zend_bool mode; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &mode) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "b", &mode) == FAILURE) { RETURN_FALSE; } @@ -4186,7 +3953,7 @@ EXCEL_METHOD(Sheet, setRightToLeft) zval *object = getThis(); long mode; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &mode) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &mode) == FAILURE) { RETURN_FALSE; } @@ -4194,7 +3961,6 @@ EXCEL_METHOD(Sheet, setRightToLeft) xlSheetSetRightToLeft(sheet, (int)mode); } /* }}} */ -#endif /* {{{ proto bool ExcelSheet::setPrintArea() Sets the print area. */ @@ -4204,15 +3970,15 @@ EXCEL_METHOD(Sheet, setPrintArea) SheetHandle sheet; long row, col, to_row, to_col; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llll", &row, &to_row, &col, &to_col) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "llll", &row, &to_row, &col, &to_col) == FAILURE) { RETURN_FALSE; } if (row > to_row) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The range row start cannot be greater than row end."); + php_error_docref(NULL, E_WARNING, "The range row start cannot be greater than row end."); RETURN_FALSE; } else if (col > to_col) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The range column start cannot be greater than column end."); + php_error_docref(NULL, E_WARNING, "The range column start cannot be greater than column end."); RETURN_FALSE; } @@ -4257,7 +4023,6 @@ EXCEL_METHOD(Sheet, clearPrintArea) RETURN_TRUE; } /* }}} */ -#endif /* {{{ proto bool ExcelSheet::protect() Returns whether sheet is protected: 1 - yes, 0 - no. */ @@ -4275,7 +4040,6 @@ EXCEL_METHOD(Sheet, setProtect) } /* }}} */ -#if LIBXL_VERSION >= 0x03060000 /* {{{ proto long ExcelSheet::hyperlinkSize() Returns the number of hyperlinks in the sheet. */ EXCEL_METHOD(Sheet, hyperlinkSize) @@ -4302,7 +4066,7 @@ EXCEL_METHOD(Sheet, hyperlink) int rowFirst, rowLast, colFirst, colLast; const char *s; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) { RETURN_FALSE; } @@ -4315,7 +4079,7 @@ EXCEL_METHOD(Sheet, hyperlink) } array_init(return_value); - add_assoc_string(return_value, "hyperlink", (char *)s, 1); + add_assoc_string(return_value, "hyperlink", (char *)s); add_assoc_long(return_value, "row_first", rowFirst); add_assoc_long(return_value, "row_last", rowLast); add_assoc_long(return_value, "col_first", colFirst); @@ -4331,7 +4095,7 @@ EXCEL_METHOD(Sheet, delHyperlink) SheetHandle sheet; long index; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) { RETURN_FALSE; } @@ -4350,17 +4114,20 @@ EXCEL_METHOD(Sheet, addHyperlink) { SheetHandle sheet; zval *object = getThis(); - char *val; - int val_len; + zend_string *val_zs = NULL; long row_first, row_last, col_first, col_last; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sllll", &val, &val_len, &row_first, &row_last, &col_first, &col_last) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sllll", &val_zs, &row_first, &row_last, &col_first, &col_last) == FAILURE) { + RETURN_FALSE; + } + + if (!val_zs || val_zs->len < 1) { RETURN_FALSE; } SHEET_FROM_OBJECT(sheet, object); - xlSheetAddHyperlink(sheet, val, row_first, row_last, col_first, col_last); + xlSheetAddHyperlink(sheet, val_zs->val, row_first, row_last, col_first, col_last); RETURN_TRUE; } /* }}} */ @@ -4390,7 +4157,7 @@ EXCEL_METHOD(Sheet, merge) long index; int rowFirst, rowLast, colFirst, colLast; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) { RETURN_FALSE; } @@ -4420,7 +4187,7 @@ EXCEL_METHOD(Sheet, delMergeByIndex) SheetHandle sheet; long index; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) { RETURN_FALSE; } @@ -4461,7 +4228,7 @@ EXCEL_METHOD(Sheet, rowHidden) SheetHandle sheet; long row; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &row) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &row) == FAILURE) { RETURN_FALSE; } @@ -4483,7 +4250,7 @@ EXCEL_METHOD(Sheet, setRowHidden) long row; zend_bool hidden; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lb", &row, &hidden) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "lb", &row, &hidden) == FAILURE) { RETURN_FALSE; } @@ -4504,7 +4271,7 @@ EXCEL_METHOD(Sheet, colHidden) SheetHandle sheet; long col; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &col) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &col) == FAILURE) { RETURN_FALSE; } @@ -4526,7 +4293,7 @@ EXCEL_METHOD(Sheet, setColHidden) long col; zend_bool hidden; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lb", &col, &hidden) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "lb", &col, &hidden) == FAILURE) { RETURN_FALSE; } @@ -4575,7 +4342,7 @@ EXCEL_METHOD(Book, sheetType) BookHandle book; long index; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) { RETURN_FALSE; } @@ -4587,100 +4354,74 @@ EXCEL_METHOD(Book, sheetType) RETURN_LONG(xlBookSheetType(book, index)); } /* }}} */ -#endif -#if PHP_MAJOR_VERSION > 5 || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 3) -# define PHP_EXCEL_ARGINFO -# else -# define PHP_EXCEL_ARGINFO static -#endif -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_load, 0, 0, 1) ZEND_ARG_INFO(0, data) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_loadFile, 0, 0, 1) ZEND_ARG_INFO(0, filename) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_save, 0, 0, 0) ZEND_ARG_INFO(0, filename) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_getSheet, 0, 0, 0) ZEND_ARG_INFO(0, sheet) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_getSheetByName, 0, 0, 1) ZEND_ARG_INFO(0, name) ZEND_ARG_INFO(0, case_insensitive) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_deleteSheet, 0, 0, 1) ZEND_ARG_INFO(0, sheet) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_activeSheet, 0, 0, 0) ZEND_ARG_INFO(0, sheet) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_addSheet, 0, 0, 1) ZEND_ARG_INFO(0, name) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_copySheet, 0, 0, 2) ZEND_ARG_INFO(0, name) ZEND_ARG_INFO(0, sheet_number) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_sheetCount, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_getError, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_addFont, 0, 0, 0) ZEND_ARG_OBJ_INFO(0, font, ExcelFont, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_addFormat, 0, 0, 0) ZEND_ARG_OBJ_INFO(0, format, ExcelFormat, 1) ZEND_END_ARG_INFO() -#ifdef HAVE_LIBXL_243_PLUS -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_getAllFormats, 0, 0, 0) ZEND_END_ARG_INFO() -#endif -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_addCustomFormat, 0, 0, 1) ZEND_ARG_INFO(0, format) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_getCustomFormat, 0, 0, 1) ZEND_ARG_INFO(0, id) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_packDate, 0, 0, 1) ZEND_ARG_INFO(0, timestamp) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_packDateValues, 0, 0, 6) ZEND_ARG_INFO(0, year) ZEND_ARG_INFO(0, month) @@ -4690,351 +4431,272 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_packDateValues, 0, 0, 6) ZEND_ARG_INFO(0, sec) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_unpackDate, 0, 0, 1) ZEND_ARG_INFO(0, date) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_getActiveSheet, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_getDefaultFont, 0, 0, 0) ZEND_END_ARG_INFO() -#if LIBXL_VERSION >= 0x03050300 -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_isDate1904, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_setDate1904, 0, 0, 1) ZEND_ARG_INFO(0, date_type) ZEND_END_ARG_INFO() -#endif -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_setDefaultFont, 0, 0, 2) ZEND_ARG_INFO(0, font) ZEND_ARG_INFO(0, font_size) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_setLocale, 0, 0, 1) ZEND_ARG_INFO(0, locale) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Book___construct, 0, 0, 0) ZEND_ARG_INFO(0, license_name) ZEND_ARG_INFO(0, license_key) ZEND_ARG_INFO(0, excel_2007) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_setActiveSheet, 0, 0, 1) ZEND_ARG_INFO(0, sheet) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_addPictureFromFile, 0, 0, 1) ZEND_ARG_INFO(0, filename) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_addPictureFromString, 0, 0, 1) ZEND_ARG_INFO(0, data) ZEND_END_ARG_INFO() -#ifdef LIBXL_VERSION -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_rgbMode, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_setRGBMode, 0, 0, 1) ZEND_ARG_INFO(0, mode) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_colorPack, 0, 0, 3) ZEND_ARG_INFO(0, r) ZEND_ARG_INFO(0, g) ZEND_ARG_INFO(0, b) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_colorUnpack, 0, 0, 1) ZEND_ARG_INFO(0, color) ZEND_END_ARG_INFO() -#endif -#if LIBXL_VERSION >= 0x03020000 -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_setRefR1C1, 0, 0, 1) ZEND_ARG_INFO(0, active) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_biffVersion, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_getRefR1C1, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_getPicture, 0, 0, 1) ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_getNumPictures, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_insertSheet, 0, 0, 2) ZEND_ARG_INFO(0, index) ZEND_ARG_INFO(0, name) ZEND_ARG_OBJ_INFO(0, sheet, ExcelSheet, 0) ZEND_END_ARG_INFO() -#endif -#if LIBXL_VERSION >= 0x03050401 -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_isTemplate, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_setTemplate, 0, 0, 1) ZEND_ARG_INFO(0, mode) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_getRightToLeft, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_setRightToLeft, 0, 0, 1) ZEND_ARG_INFO(0, mode) ZEND_END_ARG_INFO() -#endif -#if LIBXL_VERSION >= 0x03060000 -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_sheetType, 0, 0, 1) ZEND_ARG_INFO(0, sheet) ZEND_END_ARG_INFO() -#endif -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Font_size, 0, 0, 0) ZEND_ARG_INFO(0, size) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Font_italics, 0, 0, 0) ZEND_ARG_INFO(0, size) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Font_strike, 0, 0, 0) ZEND_ARG_INFO(0, strike) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Font_bold, 0, 0, 0) ZEND_ARG_INFO(0, bold) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Font_color, 0, 0, 0) ZEND_ARG_INFO(0, color) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Font_mode, 0, 0, 0) ZEND_ARG_INFO(0, mode) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Font_underline, 0, 0, 0) ZEND_ARG_INFO(0, underline_style) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Font_name, 0, 0, 0) ZEND_ARG_INFO(0, name) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Format___construct, 0, 0, 1) ZEND_ARG_OBJ_INFO(0, book, ExcelBook, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Font___construct, 0, 0, 1) ZEND_ARG_OBJ_INFO(0, book, ExcelBook, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Format_setFont, 0, 0, 1) ZEND_ARG_OBJ_INFO(0, font, ExcelFont, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Format_getFont, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Format_numberFormat, 0, 0, 0) ZEND_ARG_INFO(0, format) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Format_horizontalAlign, 0, 0, 0) ZEND_ARG_INFO(0, align_mode) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Format_verticalAlign, 0, 0, 0) ZEND_ARG_INFO(0, align_mode) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Format_wrap, 0, 0, 0) ZEND_ARG_INFO(0, wrap) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Format_rotate, 0, 0, 0) ZEND_ARG_INFO(0, angle) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Format_indent, 0, 0, 0) ZEND_ARG_INFO(0, indent) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Format_shrinkToFit, 0, 0, 0) ZEND_ARG_INFO(0, shrink) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Format_borderStyle, 0, 0, 0) ZEND_ARG_INFO(0, style) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Format_borderColor, 0, 0, 0) ZEND_ARG_INFO(0, color) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Format_borderLeftStyle, 0, 0, 0) ZEND_ARG_INFO(0, style) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Format_borderLeftColor, 0, 0, 0) ZEND_ARG_INFO(0, color) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Format_borderRightStyle, 0, 0, 0) ZEND_ARG_INFO(0, style) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Format_borderRightColor, 0, 0, 0) ZEND_ARG_INFO(0, color) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Format_borderTopStyle, 0, 0, 0) ZEND_ARG_INFO(0, style) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Format_borderTopColor, 0, 0, 0) ZEND_ARG_INFO(0, color) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Format_borderBottomStyle, 0, 0, 0) ZEND_ARG_INFO(0, style) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Format_borderBottomColor, 0, 0, 0) ZEND_ARG_INFO(0, color) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Format_borderDiagonalStyle, 0, 0, 0) ZEND_ARG_INFO(0, style) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Format_borderDiagonalColor, 0, 0, 0) ZEND_ARG_INFO(0, color) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Format_fillPattern, 0, 0, 0) ZEND_ARG_INFO(0, patern) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Format_patternForegroundColor, 0, 0, 0) ZEND_ARG_INFO(0, color) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Format_patternBackgroundColor, 0, 0, 0) ZEND_ARG_INFO(0, color) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Format_locked, 0, 0, 0) ZEND_ARG_INFO(0, locked) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Format_hidden, 0, 0, 0) ZEND_ARG_INFO(0, hidden) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet___construct, 0, 0, 2) ZEND_ARG_OBJ_INFO(0, book, ExcelBook, 0) ZEND_ARG_INFO(0, name) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_cellType, 0, 0, 2) ZEND_ARG_INFO(0, row) ZEND_ARG_INFO(0, column) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_cellFormat, 0, 0, 2) ZEND_ARG_INFO(0, row) ZEND_ARG_INFO(0, column) ZEND_END_ARG_INFO() -#ifdef HAVE_LIBXL_243_PLUS -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_setCellFormat, 0, 0, 3) ZEND_ARG_INFO(0, row) ZEND_ARG_INFO(0, column) ZEND_ARG_OBJ_INFO(0, format, ExcelFormat, 0) ZEND_END_ARG_INFO() -#endif -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_readRow, 0, 0, 1) ZEND_ARG_INFO(0, row) ZEND_ARG_INFO(0, start_col) @@ -5042,7 +4704,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_readRow, 0, 0, 1) ZEND_ARG_INFO(0, read_formula) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_readCol, 0, 0, 1) ZEND_ARG_INFO(0, column) ZEND_ARG_INFO(0, start_row) @@ -5050,7 +4711,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_readCol, 0, 0, 1) ZEND_ARG_INFO(0, read_formula) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_read, 0, 0, 2) ZEND_ARG_INFO(0, row) ZEND_ARG_INFO(0, column) @@ -5058,7 +4718,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_read, 0, 0, 2) ZEND_ARG_INFO(0, read_formula) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_write, 0, 0, 3) ZEND_ARG_INFO(0, row) ZEND_ARG_INFO(0, column) @@ -5067,7 +4726,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_write, 0, 0, 3) ZEND_ARG_INFO(0, datatype) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_writeRow, 0, 0, 2) ZEND_ARG_INFO(0, row) ZEND_ARG_INFO(0, data) @@ -5075,7 +4733,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_writeRow, 0, 0, 2) ZEND_ARG_OBJ_INFO(0, format, ExcelFormat, 1) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_writeCol, 0, 0, 2) ZEND_ARG_INFO(0, row) ZEND_ARG_INFO(0, data) @@ -5084,59 +4741,49 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_writeCol, 0, 0, 2) ZEND_ARG_INFO(0, data_type) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_isFormula, 0, 0, 2) ZEND_ARG_INFO(0, row) ZEND_ARG_INFO(0, column) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_isDate, 0, 0, 2) ZEND_ARG_INFO(0, row) ZEND_ARG_INFO(0, column) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_insertRow, 0, 0, 2) ZEND_ARG_INFO(0, row_first) ZEND_ARG_INFO(0, row_last) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_insertCol, 0, 0, 2) ZEND_ARG_INFO(0, col_first) ZEND_ARG_INFO(0, col_last) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_removeRow, 0, 0, 2) ZEND_ARG_INFO(0, row_first) ZEND_ARG_INFO(0, row_last) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_removeCol, 0, 0, 2) ZEND_ARG_INFO(0, col_first) ZEND_ARG_INFO(0, col_last) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_colWidth, 0, 0, 1) ZEND_ARG_INFO(0, column) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_rowHeight, 0, 0, 1) ZEND_ARG_INFO(0, row) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_readComment, 0, 0, 2) ZEND_ARG_INFO(0, row) ZEND_ARG_INFO(0, column) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_writeComment, 0, 0, 6) ZEND_ARG_INFO(0, row) ZEND_ARG_INFO(0, column) @@ -5146,7 +4793,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_writeComment, 0, 0, 6) ZEND_ARG_INFO(0, height) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_setColWidth, 0, 0, 3) ZEND_ARG_INFO(0, column_start) ZEND_ARG_INFO(0, column_end) @@ -5155,7 +4801,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_setColWidth, 0, 0, 3) ZEND_ARG_OBJ_INFO(0, format, ExcelFormat, 1) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_setRowHeight, 0, 0, 2) ZEND_ARG_INFO(0, row) ZEND_ARG_INFO(0, height) @@ -5163,13 +4808,11 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_setRowHeight, 0, 0, 2) ZEND_ARG_INFO(0, hidden) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_getMerge, 0, 0, 2) ZEND_ARG_INFO(0, row) ZEND_ARG_INFO(0, column) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_setMerge, 0, 0, 4) ZEND_ARG_INFO(0, row_start) ZEND_ARG_INFO(0, row_end) @@ -5177,70 +4820,57 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_setMerge, 0, 0, 4) ZEND_ARG_INFO(0, col_end) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_deleteMerge, 0, 0, 2) ZEND_ARG_INFO(0, row) ZEND_ARG_INFO(0, column) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_addPictureScaled, 0, 0, 4) ZEND_ARG_INFO(0, row) ZEND_ARG_INFO(0, column) ZEND_ARG_INFO(0, pic_id) ZEND_ARG_INFO(0, scale) -#if LIBXL_VERSION >= 0x03040000 ZEND_ARG_INFO(0, x_offset) ZEND_ARG_INFO(0, y_offset) -#endif ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_addPictureDim, 0, 0, 5) ZEND_ARG_INFO(0, row) ZEND_ARG_INFO(0, column) ZEND_ARG_INFO(0, pic_id) ZEND_ARG_INFO(0, width) ZEND_ARG_INFO(0, height) -#if LIBXL_VERSION >= 0x03040000 ZEND_ARG_INFO(0, x_offset) ZEND_ARG_INFO(0, y_offset) -#endif ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_horPageBreak, 0, 0, 2) ZEND_ARG_INFO(0, row) ZEND_ARG_INFO(0, break) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_verPageBreak, 0, 0, 2) ZEND_ARG_INFO(0, col) ZEND_ARG_INFO(0, break) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_splitSheet, 0, 0, 2) ZEND_ARG_INFO(0, row) ZEND_ARG_INFO(0, column) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_groupRows, 0, 0, 2) ZEND_ARG_INFO(0, start_row) ZEND_ARG_INFO(0, end_row) ZEND_ARG_INFO(0, collapse) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_groupCols, 0, 0, 2) ZEND_ARG_INFO(0, start_column) ZEND_ARG_INFO(0, end_column) ZEND_ARG_INFO(0, collapse) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_clear, 0, 0, 4) ZEND_ARG_INFO(0, row_s) ZEND_ARG_INFO(0, row_e) @@ -5248,7 +4878,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_clear, 0, 0, 4) ZEND_ARG_INFO(0, col_s) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_copy, 0, 0, 4) ZEND_ARG_INFO(0, row) ZEND_ARG_INFO(0, col) @@ -5256,67 +4885,50 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_copy, 0, 0, 4) ZEND_ARG_INFO(0, to_col) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_firstRow, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_lastRow, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_firstCol, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_lastCol, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_displayGridlines, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_printGridlines, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_setDisplayGridlines, 0, 0, 1) ZEND_ARG_INFO(0, value) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_setPrintGridlines, 0, 0, 1) ZEND_ARG_INFO(0, value) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_zoom, 0, 0, 0) ZEND_END_ARG_INFO() -#if LIBXL_VERSION >= 0x03020300 -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_isHidden, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_setHidden, 0, 0, 1) ZEND_ARG_INFO(0, value) ZEND_END_ARG_INFO() -#endif -#if LIBXL_VERSION >= 0x03020400 -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_getTopLeftView, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_setTopLeftView, 0, 0, 2) ZEND_ARG_INFO(0, row) ZEND_ARG_INFO(0, column) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_rowColToAddr, 0, 0, 2) ZEND_ARG_INFO(0, row) ZEND_ARG_INFO(0, column) @@ -5324,187 +4936,144 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_rowColToAddr, 0, 0, 2) ZEND_ARG_INFO(0, col_relative) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_addrToRowCol, 0, 0, 1) ZEND_ARG_INFO(0, cell_reference) ZEND_END_ARG_INFO() -#endif -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_zoomPrint, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_setZoom, 0, 0, 1) ZEND_ARG_INFO(0, value) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_setZoomPrint, 0, 0, 1) ZEND_ARG_INFO(0, value) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_setLandscape, 0, 0, 1) ZEND_ARG_INFO(0, value) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_landscape, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_paper, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_setPaper, 0, 0, 1) ZEND_ARG_INFO(0, value) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_header, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_footer, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_setHeader, 0, 0, 2) ZEND_ARG_INFO(0, header) ZEND_ARG_INFO(0, margin) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_setFooter, 0, 0, 2) ZEND_ARG_INFO(0, footer) ZEND_ARG_INFO(0, margin) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_headerMargin, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_footerMargin, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_hcenter, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_vcenter, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_setHCenter, 0, 0, 1) ZEND_ARG_INFO(0, value) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_setVCenter, 0, 0, 1) ZEND_ARG_INFO(0, value) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_marginLeft, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_marginRight, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_marginTop, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_marginBottom, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_setMarginLeft, 0, 0, 1) ZEND_ARG_INFO(0, value) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_setMarginRight, 0, 0, 1) ZEND_ARG_INFO(0, value) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_setMarginTop, 0, 0, 1) ZEND_ARG_INFO(0, value) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_setMarginBottom, 0, 0, 1) ZEND_ARG_INFO(0, value) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_printHeaders, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_setPrintHeaders, 0, 0, 1) ZEND_ARG_INFO(0, value) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_name, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_setName, 0, 0, 1) ZEND_ARG_INFO(0, name) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_protect, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_setProtect, 0, 0, 1) ZEND_ARG_INFO(0, value) ZEND_END_ARG_INFO() -#if LIBXL_VERSION >= 0x03010000 -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_setNamedRange, 0, 0, 5) ZEND_ARG_INFO(0, name) ZEND_ARG_INFO(0, row) ZEND_ARG_INFO(0, col) ZEND_ARG_INFO(0, to_row) ZEND_ARG_INFO(0, to_col) -#if LIBXL_VERSION >= 0x03050401 ZEND_ARG_INFO(0, scope_id) -#endif ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_delNamedRange, 0, 0, 1) ZEND_ARG_INFO(0, name) -#if LIBXL_VERSION >= 0x03050401 ZEND_ARG_INFO(0, scope_id) -#endif ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_setPrintRepeatRows, 0, 0, 2) ZEND_ARG_INFO(0, row_start) ZEND_ARG_INFO(0, row_end) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_setPrintRepeatCols, 0, 0, 2) ZEND_ARG_INFO(0, col_start) ZEND_ARG_INFO(0, col_end) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_setPrintArea, 0, 0, 4) ZEND_ARG_INFO(0, row_first) ZEND_ARG_INFO(0, row_last) @@ -5512,108 +5081,79 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_setPrintArea, 0, 0, 4) ZEND_ARG_INFO(0, col_last) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_clearPrintRepeats, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_clearPrintArea, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_getGroupSummaryRight, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_getGroupSummaryBelow, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_setGroupSummaryBelow, 0, 0, 1) ZEND_ARG_INFO(0, direction) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_setGroupSummaryRight, 0, 0, 1) ZEND_ARG_INFO(0, direction) ZEND_END_ARG_INFO() -#endif -#if LIBXL_VERSION >= 0x03020000 -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_setPrintFit, 0, 0, 2) ZEND_ARG_INFO(0, wPages) ZEND_ARG_INFO(0, hPages) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_getPrintFit, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_getNamedRange, 0, 0, 1) ZEND_ARG_INFO(0, name) -#if LIBXL_VERSION >= 0x03050401 ZEND_ARG_INFO(0, scope_id) -#endif ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_getIndexRange, 0, 0, 1) ZEND_ARG_INFO(0, index) -#if LIBXL_VERSION >= 0x03050401 ZEND_ARG_INFO(0, scope_id) -#endif ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_namedRangeSize, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_getVerPageBreak, 0, 0, 1) ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_getVerPageBreakSize, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_getHorPageBreak, 0, 0, 1) ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_getHorPageBreakSize, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_getPictureInfo, 0, 0, 1) ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_getNumPictures, 0, 0, 0) ZEND_END_ARG_INFO() -#endif -#if LIBXL_VERSION >= 0x03060000 -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_hyperlinkSize, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_hyperlink, 0, 0, 1) ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_delHyperlink, 0, 0, 1) ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_addHyperlink, 0, 0, 5) ZEND_ARG_INFO(0, hyperlink) ZEND_ARG_INFO(0, row_first) @@ -5622,60 +5162,48 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_addHyperlink, 0, 0, 5) ZEND_ARG_INFO(0, col_last) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_mergeSize, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_merge, 0, 0, 1) ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_delMergeByIndex, 0, 0, 1) ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_splitInfo, 0, 0, 0) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_colHidden, 0, 0, 1) ZEND_ARG_INFO(0, col) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_rowHidden, 0, 0, 1) ZEND_ARG_INFO(0, row) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_setColHidden, 0, 0, 2) ZEND_ARG_INFO(0, col) ZEND_ARG_INFO(0, hidden) ZEND_END_ARG_INFO() -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_setRowHidden, 0, 0, 2) ZEND_ARG_INFO(0, row) ZEND_ARG_INFO(0, hidden) ZEND_END_ARG_INFO() -#endif -PHP_EXCEL_ARGINFO ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_isLicensed, 0, 0, 0) ZEND_END_ARG_INFO() #define EXCEL_ME(class_name, function_name, arg_info, flags) \ - PHP_ME( Excel ## class_name, function_name, arg_info, flags) + PHP_ME(Excel ## class_name, function_name, arg_info, flags) zend_function_entry excel_funcs_book[] = { EXCEL_ME(Book, addFont, arginfo_Book_addFont, 0) EXCEL_ME(Book, addFormat, arginfo_Book_addFormat, 0) -#ifdef HAVE_LIBXL_243_PLUS EXCEL_ME(Book, getAllFormats, arginfo_Book_getAllFormats, 0) -#endif EXCEL_ME(Book, getError, arginfo_Book_getError, 0) EXCEL_ME(Book, loadFile, arginfo_Book_loadFile, 0) EXCEL_ME(Book, load, arginfo_Book_load, 0) @@ -5699,32 +5227,22 @@ zend_function_entry excel_funcs_book[] = { EXCEL_ME(Book, setLocale, arginfo_Book_setLocale, 0) EXCEL_ME(Book, addPictureFromFile, arginfo_Book_addPictureFromFile, 0) EXCEL_ME(Book, addPictureFromString, arginfo_Book_addPictureFromString, 0) -#ifdef LIBXL_VERSION EXCEL_ME(Book, rgbMode, arginfo_Book_rgbMode, 0) EXCEL_ME(Book, setRGBMode, arginfo_Book_setRGBMode, 0) EXCEL_ME(Book, colorPack, arginfo_Book_colorPack, 0) EXCEL_ME(Book, colorUnpack, arginfo_Book_colorUnpack, 0) -#endif -#if LIBXL_VERSION >= 0x03050300 EXCEL_ME(Book, isDate1904, arginfo_Book_isDate1904, 0) EXCEL_ME(Book, setDate1904, arginfo_Book_setDate1904, 0) -#endif EXCEL_ME(Book, __construct, arginfo_Book___construct, 0) -#if LIBXL_VERSION >= 0x03020000 EXCEL_ME(Book, biffVersion, arginfo_Book_biffVersion, 0) EXCEL_ME(Book, setRefR1C1, arginfo_Book_setRefR1C1, 0) EXCEL_ME(Book, getRefR1C1, arginfo_Book_getRefR1C1, 0) EXCEL_ME(Book, getPicture, arginfo_Book_getPicture, 0) EXCEL_ME(Book, getNumPictures, arginfo_Book_getNumPictures, 0) EXCEL_ME(Book, insertSheet, arginfo_Book_insertSheet, 0) -#endif -#if LIBXL_VERSION >= 0x03050401 EXCEL_ME(Book, isTemplate, arginfo_Book_isTemplate, 0) EXCEL_ME(Book, setTemplate, arginfo_Book_setTemplate, 0) -#endif -#if LIBXL_VERSION >= 0x03060000 EXCEL_ME(Book, sheetType, arginfo_Book_sheetType, 0) -#endif {NULL, NULL, NULL} }; @@ -5732,9 +5250,7 @@ zend_function_entry excel_funcs_sheet[] = { EXCEL_ME(Sheet, __construct, arginfo_Sheet___construct, 0) EXCEL_ME(Sheet, cellType, arginfo_Sheet_cellType, 0) EXCEL_ME(Sheet, cellFormat, arginfo_Sheet_cellFormat, 0) -#ifdef HAVE_LIBXL_243_PLUS EXCEL_ME(Sheet, setCellFormat, arginfo_Sheet_setCellFormat, 0) -#endif EXCEL_ME(Sheet, read, arginfo_Sheet_read, 0) EXCEL_ME(Sheet, readRow, arginfo_Sheet_readRow, 0) EXCEL_ME(Sheet, readCol, arginfo_Sheet_readCol, 0) @@ -5805,7 +5321,6 @@ zend_function_entry excel_funcs_sheet[] = { EXCEL_ME(Sheet, setName, arginfo_Sheet_setName, 0) EXCEL_ME(Sheet, protect, arginfo_Sheet_protect, 0) EXCEL_ME(Sheet, setProtect, arginfo_Sheet_setProtect, 0) -#if LIBXL_VERSION >= 0x03010000 EXCEL_ME(Sheet, setNamedRange, arginfo_Sheet_setNamedRange, 0) EXCEL_ME(Sheet, delNamedRange, arginfo_Sheet_delNamedRange, 0) EXCEL_ME(Sheet, setPrintRepeatRows, arginfo_Sheet_setPrintRepeatRows, 0) @@ -5817,8 +5332,6 @@ zend_function_entry excel_funcs_sheet[] = { EXCEL_ME(Sheet, setGroupSummaryBelow, arginfo_Sheet_setGroupSummaryBelow, 0) EXCEL_ME(Sheet, getGroupSummaryBelow, arginfo_Sheet_getGroupSummaryBelow, 0) EXCEL_ME(Sheet, setGroupSummaryRight, arginfo_Sheet_setGroupSummaryRight, 0) -#endif -#if LIBXL_VERSION >= 0x03020000 EXCEL_ME(Sheet, setPrintFit, arginfo_Sheet_setPrintFit, 0) EXCEL_ME(Sheet, getPrintFit, arginfo_Sheet_getPrintFit, 0) EXCEL_ME(Sheet, getNamedRange, arginfo_Sheet_getNamedRange, 0) @@ -5830,22 +5343,14 @@ zend_function_entry excel_funcs_sheet[] = { EXCEL_ME(Sheet, getHorPageBreakSize, arginfo_Sheet_getHorPageBreakSize, 0) EXCEL_ME(Sheet, getNumPictures, arginfo_Sheet_getNumPictures, 0) EXCEL_ME(Sheet, getPictureInfo, arginfo_Sheet_getPictureInfo, 0) -#endif -#if LIBXL_VERSION >= 0x03020300 EXCEL_ME(Sheet, setHidden, arginfo_Sheet_setHidden, 0) EXCEL_ME(Sheet, isHidden, arginfo_Sheet_isHidden, 0) -#endif -#if LIBXL_VERSION >= 0x03020400 EXCEL_ME(Sheet, setTopLeftView, arginfo_Sheet_setTopLeftView, 0) EXCEL_ME(Sheet, getTopLeftView, arginfo_Sheet_getTopLeftView, 0) EXCEL_ME(Sheet, rowColToAddr, arginfo_Sheet_rowColToAddr, 0) EXCEL_ME(Sheet, addrToRowCol, arginfo_Sheet_addrToRowCol, 0) -#endif -#if LIBXL_VERSION >= 0x03050401 EXCEL_ME(Sheet, getRightToLeft, arginfo_Sheet_getRightToLeft, 0) EXCEL_ME(Sheet, setRightToLeft, arginfo_Sheet_setRightToLeft, 0) -#endif -#if LIBXL_VERSION >= 0x03060000 EXCEL_ME(Sheet, hyperlinkSize, arginfo_Sheet_hyperlinkSize, 0) EXCEL_ME(Sheet, hyperlink, arginfo_Sheet_hyperlink, 0) EXCEL_ME(Sheet, delHyperlink, arginfo_Sheet_delHyperlink, 0) @@ -5859,7 +5364,6 @@ zend_function_entry excel_funcs_sheet[] = { EXCEL_ME(Sheet, rowHidden, arginfo_Sheet_rowHidden, 0) EXCEL_ME(Sheet, setColHidden, arginfo_Sheet_setColHidden, 0) EXCEL_ME(Sheet, setRowHidden, arginfo_Sheet_setRowHidden, 0) -#endif EXCEL_ME(Sheet, isLicensed, arginfo_Sheet_isLicensed, 0) {NULL, NULL, NULL} }; @@ -6068,11 +5572,7 @@ PHP_MINIT_FUNCTION(excel) REGISTER_EXCEL_CLASS_CONST_LONG(format, "FILLPATTERN_GRAY50", FILLPATTERN_GRAY50); REGISTER_EXCEL_CLASS_CONST_LONG(format, "FILLPATTERN_GRAY75", FILLPATTERN_GRAY75); REGISTER_EXCEL_CLASS_CONST_LONG(format, "FILLPATTERN_GRAY25", FILLPATTERN_GRAY25); -#ifdef HAVE_LIBXL_243_PLUS REGISTER_EXCEL_CLASS_CONST_LONG(format, "FILLPATTERN_HORSTRIPE", FILLPATTERN_HORSTRIPE); -#else - REGISTER_EXCEL_CLASS_CONST_LONG(format, "FILLPATTERN_HORSTRIPE", FILLPATTEN_HORSTRIPE); -#endif REGISTER_EXCEL_CLASS_CONST_LONG(format, "FILLPATTERN_VERSTRIPE", FILLPATTERN_VERSTRIPE); REGISTER_EXCEL_CLASS_CONST_LONG(format, "FILLPATTERN_REVDIAGSTRIPE", FILLPATTERN_REVDIAGSTRIPE); REGISTER_EXCEL_CLASS_CONST_LONG(format, "FILLPATTERN_DIAGSTRIPE", FILLPATTERN_DIAGSTRIPE); @@ -6144,7 +5644,6 @@ PHP_MINIT_FUNCTION(excel) REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "PAPER_FANFOLD", PAPER_FANFOLD); REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "PAPER_GERMAN_STD_FANFOLD", PAPER_GERMAN_STD_FANFOLD); REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "PAPER_GERMAN_LEGAL_FANFOLD", PAPER_GERMAN_LEGAL_FANFOLD); -#if LIBXL_VERSION >= 0x03020000 REGISTER_EXCEL_CLASS_CONST_LONG(book, "PICTURETYPE_PNG", PICTURETYPE_PNG); REGISTER_EXCEL_CLASS_CONST_LONG(book, "PICTURETYPE_JPEG", PICTURETYPE_JPEG); REGISTER_EXCEL_CLASS_CONST_LONG(book, "PICTURETYPE_WMF", PICTURETYPE_WMF); @@ -6152,18 +5651,13 @@ PHP_MINIT_FUNCTION(excel) REGISTER_EXCEL_CLASS_CONST_LONG(book, "PICTURETYPE_EMF", PICTURETYPE_EMF); REGISTER_EXCEL_CLASS_CONST_LONG(book, "PICTURETYPE_PICT", PICTURETYPE_PICT); REGISTER_EXCEL_CLASS_CONST_LONG(book, "PICTURETYPE_TIFF", PICTURETYPE_TIFF); -#endif -#if LIBXL_VERSION >= 0x03050401 REGISTER_EXCEL_CLASS_CONST_LONG(book, "SCOPE_UNDEFINED", SCOPE_UNDEFINED); REGISTER_EXCEL_CLASS_CONST_LONG(book, "SCOPE_WORKBOOK", SCOPE_WORKBOOK); REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "RIGHT_TO_LEFT", 1); REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "LEFT_TO_RIGHT", 0); -#endif -#if LIBXL_VERSION >= 0x03060000 REGISTER_EXCEL_CLASS_CONST_LONG(book, "SHEETTYPE_SHEET", SHEETTYPE_SHEET); REGISTER_EXCEL_CLASS_CONST_LONG(book, "SHEETTYPE_CHART", SHEETTYPE_CHART); REGISTER_EXCEL_CLASS_CONST_LONG(book, "SHEETTYPE_UNKNOWN", SHEETTYPE_UNKNOWN); -#endif return SUCCESS; } /* }}} */ diff --git a/tests/002.phpt b/tests/002.phpt index 2f5e928..64e4a16 100644 --- a/tests/002.phpt +++ b/tests/002.phpt @@ -1,5 +1,7 @@ --TEST-- Excel date pack/unpack tests +--INI-- +date.timezone=America/Toronto --SKIPIF-- --FILE-- diff --git a/tests/053.phpt b/tests/053.phpt index e527d51..c1143cf 100644 --- a/tests/053.phpt +++ b/tests/053.phpt @@ -26,139 +26,139 @@ date.timezone=America/Toronto --EXPECT-- array(21) { [0]=> - &object(ExcelFormat)#2 (0) { + object(ExcelFormat)#2 (0) { } [1]=> - &object(ExcelFormat)#3 (0) { + object(ExcelFormat)#3 (0) { } [2]=> - &object(ExcelFormat)#4 (0) { + object(ExcelFormat)#4 (0) { } [3]=> - &object(ExcelFormat)#5 (0) { + object(ExcelFormat)#5 (0) { } [4]=> - &object(ExcelFormat)#6 (0) { + object(ExcelFormat)#6 (0) { } [5]=> - &object(ExcelFormat)#7 (0) { + object(ExcelFormat)#7 (0) { } [6]=> - &object(ExcelFormat)#8 (0) { + object(ExcelFormat)#8 (0) { } [7]=> - &object(ExcelFormat)#9 (0) { + object(ExcelFormat)#9 (0) { } [8]=> - &object(ExcelFormat)#10 (0) { + object(ExcelFormat)#10 (0) { } [9]=> - &object(ExcelFormat)#11 (0) { + object(ExcelFormat)#11 (0) { } [10]=> - &object(ExcelFormat)#12 (0) { + object(ExcelFormat)#12 (0) { } [11]=> - &object(ExcelFormat)#13 (0) { + object(ExcelFormat)#13 (0) { } [12]=> - &object(ExcelFormat)#14 (0) { + object(ExcelFormat)#14 (0) { } [13]=> - &object(ExcelFormat)#15 (0) { + object(ExcelFormat)#15 (0) { } [14]=> - &object(ExcelFormat)#16 (0) { + object(ExcelFormat)#16 (0) { } [15]=> - &object(ExcelFormat)#17 (0) { + object(ExcelFormat)#17 (0) { } [16]=> - &object(ExcelFormat)#18 (0) { + object(ExcelFormat)#18 (0) { } [17]=> - &object(ExcelFormat)#19 (0) { + object(ExcelFormat)#19 (0) { } [18]=> - &object(ExcelFormat)#20 (0) { + object(ExcelFormat)#20 (0) { } [19]=> - &object(ExcelFormat)#21 (0) { + object(ExcelFormat)#21 (0) { } [20]=> - &object(ExcelFormat)#22 (0) { + object(ExcelFormat)#22 (0) { } } bool(false) array(23) { [0]=> - &object(ExcelFormat)#20 (0) { + object(ExcelFormat)#20 (0) { } [1]=> - &object(ExcelFormat)#19 (0) { + object(ExcelFormat)#19 (0) { } [2]=> - &object(ExcelFormat)#18 (0) { + object(ExcelFormat)#18 (0) { } [3]=> - &object(ExcelFormat)#17 (0) { + object(ExcelFormat)#17 (0) { } [4]=> - &object(ExcelFormat)#16 (0) { + object(ExcelFormat)#16 (0) { } [5]=> - &object(ExcelFormat)#15 (0) { + object(ExcelFormat)#15 (0) { } [6]=> - &object(ExcelFormat)#14 (0) { + object(ExcelFormat)#14 (0) { } [7]=> - &object(ExcelFormat)#13 (0) { + object(ExcelFormat)#13 (0) { } [8]=> - &object(ExcelFormat)#12 (0) { + object(ExcelFormat)#12 (0) { } [9]=> - &object(ExcelFormat)#11 (0) { + object(ExcelFormat)#11 (0) { } [10]=> - &object(ExcelFormat)#10 (0) { + object(ExcelFormat)#10 (0) { } [11]=> - &object(ExcelFormat)#9 (0) { + object(ExcelFormat)#9 (0) { } [12]=> - &object(ExcelFormat)#8 (0) { + object(ExcelFormat)#8 (0) { } [13]=> - &object(ExcelFormat)#7 (0) { + object(ExcelFormat)#7 (0) { } [14]=> - &object(ExcelFormat)#6 (0) { + object(ExcelFormat)#6 (0) { } [15]=> - &object(ExcelFormat)#5 (0) { + object(ExcelFormat)#5 (0) { } [16]=> - &object(ExcelFormat)#4 (0) { + object(ExcelFormat)#4 (0) { } [17]=> - &object(ExcelFormat)#3 (0) { + object(ExcelFormat)#3 (0) { } [18]=> - &object(ExcelFormat)#2 (0) { + object(ExcelFormat)#2 (0) { } [19]=> - &object(ExcelFormat)#23 (0) { + object(ExcelFormat)#23 (0) { } [20]=> - &object(ExcelFormat)#24 (0) { + object(ExcelFormat)#24 (0) { } [21]=> - &object(ExcelFormat)#25 (0) { + object(ExcelFormat)#25 (0) { } [22]=> - &object(ExcelFormat)#26 (0) { + object(ExcelFormat)#26 (0) { } } OK From 47cb18871b4c4740eb42251952c06b4879632315 Mon Sep 17 00:00:00 2001 From: Johannes Mueller Date: Mon, 9 Feb 2015 11:14:37 +0100 Subject: [PATCH 08/68] updated README --- README.markdown | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/README.markdown b/README.markdown index ab093cd..a097ac6 100644 --- a/README.markdown +++ b/README.markdown @@ -32,16 +32,21 @@ git clone https://github.com/iliaal/php_excel.git ext/excel # replace with the file path to the extracted libxl files # on a 32-bit platform use -./configure --with-excel --with-libxl-incdir=/libxl-3.6.0.1/include_c --with-libxl-libdir=/libxl-3.6.0.1/lib +./configure --with-excel=shared --with-libxl-incdir=/libxl-3.6.0.1/include_c --with-libxl-libdir=/libxl-3.6.0.1/lib # on a 64-bit platform use -./configure --with-excel --with-libxl-incdir=/libxl-3.6.0.1/include_c --with-libxl-libdir=/libxl-3.6.0.1/lib64 +./configure --with-excel=shared --with-libxl-incdir=/libxl-3.6.0.1/include_c --with-libxl-libdir=/libxl-3.6.0.1/lib64 ``` - + ### Windows Pre-build packages for Windows can be downloaded [here](http://windows.php.net/downloads/pecl/snaps/excel). +### PHP7 + +* requires LibXL 3.6.0+ +* use the php7 branch of the github repo + ## Getting started ``` php From f21da5367c5bea7111fe1177acb475c0893ae10e Mon Sep 17 00:00:00 2001 From: Johannes Mueller Date: Thu, 5 Mar 2015 10:45:34 +0100 Subject: [PATCH 09/68] fixes issue with ExcelSheet::addPictureDim() arguments --- excel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/excel.c b/excel.c index 9382394..3a53f0d 100644 --- a/excel.c +++ b/excel.c @@ -2726,7 +2726,7 @@ EXCEL_METHOD(Sheet, addPictureDim) long row, col, pic_id, w, h; long x_offset = 0, y_offset = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "lllll", &row, &col, &pic_id, &w, &h, &x_offset, &y_offset) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "lllll|ll", &row, &col, &pic_id, &w, &h, &x_offset, &y_offset) == FAILURE) { RETURN_FALSE; } From 99a3db3dfce65affe2ad4198126c2b750724d3f0 Mon Sep 17 00:00:00 2001 From: Johannes Mueller Date: Mon, 30 Mar 2015 23:52:15 +0200 Subject: [PATCH 10/68] removed PHP7 incompatible ENFORCE_SAFE_MODE option for php_stream_open_wrapper() --- excel.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/excel.c b/excel.c index 3a53f0d..7fd7a49 100644 --- a/excel.c +++ b/excel.c @@ -394,7 +394,7 @@ EXCEL_METHOD(Book, loadFile) BOOK_FROM_OBJECT(book, object); - stream = php_stream_open_wrapper(filename_zs->val, "rb", ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL); + stream = php_stream_open_wrapper(filename_zs->val, "rb", REPORT_ERRORS, NULL); if (!stream) { RETURN_FALSE; @@ -435,7 +435,7 @@ EXCEL_METHOD(Book, save) if (filename_zs && filename_zs->len > 0) { int numbytes; - php_stream *stream = php_stream_open_wrapper(filename_zs->val, "wb", ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL); + php_stream *stream = php_stream_open_wrapper(filename_zs->val, "wb", REPORT_ERRORS, NULL); if (!stream) { RETURN_FALSE; @@ -1205,7 +1205,7 @@ static void php_excel_add_picture(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{ if (mode == 1) { ret = xlBookAddPicture2(book, data_zs->val, data_zs->len); } else { - stream = php_stream_open_wrapper(data_zs->val, "rb", ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL); + stream = php_stream_open_wrapper(data_zs->val, "rb", REPORT_ERRORS, NULL); if (!stream) { RETURN_FALSE; From 0a2c7d2be83580c8d3657810acd4b35ff34a1951 Mon Sep 17 00:00:00 2001 From: Johannes Mueller Date: Fri, 25 Sep 2015 22:17:22 +0200 Subject: [PATCH 11/68] adopted changes from master and updated for libxl 3.6.3 --- ChangeLog | 13 +++- excel.c | 209 ++++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 200 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index 690c1c4..688ba84 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,15 @@ -[2014-??-??] - Version 1.0.1 +[2015-??-??] - Version 1.0.2 + * Fixed bug in ExcelSheet::addPictureDim() (see issue #120) + * Fixed bug in ExcelSheet::isLicensed() (see issue #122) + * Added new methods (requires LibXL 3.6.2) + - ExcelBook::setAutoFitArea() + - ExcelBook::printArea() + - ExcelBook::printRepeatCols() + - ExcelBook::printRepeatRows() + * Added support for LibXL 3.6.3 + * ExcelSheet::addPictureDim() & ExcelSheet::addPictureScaled() now support position parameters + +[2015-02-26] - Version 1.0.1 * Added methods - ExcelBook::sheetType() - ExcelSheet::colHidden() diff --git a/excel.c b/excel.c index 7fd7a49..2c421d8 100644 --- a/excel.c +++ b/excel.c @@ -58,7 +58,7 @@ static long xlFormatBorderColor(FormatHandle f) #define PHP_EXCEL_FORMULA 2 #define PHP_EXCEL_NUMERIC_STRING 3 -#define PHP_EXCEL_VERSION "1.0.1dev" +#define PHP_EXCEL_VERSION "1.0.2dev" #ifdef COMPILE_DL_EXCEL ZEND_GET_MODULE(excel) @@ -442,8 +442,8 @@ EXCEL_METHOD(Book, save) } if ((numbytes = php_stream_write(stream, contents, len)) != len) { - php_error_docref(NULL, E_WARNING, "Only %d of %d bytes written, possibly out of free disk space", numbytes, len); php_stream_close(stream); + php_error_docref(NULL, E_WARNING, "Only %d of %d bytes written, possibly out of free disk space", numbytes, len); RETURN_FALSE; } @@ -913,26 +913,38 @@ EXCEL_METHOD(Book, packDateValues) RETURN_FALSE; } - if (year < 1) { - php_error_docref(NULL, E_WARNING, "Invalid '%ld' value for year", year); - RETURN_FALSE; - } else if (month < 1 || month > 12) { - php_error_docref(NULL, E_WARNING, "Invalid '%ld' value for month", month); - RETURN_FALSE; - } else if (day < 1 || day > 31) { - php_error_docref(NULL, E_WARNING, "Invalid '%ld' value for day", day); - RETURN_FALSE; - } else if (hour < 0 || hour > 23) { + // if it is a date or just a time - hout, min & sec must be checked + + if (hour < 0 || hour > 23) { php_error_docref(NULL, E_WARNING, "Invalid '%ld' value for hour", hour); RETURN_FALSE; - } else if (min < 0 || min > 59) { + } + if (min < 0 || min > 59) { php_error_docref(NULL, E_WARNING, "Invalid '%ld' value for minute", min); RETURN_FALSE; - } else if (sec < 0 || sec > 59) { + } + if (sec < 0 || sec > 59) { php_error_docref(NULL, E_WARNING, "Invalid '%ld' value for second", sec); RETURN_FALSE; } + // check date only if there are values + // is every value=0 - it's okay for generating a time + if (year != 0 || month != 0 || day != 0) { + if (year < 1) { + php_error_docref(NULL, E_WARNING, "Invalid '%ld' value for year", year); + RETURN_FALSE; + } + if (month < 1 || month > 12) { + php_error_docref(NULL, E_WARNING, "Invalid '%ld' value for month", month); + RETURN_FALSE; + } + if (day < 1 || day > 31) { + php_error_docref(NULL, E_WARNING, "Invalid '%ld' value for day", day); + RETURN_FALSE; + } + } + BOOK_FROM_OBJECT(book, object); if ((dt = _php_excel_date_pack_values(book, year, month, day, hour, min, sec)) == -1) { @@ -2704,16 +2716,20 @@ EXCEL_METHOD(Sheet, addPictureScaled) SheetHandle sheet; zval *object = getThis(); long row, col, pic_id; - long x_offset = 0, y_offset = 0; + long x_offset = 0, y_offset = 0, pos = 0; double scale; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "llld|ll", &row, &col, &pic_id, &scale, &x_offset, &y_offset) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "llld|lll", &row, &col, &pic_id, &scale, &x_offset, &y_offset, &pos) == FAILURE) { RETURN_FALSE; } SHEET_FROM_OBJECT(sheet, object); - xlSheetSetPicture(sheet, row, col, pic_id, scale, x_offset, y_offset); + xlSheetSetPicture(sheet, row, col, pic_id, scale, x_offset, y_offset +#if LIBXL_VERSION >= 0x03060300 +, pos +#endif + ); } /* }}} */ @@ -2724,15 +2740,19 @@ EXCEL_METHOD(Sheet, addPictureDim) SheetHandle sheet; zval *object = getThis(); long row, col, pic_id, w, h; - long x_offset = 0, y_offset = 0; + long x_offset = 0, y_offset = 0, pos = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "lllll|ll", &row, &col, &pic_id, &w, &h, &x_offset, &y_offset) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "lllll|lll", &row, &col, &pic_id, &w, &h, &x_offset, &y_offset, &pos) == FAILURE) { RETURN_FALSE; } SHEET_FROM_OBJECT(sheet, object); - xlSheetSetPicture2(sheet, row, col, pic_id, w, h, x_offset, y_offset); + xlSheetSetPicture2(sheet, row, col, pic_id, w, h, x_offset, y_offset +#if LIBXL_VERSION >= 0x03060300 +, pos +#endif + ); } /* }}} */ @@ -4355,6 +4375,118 @@ EXCEL_METHOD(Book, sheetType) } /* }}} */ +#if LIBXL_VERSION >= 0x03060200 +/* {{{ proto void ExcelSheet::setAutoFitArea(int rowFirst, int colFirst, int rowLast, int colLast) + Sets the borders for autofit column widths feature. + The function xlSheetSetCol() with -1 width value will + affect only to the specified limited area. */ +EXCEL_METHOD(Sheet, setAutoFitArea) +{ + zval *object = getThis(); + SheetHandle sheet; + long rowFirst=0, colFirst=0, rowLast=-1, colLast=-1; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|llll", &rowFirst, &rowLast, &colFirst, &colLast) == FAILURE) { + RETURN_FALSE; + } + + if (rowFirst < 0) { + RETURN_FALSE; + } + + if (colFirst < 0) { + RETURN_FALSE; + } + + if (rowLast < -1) { + RETURN_FALSE; + } + + if (colLast < -1) { + RETURN_FALSE; + } + + SHEET_FROM_OBJECT(sheet, object); + + xlSheetSetAutoFitArea(sheet, rowFirst, colFirst, rowLast, colLast); + RETURN_TRUE; +} +/* }}} */ + +/* {{{ proto long ExcelSheet::printRepeatRows() + Gets repeated rows on each page from rowFirst to rowLast. + Returns 0 if repeated rows aren't found. */ +EXCEL_METHOD(Sheet, printRepeatRows) +{ + zval *object = getThis(); + SheetHandle sheet; + int rowFirst, rowLast; + + if (ZEND_NUM_ARGS()) { + RETURN_FALSE; + } + + SHEET_FROM_OBJECT(sheet, object); + + if (!xlSheetPrintRepeatRows(sheet, &rowFirst, &rowLast)) { + RETURN_FALSE; + } + + array_init(return_value); + add_assoc_long(return_value, "row_start", rowFirst); + add_assoc_long(return_value, "row_end", rowLast); +} +/* }}} */ + +/* {{{ proto long ExcelSheet::printRepeatCols() + Gets repeated columns on each page from colFirst to colLast. + Returns 0 if repeated columns aren't found. */ +EXCEL_METHOD(Sheet, printRepeatCols) +{ + zval *object = getThis(); + SheetHandle sheet; + int colFirst, colLast; + + if (ZEND_NUM_ARGS()) { + RETURN_FALSE; + } + + SHEET_FROM_OBJECT(sheet, object); + + if (!xlSheetPrintRepeatCols(sheet, &colFirst, &colLast)) { + RETURN_FALSE; + } + + array_init(return_value); + add_assoc_long(return_value, "col_start", colFirst); + add_assoc_long(return_value, "col_end", colLast); +} +/* }}} */ + +/* {{{ proto long ExcelSheet::printArea() + Gets the print area. Returns 0 if print area isn't found. */ +EXCEL_METHOD(Sheet, printArea) +{ + zval *object = getThis(); + SheetHandle sheet; + int rowFirst, colFirst, rowLast, colLast; + + SHEET_FROM_OBJECT(sheet, object); + + if (!xlSheetPrintArea(sheet, &rowFirst, &colFirst, &rowLast, &colLast)) { + RETURN_FALSE; + } + + array_init(return_value); + add_assoc_long(return_value, "row_start", rowFirst); + add_assoc_long(return_value, "col_start", colFirst); + add_assoc_long(return_value, "row_end", rowLast); + add_assoc_long(return_value, "col_end", colLast); +} +/* }}} */ + +#endif + ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_load, 0, 0, 1) ZEND_ARG_INFO(0, data) ZEND_END_ARG_INFO() @@ -4832,6 +4964,9 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_addPictureScaled, 0, 0, 4) ZEND_ARG_INFO(0, scale) ZEND_ARG_INFO(0, x_offset) ZEND_ARG_INFO(0, y_offset) +#if LIBXL_VERSION >= 0x03060300 + ZEND_ARG_INFO(0, pos) +#endif ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_addPictureDim, 0, 0, 5) @@ -4842,7 +4977,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_addPictureDim, 0, 0, 5) ZEND_ARG_INFO(0, height) ZEND_ARG_INFO(0, x_offset) ZEND_ARG_INFO(0, y_offset) -ZEND_END_ARG_INFO() +#if LIBXL_VERSION >= 0x03060300 + ZEND_ARG_INFO(0, pos) +#endif + ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_horPageBreak, 0, 0, 2) ZEND_ARG_INFO(0, row) @@ -5197,6 +5335,24 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_isLicensed, 0, 0, 0) ZEND_END_ARG_INFO() +#if LIBXL_VERSION >= 0x03060200 +ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_setAutoFitArea, 0, 0, 0) + ZEND_ARG_INFO(0, row_start) + ZEND_ARG_INFO(0, row_end) + ZEND_ARG_INFO(0, col_start) + ZEND_ARG_INFO(0, col_end) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_printRepeatRows, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_printRepeatCols, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_printArea, 0, 0, 0) +ZEND_END_ARG_INFO() +#endif + #define EXCEL_ME(class_name, function_name, arg_info, flags) \ PHP_ME(Excel ## class_name, function_name, arg_info, flags) @@ -5365,6 +5521,12 @@ zend_function_entry excel_funcs_sheet[] = { EXCEL_ME(Sheet, setColHidden, arginfo_Sheet_setColHidden, 0) EXCEL_ME(Sheet, setRowHidden, arginfo_Sheet_setRowHidden, 0) EXCEL_ME(Sheet, isLicensed, arginfo_Sheet_isLicensed, 0) +#if LIBXL_VERSION >= 0x03060200 + EXCEL_ME(Sheet, setAutoFitArea, arginfo_Sheet_setAutoFitArea, 0) + EXCEL_ME(Sheet, printRepeatRows, arginfo_Sheet_printRepeatRows, 0) + EXCEL_ME(Sheet, printRepeatCols, arginfo_Sheet_printRepeatCols, 0) + EXCEL_ME(Sheet, printArea, arginfo_Sheet_printArea, 0) +#endif {NULL, NULL, NULL} }; @@ -5658,6 +5820,11 @@ PHP_MINIT_FUNCTION(excel) REGISTER_EXCEL_CLASS_CONST_LONG(book, "SHEETTYPE_SHEET", SHEETTYPE_SHEET); REGISTER_EXCEL_CLASS_CONST_LONG(book, "SHEETTYPE_CHART", SHEETTYPE_CHART); REGISTER_EXCEL_CLASS_CONST_LONG(book, "SHEETTYPE_UNKNOWN", SHEETTYPE_UNKNOWN); +#if LIBXL_VERSION >= 0x03060300 + REGISTER_EXCEL_CLASS_CONST_LONG(book, "POSITION_MOVE_AND_SIZE", POSITION_MOVE_AND_SIZE); + REGISTER_EXCEL_CLASS_CONST_LONG(book, "POSITION_ONLY_MOVE", POSITION_ONLY_MOVE); + REGISTER_EXCEL_CLASS_CONST_LONG(book, "POSITION_ABSOLUTE", POSITION_ABSOLUTE); +#endif return SUCCESS; } /* }}} */ From 75ba0a0d85ce3aa78043646b5d2cd91c5a027bed Mon Sep 17 00:00:00 2001 From: Johannes Mueller Date: Fri, 6 Nov 2015 23:06:55 +0100 Subject: [PATCH 12/68] force string behaviour with single quote --- excel.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/excel.c b/excel.c index 2c421d8..39a10c3 100644 --- a/excel.c +++ b/excel.c @@ -2268,7 +2268,9 @@ zend_bool php_excel_write_cell(SheetHandle sheet, BookHandle book, int row, int case IS_STRING: data_zs = Z_STR_P(data); - + if (Z_STRLEN_P(data) > 0 && '\'' == Z_STRVAL_P(data)[0]) { + return xlSheetWriteStr(sheet, row, col, (const char*) data_zs->val, format); + } if (Z_STRLEN_P(data) > 0 && '=' == Z_STRVAL_P(data)[0]) { dtype = PHP_EXCEL_FORMULA; } From e14c430418b0be5843019d15297ec8557f269801 Mon Sep 17 00:00:00 2001 From: Johannes Mueller Date: Fri, 6 Nov 2015 23:09:00 +0100 Subject: [PATCH 13/68] added test --- excel.c | 2 +- tests/089.phpt | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 tests/089.phpt diff --git a/excel.c b/excel.c index 39a10c3..3fa0115 100644 --- a/excel.c +++ b/excel.c @@ -2269,7 +2269,7 @@ zend_bool php_excel_write_cell(SheetHandle sheet, BookHandle book, int row, int case IS_STRING: data_zs = Z_STR_P(data); if (Z_STRLEN_P(data) > 0 && '\'' == Z_STRVAL_P(data)[0]) { - return xlSheetWriteStr(sheet, row, col, (const char*) data_zs->val, format); + return xlSheetWriteStr(sheet, row, col, (const char*) data_zs->val + 1, format); } if (Z_STRLEN_P(data) > 0 && '=' == Z_STRVAL_P(data)[0]) { dtype = PHP_EXCEL_FORMULA; diff --git a/tests/089.phpt b/tests/089.phpt new file mode 100644 index 0000000..a2fedae --- /dev/null +++ b/tests/089.phpt @@ -0,0 +1,37 @@ +--TEST-- +force string behaviout with single quoted strings +--INI-- +date.timezone=America/Toronto +--SKIPIF-- + +--FILE-- +setLocale('UTF-8'); + $xs = new ExcelSheet($xb, 'test'); + + var_dump($xs->write(1, 1, "'=3+4")); + var_dump($xs->write(1, 2, "'")); + var_dump($xs->write(1, 3, "'3")); + + var_dump($xs->isFormula(1, 1)); + var_dump($xs->isFormula(1, 2)); + var_dump($xs->isFormula(1, 3)); + + var_dump($xs->read(1, 1)); + var_dump($xs->read(1, 2)); + var_dump($xs->read(1, 3)); + + echo "OK\n"; +?> +--EXPECT-- +bool(true) +bool(true) +bool(true) +bool(false) +bool(false) +bool(false) +string(5) "=3+4" +string(1) "" +string(2) "3" +OK From 74d0b87f5709221d6a4f67c8ed5c8915b9db6ae2 Mon Sep 17 00:00:00 2001 From: Johannes Mueller Date: Sat, 14 Nov 2015 22:49:25 +0100 Subject: [PATCH 14/68] fixed type mismatch in is_numeric_string() --- excel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/excel.c b/excel.c index 3fa0115..4b8ff05 100644 --- a/excel.c +++ b/excel.c @@ -2278,7 +2278,7 @@ zend_bool php_excel_write_cell(SheetHandle sheet, BookHandle book, int row, int return xlSheetWriteFormula(sheet, row, col, Z_STRVAL_P(data), format); } else { if (dtype == PHP_EXCEL_NUMERIC_STRING) { - long lval; + zend_long lval; double dval; switch (is_numeric_string(Z_STRVAL_P(data), Z_STRLEN_P(data), &lval, &dval, 0)) { From 09c97f25c3129a160015229e7c3175e43f1bd797 Mon Sep 17 00:00:00 2001 From: Philip Hofstetter Date: Wed, 18 Nov 2015 11:42:04 +0100 Subject: [PATCH 15/68] fix a multitude of segfaults PHP7 requires the zend_object in the backing structs to come last which is also reflected by the various fetch_object functions that all subtract from the zend_object pointer. --- excel.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/excel.c b/excel.c index 4b8ff05..89847bc 100644 --- a/excel.c +++ b/excel.c @@ -95,8 +95,8 @@ static zend_object_handlers excel_object_handlers_format; static zend_object_handlers excel_object_handlers_font; typedef struct _excel_book_object { - zend_object std; BookHandle book; + zend_object std; } excel_book_object; static inline excel_book_object *php_excel_book_object_fetch_object(zend_object *obj) { @@ -116,9 +116,9 @@ static inline excel_book_object *php_excel_book_object_fetch_object(zend_object } typedef struct _excel_sheet_object { - zend_object std; SheetHandle sheet; BookHandle book; + zend_object std; } excel_sheet_object; static inline excel_sheet_object *php_excel_sheet_object_fetch_object(zend_object *obj) { @@ -149,9 +149,9 @@ static inline excel_sheet_object *php_excel_sheet_object_fetch_object(zend_objec } typedef struct _excel_font_object { - zend_object std; FontHandle font; BookHandle book; + zend_object std; } excel_font_object; static inline excel_font_object *php_excel_font_object_fetch_object(zend_object *obj) { @@ -180,9 +180,9 @@ static inline excel_font_object *php_excel_font_object_fetch_object(zend_object } typedef struct _excel_format_object { - zend_object std; FormatHandle format; BookHandle book; + zend_object std; } excel_format_object; static inline excel_format_object *php_excel_format_object_fetch_object(zend_object *obj) { From 6430a3bbe80ef113eaf65b7bf7f51e6361867122 Mon Sep 17 00:00:00 2001 From: Philip Hofstetter Date: Thu, 19 Nov 2015 09:34:13 +0100 Subject: [PATCH 16/68] properly support libxl built from source code if you license libxl with source code and build your own copy, then it won't export the xlBookSetKey symbol. Detect this and don't call the function in that case. --- config.m4 | 5 +++++ excel.c | 28 ++++++++++++++++------------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/config.m4 b/config.m4 index 5a2d286..94426e9 100644 --- a/config.m4 +++ b/config.m4 @@ -86,6 +86,11 @@ if test "$PHP_EXCEL" != "no"; then -L$EXCEL_LIBDIR ]) + PHP_CHECK_LIBRARY(xl,xlBookSetKeyA, + [ + AC_DEFINE(HAVE_LIBXL_SETKEY,1,[ ]) + ],[],[]) + if test `grep -c FILLPATTERN_HORSTRIPE $EXCEL_INCDIR/enum.h` -eq 1; then AC_DEFINE(HAVE_LIBXL_243_PLUS,1,[ ]) fi diff --git a/excel.c b/excel.c index 89847bc..d08d763 100644 --- a/excel.c +++ b/excel.c @@ -1135,6 +1135,20 @@ EXCEL_METHOD(Book, __construct) RETURN_FALSE; } + BOOK_FROM_OBJECT(book, object); + + if (new_excel) { + excel_book_object *obj = (excel_book_object*) Z_EXCEL_BOOK_OBJ_P(object); + if ((book = xlCreateXMLBook())) { + xlBookRelease(obj->book); + obj->book = book; + } else { + RETURN_FALSE; + } + } + +#if defined(HAVE_LIBXL_SETKEY) + if (INI_STR("excel.license_name") && INI_STR("excel.license_key")) { name = INI_STR("excel.license_name"); name_len = strlen(name); @@ -1160,19 +1174,9 @@ EXCEL_METHOD(Book, __construct) RETURN_FALSE; } - BOOK_FROM_OBJECT(book, object); - - if (new_excel) { - excel_book_object *obj = (excel_book_object*) Z_EXCEL_BOOK_OBJ_P(object); - if ((book = xlCreateXMLBook())) { - xlBookRelease(obj->book); - obj->book = book; - } else { - RETURN_FALSE; - } - } - xlBookSetKey(book, name_zs->val, key_zs->val); + +#endif } /* }}} */ From acc248fc1be7f333eba43a4f8a4a6462ecc7356e Mon Sep 17 00:00:00 2001 From: Philip Hofstetter Date: Thu, 19 Nov 2015 09:59:13 +0100 Subject: [PATCH 17/68] remove license ini settings if they are not needed --- excel.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/excel.c b/excel.c index d08d763..2a818b9 100644 --- a/excel.c +++ b/excel.c @@ -69,8 +69,10 @@ ZEND_DECLARE_MODULE_GLOBALS(excel) static PHP_GINIT_FUNCTION(excel); PHP_INI_BEGIN() +#if defined(HAVE_LIBXL_SETKEY) STD_PHP_INI_ENTRY("excel.license_name", NULL, PHP_INI_ALL, OnUpdateString, ini_license_name, zend_excel_globals, excel_globals) STD_PHP_INI_ENTRY("excel.license_key", NULL, PHP_INI_ALL, OnUpdateString, ini_license_key, zend_excel_globals, excel_globals) +#endif STD_PHP_INI_ENTRY("excel.skip_empty", "0", PHP_INI_ALL, OnUpdateLong, ini_skip_empty, zend_excel_globals, excel_globals) PHP_INI_END() From 5054ee29a95cd914ecb1997a8280d66b403ddc1c Mon Sep 17 00:00:00 2001 From: Philip Hofstetter Date: Thu, 19 Nov 2015 09:59:50 +0100 Subject: [PATCH 18/68] skip trial version related tests on source-code licensed libs this fixes the tests failing for people who use libxl licensed with source code. This also adds a static method `requiresKey` to ExcelBook in order to check whether a license key is required or not --- excel.c | 16 ++++++++++++++++ tests/000.phpt | 2 +- tests/086.phpt | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/excel.c b/excel.c index 2a818b9..f34ca74 100644 --- a/excel.c +++ b/excel.c @@ -354,6 +354,18 @@ static zend_object *excel_format_object_clone(zval *this_ptr) #define EXCEL_METHOD(class_name, function_name) \ PHP_METHOD(Excel ## class_name, function_name) +/* {{{ proto bool ExcelBook::requiresKey() + true if license key is required. */ +EXCEL_METHOD(Book, requiresKey) +{ +#if defined(HAVE_LIBXL_SETKEY) + RETURN_BOOL(1); +#else + RETURN_BOOL(0); +#endif +} +/* }}} */ + /* {{{ proto bool ExcelBook::load(string data) Load Excel data string. */ EXCEL_METHOD(Book, load) @@ -4495,6 +4507,9 @@ EXCEL_METHOD(Sheet, printArea) #endif +ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_requiresKey, 0, 0, 0) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_load, 0, 0, 1) ZEND_ARG_INFO(0, data) ZEND_END_ARG_INFO() @@ -5365,6 +5380,7 @@ ZEND_END_ARG_INFO() PHP_ME(Excel ## class_name, function_name, arg_info, flags) zend_function_entry excel_funcs_book[] = { + EXCEL_ME(Book, requiresKey, arginfo_Book_requiresKey, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) EXCEL_ME(Book, addFont, arginfo_Book_addFont, 0) EXCEL_ME(Book, addFormat, arginfo_Book_addFormat, 0) EXCEL_ME(Book, getAllFormats, arginfo_Book_getAllFormats, 0) diff --git a/tests/000.phpt b/tests/000.phpt index ab9d5eb..07ebcc2 100644 --- a/tests/000.phpt +++ b/tests/000.phpt @@ -3,7 +3,7 @@ LibXL licensed version vs trial version test --INI-- date.timezone=America/Toronto --SKIPIF-- - + --FILE-- + --FILE-- Date: Thu, 19 Nov 2015 10:47:15 +0100 Subject: [PATCH 19/68] update tests for PHP7 --- tests/020.phpt | 10 +++++----- tests/021.phpt | 11 ++++++----- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/tests/020.phpt b/tests/020.phpt index c2f0ed5..87d3d04 100644 --- a/tests/020.phpt +++ b/tests/020.phpt @@ -5,18 +5,18 @@ date.timezone=America/Toronto --SKIPIF-- --FILE-- -getMessage()); } try { $format = new ExcelFormat('cdsd'); - } catch (Exception $e) { + } catch (Throwable $e) { var_dump($e->getMessage()); } @@ -24,5 +24,5 @@ date.timezone=America/Toronto ?> --EXPECTF-- string(63) "ExcelFormat::__construct() expects exactly 1 parameter, 0 given" - -Catchable fatal error: Argument 1 passed to ExcelFormat::__construct() must be an instance of ExcelBook, string given in %s on line %d +string(94) "Argument 1 passed to ExcelFormat::__construct() must be an instance of ExcelBook, string given" +OK diff --git a/tests/021.phpt b/tests/021.phpt index 64b529d..3467690 100644 --- a/tests/021.phpt +++ b/tests/021.phpt @@ -5,22 +5,23 @@ date.timezone=America/Toronto --SKIPIF-- --FILE-- -getMessage()); } try { $format = new ExcelFont('cdsd'); - } catch (Exception $e) { + } catch (Throwable $e) { var_dump($e->getMessage()); } + echo "OK\n" ?> --EXPECTF-- string(61) "ExcelFont::__construct() expects exactly 1 parameter, 0 given" - -Catchable fatal error: Argument 1 passed to ExcelFont::__construct() must be an instance of ExcelBook, string given in %s on line %d +string(92) "Argument 1 passed to ExcelFont::__construct() must be an instance of ExcelBook, string given" +OK From 853bcd0b1a6e6eda85f4cc93b74734c85470ccfd Mon Sep 17 00:00:00 2001 From: Philip Hofstetter Date: Thu, 19 Nov 2015 10:53:23 +0100 Subject: [PATCH 20/68] fix character counts in test output --- tests/089.phpt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/089.phpt b/tests/089.phpt index a2fedae..7678d6b 100644 --- a/tests/089.phpt +++ b/tests/089.phpt @@ -31,7 +31,7 @@ bool(true) bool(false) bool(false) bool(false) -string(5) "=3+4" -string(1) "" -string(2) "3" +string(4) "=3+4" +string(0) "" +string(1) "3" OK From 6fcd0ba6266f030c9ce2a74c434e4097ed82e3de Mon Sep 17 00:00:00 2001 From: Johannes Mueller Date: Sun, 29 Nov 2015 21:17:40 +0100 Subject: [PATCH 21/68] removed libxml2 dependencies and described a solution for multibyte credentials in README --- README.markdown | 18 +++++++++++++----- excel.c | 27 ++++----------------------- 2 files changed, 17 insertions(+), 28 deletions(-) diff --git a/README.markdown b/README.markdown index a097ac6..c8f21c1 100644 --- a/README.markdown +++ b/README.markdown @@ -117,12 +117,20 @@ in Excel or using the COM classes to open and save the Excel file via PHP. (**In ### 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 your credentials do not work properly because of multibyte characters you can extend ExcelBook +class and circumvent the build-in mechanism for ```php.ini``` settings. -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```. + len > 0 && key_zs && key_zs->len > 0) { - name = name_zs->val; - name_len = (int) name_zs->len; - key = key_zs->val; - key_len = (int) key_zs->len; - } - -#if defined(HAVE_XML) && defined(EXCEL_WITH_LIBXML) - if (name_len > 0 && key_len > 0) { - name_zs = xml_utf8_decode((const XML_Char *) name, name_len, "ISO-8859-1"); - key_zs = xml_utf8_decode((const XML_Char *) key, key_len, "ISO-8859-1"); - } -#endif - - if (!name_zs || name_zs->len < 1 || !key_zs || key_zs->len < 1) { + if (!name || name_len < 1 || !key || key_len < 1) { RETURN_FALSE; } @@ -1172,7 +1153,7 @@ EXCEL_METHOD(Book, __construct) } } - xlBookSetKey(book, name_zs->val, key_zs->val); + xlBookSetKey(book, name, key); } /* }}} */ From cb1eb02fbc306fa3bfe857f65c0d6a4fd088a4d1 Mon Sep 17 00:00:00 2001 From: Johannes Mueller Date: Sun, 29 Nov 2015 21:21:17 +0100 Subject: [PATCH 22/68] added link to pre-build win binaries --- README.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index c8f21c1..2de171a 100644 --- a/README.markdown +++ b/README.markdown @@ -40,7 +40,7 @@ git clone https://github.com/iliaal/php_excel.git ext/excel ### Windows -Pre-build packages for Windows can be downloaded [here](http://windows.php.net/downloads/pecl/snaps/excel). +Pre-build packages for Windows can be downloaded [here](http://windows.php.net/downloads/pecl/snaps/excel) or [here](https://www.apachelounge.com/viewtopic.php?t=6617). ### PHP7 From 3264cc2b85d7331637ae747c9c68e098d1178b45 Mon Sep 17 00:00:00 2001 From: Johannes Mueller Date: Sun, 29 Nov 2015 21:23:06 +0100 Subject: [PATCH 23/68] changed README --- README.markdown | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/README.markdown b/README.markdown index 2de171a..02e9d32 100644 --- a/README.markdown +++ b/README.markdown @@ -120,17 +120,19 @@ in Excel or using the COM classes to open and save the Excel file via PHP. (**In If your credentials do not work properly because of multibyte characters you can extend ExcelBook class and circumvent the build-in mechanism for ```php.ini``` settings. - Date: Thu, 17 Mar 2016 21:31:49 +0100 Subject: [PATCH 24/68] Fix for coredump when passing valid user name and user key with constructor --- excel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/excel.c b/excel.c index bb4274c..49c89ca 100644 --- a/excel.c +++ b/excel.c @@ -1123,7 +1123,7 @@ EXCEL_METHOD(Book, __construct) BookHandle book; zval *object = getThis(); char *name = NULL, *key; - int name_len = 0, key_len = 0; + zend_long name_len = 0, key_len = 0; zend_bool new_excel = 0; if (zend_parse_parameters(ZEND_NUM_ARGS(), "|ssb", &name, &name_len, &key, &key_len, &new_excel) == FAILURE) { From c6b6fb2fac2504235808b92311480e2dcf64dd71 Mon Sep 17 00:00:00 2001 From: Johannes Mueller Date: Sun, 20 Mar 2016 17:22:33 +0100 Subject: [PATCH 25/68] changed type from zend_long to size_t --- excel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/excel.c b/excel.c index 49c89ca..a059884 100644 --- a/excel.c +++ b/excel.c @@ -1123,7 +1123,7 @@ EXCEL_METHOD(Book, __construct) BookHandle book; zval *object = getThis(); char *name = NULL, *key; - zend_long name_len = 0, key_len = 0; + size_t name_len = 0, key_len = 0; zend_bool new_excel = 0; if (zend_parse_parameters(ZEND_NUM_ARGS(), "|ssb", &name, &name_len, &key, &key_len, &new_excel) == FAILURE) { From 810511c48a5b66331ec14d81b090233ffa958fa5 Mon Sep 17 00:00:00 2001 From: Johannes Mueller Date: Sun, 20 Mar 2016 17:27:35 +0100 Subject: [PATCH 26/68] updated README --- README.markdown | 47 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/README.markdown b/README.markdown index 02e9d32..18ecfe0 100644 --- a/README.markdown +++ b/README.markdown @@ -4,7 +4,7 @@ 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, +able to generate output readable on Blackberries, iPhone, Office Products, Numbers, etc... ## Documentation @@ -22,25 +22,26 @@ Please see the ```docs/``` and the ```tests/``` directory. ``` shell # change into php source files directory -cd php-5.x.x +cd php-7.x.x # clone repository into php extension dir -git clone https://github.com/iliaal/php_excel.git ext/excel +git clone https://github.com/johmue/php_excel -b php7 ext/excel # rebuild configure ./buildconf --force # replace with the file path to the extracted libxl files # on a 32-bit platform use -./configure --with-excel=shared --with-libxl-incdir=/libxl-3.6.0.1/include_c --with-libxl-libdir=/libxl-3.6.0.1/lib +./configure --with-excel=shared --with-libxl-incdir=/libxl-3.6.5.0/include_c --with-libxl-libdir=/libxl-3.6.5.0/lib # on a 64-bit platform use -./configure --with-excel=shared --with-libxl-incdir=/libxl-3.6.0.1/include_c --with-libxl-libdir=/libxl-3.6.0.1/lib64 +./configure --with-excel=shared --with-libxl-incdir=/libxl-3.6.5.0/include_c --with-libxl-libdir=/libxl-3.6.5.0/lib64 ``` ### Windows -Pre-build packages for Windows can be downloaded [here](http://windows.php.net/downloads/pecl/snaps/excel) or [here](https://www.apachelounge.com/viewtopic.php?t=6617). +Pre-build packages for Windows can be downloaded [here](https://www.apachelounge.com/viewtopic.php?t=6617). To build the package for +Windows on your own you may want to visit this [project](https://github.com/johmue/win-php-sdk-builder). ### PHP7 @@ -51,7 +52,7 @@ Pre-build packages for Windows can be downloaded [here](http://windows.php.net/d ``` php ', '', $useXlsxFormat); @@ -110,10 +111,27 @@ excel.skip_empty=0 ### 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!**) +if you create an Excel sheet with php_excel and write a formula like ```=SUM(A1:B1)``` in cell ```C1``` you cannot +read the value of the calculation by reading cell ```C1``` in a later step. There have been observations that +this can also affect the OS pre-view of Excel files which rely on values. You can circumvent this by opening and saving the file directly +in Excel by using the [COM](http://de2.php.net/manual/en/class.com.php) or [DOTNET](http://de2.php.net/manual/en/class.dotnet.php) +interface. (**Excel is required!**) + +``` php +/** + * if you are having trouble try adding usleep(1000000) between the steps + * for a pause of 1s or kill running Excel tasks beforehand e.g. with PHP on Windows + * exec('TASKKILL /F /FI "IMAGENAME eq EXCEL.EXE" /T', $out); + */ + +$workbook = realpath($file); +$excelHandler = new \COM("Excel.sheet") or die('Failed to connect Excel COM handler in file '.__FILE__.' on line '.__LINE__); +$excelHandler->Application->Workbooks->Open($workbook) or die('Failed to open Excel Workbook '.$file.' in file '.__FILE__.' on line '.__LINE__); +$excelHandler->Application->ActiveWorkbook->Save(); +$excelHandler->Application->ActiveWorkbook->Close(); +$excelHandler->Application->Quit(); +$excelHandler = null; +``` ### multibyte characters in credentials @@ -127,9 +145,12 @@ class MyExcelBook extends \ExcelBook { public function __construct($license_name=null, $license_key=null, $new_excel=false) { - $license_name = utf8_decode(get_cfg_var('excel.license_name')); - $license_key = utf8_decode(get_cfg_var('excel.license_key')); + if (null === $license_name) { + $license_name = utf8_decode(get_cfg_var('excel.license_name')); + $license_key = utf8_decode(get_cfg_var('excel.license_key')); + } parent::__construct($license_name, $license_key, $new_excel); + $this->setLocale('UTF-8'); } } ``` From e81a522b69d0ac7f3b3fc6f293c29700dcd2b3f1 Mon Sep 17 00:00:00 2001 From: Johannes Mueller Date: Fri, 29 Apr 2016 22:31:59 +0200 Subject: [PATCH 27/68] fixes issue #160 --- excel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/excel.c b/excel.c index a059884..808f1da 100644 --- a/excel.c +++ b/excel.c @@ -2126,7 +2126,7 @@ EXCEL_METHOD(Sheet, readCol) BookHandle book; zend_bool read_formula = 1; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|ll", &col, &row_start, &row_end, &read_formula) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|llb", &col, &row_start, &row_end, &read_formula) == FAILURE) { RETURN_FALSE; } From 32d5cac2c8ae7a08a3236929d65f018a1574921e Mon Sep 17 00:00:00 2001 From: Johannes Mueller Date: Sun, 8 May 2016 22:19:40 +0200 Subject: [PATCH 28/68] adresses issue #151 --- excel.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/excel.c b/excel.c index 808f1da..a8a35e2 100644 --- a/excel.c +++ b/excel.c @@ -2281,6 +2281,18 @@ zend_bool php_excel_write_cell(SheetHandle sheet, BookHandle book, int row, int case IS_FALSE: return xlSheetWriteBool(sheet, row, col, 0, format); + + case IS_ARRAY: + php_error_docref(NULL, E_WARNING, "Type mismatch: array not supported for atomic write operation in row %d, column %d", row, col); + return 1; + + case IS_OBJECT: + php_error_docref(NULL, E_WARNING, "Type mismatch: object not supported for atomic write operation in row %d, column %d", row, col); + return 1; + + case IS_RESOURCE: + php_error_docref(NULL, E_WARNING, "Type mismatch: resource not supported for atomic write operation in row %d, column %d", row, col); + return 1; } return 0; From 7b40551d06e55063af723cbec266f4d020f84c3c Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Wed, 22 Jun 2016 17:04:48 -0400 Subject: [PATCH 29/68] Fixed tests --- tests/088.phpt | 6 +++--- tests/089.phpt | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/088.phpt b/tests/088.phpt index a2fedae..7678d6b 100644 --- a/tests/088.phpt +++ b/tests/088.phpt @@ -31,7 +31,7 @@ bool(true) bool(false) bool(false) bool(false) -string(5) "=3+4" -string(1) "" -string(2) "3" +string(4) "=3+4" +string(0) "" +string(1) "3" OK diff --git a/tests/089.phpt b/tests/089.phpt index a2fedae..7678d6b 100644 --- a/tests/089.phpt +++ b/tests/089.phpt @@ -31,7 +31,7 @@ bool(true) bool(false) bool(false) bool(false) -string(5) "=3+4" -string(1) "" -string(2) "3" +string(4) "=3+4" +string(0) "" +string(1) "3" OK From b3979fe1ec698538eb827e133ff5f072ced7b439 Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Wed, 22 Jun 2016 17:06:59 -0400 Subject: [PATCH 30/68] fixed more tests --- tests/020.phpt | 6 +++++- tests/021.phpt | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/020.phpt b/tests/020.phpt index c2f0ed5..b2de476 100644 --- a/tests/020.phpt +++ b/tests/020.phpt @@ -25,4 +25,8 @@ date.timezone=America/Toronto --EXPECTF-- string(63) "ExcelFormat::__construct() expects exactly 1 parameter, 0 given" -Catchable fatal error: Argument 1 passed to ExcelFormat::__construct() must be an instance of ExcelBook, string given in %s on line %d +Fatal error: Uncaught TypeError: Argument 1 passed to ExcelFormat::__construct() must be an instance of ExcelBook, string given in %s:%d +Stack trace: +#0 %s(%d): ExcelFormat->__construct('cdsd') +#1 {main} + thrown in %s on line %d diff --git a/tests/021.phpt b/tests/021.phpt index 64b529d..c090590 100644 --- a/tests/021.phpt +++ b/tests/021.phpt @@ -23,4 +23,8 @@ date.timezone=America/Toronto --EXPECTF-- string(61) "ExcelFont::__construct() expects exactly 1 parameter, 0 given" -Catchable fatal error: Argument 1 passed to ExcelFont::__construct() must be an instance of ExcelBook, string given in %s on line %d +Fatal error: Uncaught TypeError: Argument 1 passed to ExcelFont::__construct() must be an instance of ExcelBook, string given in %s:%d +Stack trace: +#0 %s(%d): ExcelFont->__construct('cdsd') +#1 {main} + thrown in %s on line %d From 9713144b29ee9b46e62df37b062e21fbed876320 Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Thu, 23 Jun 2016 08:39:52 -0400 Subject: [PATCH 31/68] Use zend_long instead of long --- excel.c | 164 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 82 insertions(+), 82 deletions(-) diff --git a/excel.c b/excel.c index dc4ae47..f7aa4e6 100644 --- a/excel.c +++ b/excel.c @@ -458,7 +458,7 @@ EXCEL_METHOD(Book, getSheet) { BookHandle book; zval *object = getThis(); - long sheet = 0; + zend_long sheet = 0; SheetHandle sh; excel_sheet_object *fo; @@ -533,7 +533,7 @@ EXCEL_METHOD(Book, deleteSheet) { BookHandle book; zval *object = getThis(); - long sheet; + zend_long sheet; if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &sheet) == FAILURE) { RETURN_FALSE; @@ -555,7 +555,7 @@ EXCEL_METHOD(Book, activeSheet) { BookHandle book; zval *object = getThis(); - long sheet = -1; + zend_long sheet = -1; long res; if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &sheet) == FAILURE) { @@ -618,7 +618,7 @@ EXCEL_METHOD(Book, copySheet) SheetHandle sh; excel_sheet_object *fo; zend_string *name_zs = NULL; - long num; + zend_long num; SheetHandle osh; if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sl", &name_zs, &num) == FAILURE) { @@ -831,7 +831,7 @@ EXCEL_METHOD(Book, getCustomFormat) { BookHandle book; zval *object = getThis(); - long id; + zend_long id; char *data; if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &id) == FAILURE) { @@ -871,7 +871,7 @@ EXCEL_METHOD(Book, packDate) { BookHandle book; zval *object = getThis(); - long ts; + zend_long ts; double dt; if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &ts) == FAILURE) { @@ -902,7 +902,7 @@ EXCEL_METHOD(Book, packDateValues) { BookHandle book; zval *object = getThis(); - long year, month, day, hour, min, sec; + zend_long year, month, day, hour, min, sec; double dt; if (zend_parse_parameters(ZEND_NUM_ARGS(), "llllll", &year, &month, &day, &hour, &min, &sec) == FAILURE) { @@ -1077,7 +1077,7 @@ EXCEL_METHOD(Book, setDefaultFont) { BookHandle book; zval *object = getThis(); - long font_size; + zend_long font_size; zend_string *font_zs = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sl", &font_zs, &font_size) == FAILURE || font_size < 1) { @@ -1122,7 +1122,7 @@ EXCEL_METHOD(Book, __construct) { BookHandle book; zval *object = getThis(); - char *name = NULL, *key; + char *name = NULL, *key = NULL; size_t name_len = 0, key_len = 0; zend_bool new_excel = 0; @@ -1163,7 +1163,7 @@ EXCEL_METHOD(Book, setActiveSheet) { BookHandle book; zval *object = getThis(); - long id; + zend_long id; if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &id) == FAILURE || id < 0) { RETURN_FALSE; @@ -1279,7 +1279,7 @@ EXCEL_METHOD(Book, colorPack) { BookHandle book; zval *object = getThis(); - long r, g, b; + zend_long r, g, b; if (zend_parse_parameters(ZEND_NUM_ARGS(), "lll", &r, &g, &b) == FAILURE) { RETURN_FALSE; @@ -1309,7 +1309,7 @@ EXCEL_METHOD(Book, colorUnpack) BookHandle book; zval *object = getThis(); int r, g, b; - long color; + zend_long color; if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &color) == FAILURE) { RETURN_FALSE; @@ -1337,7 +1337,7 @@ EXCEL_METHOD(Font, size) { zval *object = getThis(); FontHandle font; - long size = -1; + zend_long size = -1; if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &size) == FAILURE) { RETURN_FALSE; @@ -1425,7 +1425,7 @@ EXCEL_METHOD(Font, color) { zval *object = getThis(); FontHandle font; - long color; + zend_long color; if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &color) == FAILURE) { RETURN_FALSE; @@ -1447,7 +1447,7 @@ EXCEL_METHOD(Font, mode) { zval *object = getThis(); FontHandle font; - long mode; + zend_long mode; if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &mode) == FAILURE) { RETURN_FALSE; @@ -1469,7 +1469,7 @@ EXCEL_METHOD(Font, underline) { zval *object = getThis(); FontHandle font; - long underline; + zend_long underline; if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &underline) == FAILURE) { RETURN_FALSE; @@ -1630,7 +1630,7 @@ EXCEL_METHOD(Format, getFont) { \ FormatHandle format; \ zval *object = getThis(); \ - long data; \ + zend_long data; \ if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &data) == FAILURE) { \ RETURN_FALSE; \ } \ @@ -1698,7 +1698,7 @@ EXCEL_METHOD(Format, rotate) { FormatHandle format; zval *object = getThis(); - long angle; + zend_long angle; if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &angle) == FAILURE) { RETURN_FALSE; @@ -1724,7 +1724,7 @@ EXCEL_METHOD(Format, indent) { FormatHandle format; zval *object = getThis(); - long indent; + zend_long indent; if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &indent) == FAILURE) { RETURN_FALSE; @@ -1931,7 +1931,7 @@ EXCEL_METHOD(Sheet, cellType) { zval *object = getThis(); SheetHandle sheet; - long row, col; + zend_long row, col; if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll", &row, &col) == FAILURE) { RETURN_FALSE; @@ -1950,7 +1950,7 @@ EXCEL_METHOD(Sheet, cellFormat) zval *object = getThis(); SheetHandle sheet; FormatHandle format; - long row, col; + zend_long row, col; excel_format_object *fo; if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll", &row, &col) == FAILURE) { @@ -1975,7 +1975,7 @@ EXCEL_METHOD(Sheet, setCellFormat) SheetHandle sheet; FormatHandle format; zval *oformat; - long row, col; + zend_long row, col; if (zend_parse_parameters(ZEND_NUM_ARGS(), "llo", &row, &col, &oformat, excel_ce_format) == FAILURE) { RETURN_FALSE; @@ -2058,9 +2058,9 @@ zend_bool php_excel_read_cell(int row, int col, zval *val, SheetHandle sheet, Bo EXCEL_METHOD(Sheet, readRow) { zval *object = getThis(); - long row; - long col_start = 0; - long col_end = -1; + zend_long row; + zend_long col_start = 0; + zend_long col_end = -1; int lc; SheetHandle sheet; BookHandle book; @@ -2118,9 +2118,9 @@ EXCEL_METHOD(Sheet, readRow) EXCEL_METHOD(Sheet, readCol) { zval *object = getThis(); - long col; - long row_start = 0; - long row_end = -1; + zend_long col; + zend_long row_start = 0; + zend_long row_end = -1; int lc; SheetHandle sheet; BookHandle book; @@ -2180,7 +2180,7 @@ EXCEL_METHOD(Sheet, read) zval *object = getThis(); SheetHandle sheet; BookHandle book; - long row, col; + zend_long row, col; zval *oformat = NULL; FormatHandle format = NULL; zend_bool read_formula = 1; @@ -2306,9 +2306,9 @@ EXCEL_METHOD(Sheet, write) SheetHandle sheet; BookHandle book; FormatHandle format; - long row, col; + zend_long row, col; zval *oformat = NULL; - long dtype = -1; + zend_long dtype = -1; zval *data; if (zend_parse_parameters(ZEND_NUM_ARGS(), "llz|O!l", &row, &col, &data, &oformat, excel_ce_format, &dtype) == FAILURE) { @@ -2337,7 +2337,7 @@ EXCEL_METHOD(Sheet, writeRow) SheetHandle sheet; BookHandle book; FormatHandle format; - long row, col = 0; + zend_long row, col = 0; zval *oformat = NULL; zval *data; zval *element; @@ -2383,12 +2383,12 @@ EXCEL_METHOD(Sheet, writeCol) SheetHandle sheet; BookHandle book; FormatHandle format; - long row = 0, col; + zend_long row = 0, col; zval *oformat = NULL; zval *data; zval *element; long i; - long dtype = -1; + zend_long dtype = -1; if (zend_parse_parameters(ZEND_NUM_ARGS(), "la|lO!l", &col, &data, &row, &oformat, excel_ce_format, &dtype) == FAILURE) { RETURN_FALSE; @@ -2426,7 +2426,7 @@ EXCEL_METHOD(Sheet, writeCol) { \ SheetHandle sheet; \ zval *object = getThis(); \ - long r, c; \ + zend_long r, c; \ if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll", &r, &c) == FAILURE) { \ RETURN_FALSE; \ } \ @@ -2447,7 +2447,7 @@ EXCEL_METHOD(Sheet, isFormula) EXCEL_METHOD(Sheet, isDate) { zval *object = getThis(); - long r, c; + zend_long r, c; SheetHandle sheet; if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll", &r, &c) == FAILURE) { @@ -2500,7 +2500,7 @@ EXCEL_METHOD(Sheet, removeCol) { \ SheetHandle sheet; \ zval *object = getThis(); \ - long val; \ + zend_long val; \ if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &val) == FAILURE) { \ RETURN_FALSE; \ } \ @@ -2531,7 +2531,7 @@ EXCEL_METHOD(Sheet, readComment) SheetHandle sheet; zval *object = getThis(); const char *s; - long r, c; + zend_long r, c; if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll", &r, &c) == FAILURE) { RETURN_FALSE; @@ -2554,7 +2554,7 @@ EXCEL_METHOD(Sheet, writeComment) SheetHandle sheet; zval *object = getThis(); zend_string *val_zs = NULL, *auth_zs = NULL; - long r, c, w, h; + zend_long r, c, w, h; if (zend_parse_parameters(ZEND_NUM_ARGS(), "llSSll", &r, &c, &val_zs, &auth_zs, &w, &h) == FAILURE) { RETURN_FALSE; @@ -2577,7 +2577,7 @@ EXCEL_METHOD(Sheet, setColWidth) SheetHandle sheet; FormatHandle format; zval *object = getThis(); - long s, e; + zend_long s, e; double width; zval *f = NULL; zend_bool h = 0; @@ -2614,7 +2614,7 @@ EXCEL_METHOD(Sheet, setRowHeight) SheetHandle sheet; FormatHandle format; zval *object = getThis(); - long row; + zend_long row; double height; zval *f = NULL; zend_bool h = 0; @@ -2647,7 +2647,7 @@ EXCEL_METHOD(Sheet, getMerge) { SheetHandle sheet; zval *object = getThis(); - long row, col; + zend_long row, col; int rowFirst, rowLast, colFirst, colLast; if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll", &row, &col) == FAILURE) { @@ -2674,7 +2674,7 @@ EXCEL_METHOD(Sheet, setMerge) { SheetHandle sheet; zval *object = getThis(); - long row_s, col_s, row_e, col_e; + zend_long row_s, col_s, row_e, col_e; if (zend_parse_parameters(ZEND_NUM_ARGS(), "llll", &row_s, &row_e, &col_s, &col_e) == FAILURE) { RETURN_FALSE; @@ -2692,7 +2692,7 @@ EXCEL_METHOD(Sheet, deleteMerge) { SheetHandle sheet; zval *object = getThis(); - long row, col; + zend_long row, col; if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll", &row, &col) == FAILURE) { RETURN_FALSE; @@ -2710,8 +2710,8 @@ EXCEL_METHOD(Sheet, addPictureScaled) { SheetHandle sheet; zval *object = getThis(); - long row, col, pic_id; - long x_offset = 0, y_offset = 0, pos = 0; + zend_long row, col, pic_id; + zend_long x_offset = 0, y_offset = 0, pos = 0; double scale; if (zend_parse_parameters(ZEND_NUM_ARGS(), "llld|lll", &row, &col, &pic_id, &scale, &x_offset, &y_offset, &pos) == FAILURE) { @@ -2734,8 +2734,8 @@ EXCEL_METHOD(Sheet, addPictureDim) { SheetHandle sheet; zval *object = getThis(); - long row, col, pic_id, w, h; - long x_offset = 0, y_offset = 0, pos = 0; + zend_long row, col, pic_id, w, h; + zend_long x_offset = 0, y_offset = 0, pos = 0; if (zend_parse_parameters(ZEND_NUM_ARGS(), "lllll|lll", &row, &col, &pic_id, &w, &h, &x_offset, &y_offset, &pos) == FAILURE) { RETURN_FALSE; @@ -2755,7 +2755,7 @@ EXCEL_METHOD(Sheet, addPictureDim) { \ SheetHandle sheet; \ zval *object = getThis(); \ - long val; \ + zend_long val; \ zend_bool brk; \ if (zend_parse_parameters(ZEND_NUM_ARGS(), "lb", &val, &brk) == FAILURE) { \ RETURN_FALSE; \ @@ -2786,7 +2786,7 @@ EXCEL_METHOD(Sheet, splitSheet) { SheetHandle sheet; zval *object = getThis(); - long row, col; + zend_long row, col; if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll", &row, &col) == FAILURE) { RETURN_FALSE; @@ -2802,7 +2802,7 @@ EXCEL_METHOD(Sheet, splitSheet) { \ SheetHandle sheet; \ zval *object = getThis(); \ - long s, e; \ + zend_long s, e; \ zend_bool brk = 0; \ if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll|b", &s, &e, &brk) == FAILURE) { \ RETURN_FALSE; \ @@ -2833,7 +2833,7 @@ EXCEL_METHOD(Sheet, clear) { SheetHandle sheet; zval *object = getThis(); - long row_s, col_s, col_e, row_e; + zend_long row_s, col_s, col_e, row_e; if (zend_parse_parameters(ZEND_NUM_ARGS(), "llll", &row_s, &row_e, &col_s, &col_e) == FAILURE) { RETURN_FALSE; @@ -2851,7 +2851,7 @@ EXCEL_METHOD(Sheet, copy) { SheetHandle sheet; zval *object = getThis(); - long row, col, to_row, to_col; + zend_long row, col, to_row, to_col; if (zend_parse_parameters(ZEND_NUM_ARGS(), "llll", &row, &col, &to_row, &to_col) == FAILURE) { RETURN_FALSE; @@ -2895,7 +2895,7 @@ EXCEL_METHOD(Sheet, copy) { \ SheetHandle sheet; \ zval *object = getThis(); \ - long val; \ + zend_long val; \ if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &val) == FAILURE) { \ RETURN_FALSE; \ } \ @@ -3034,7 +3034,7 @@ EXCEL_METHOD(Sheet, setTopLeftView) { SheetHandle sheet; zval *object = getThis(); - long r,c; + zend_long r,c; if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll", &r, &c) == FAILURE) { RETURN_FALSE; @@ -3054,7 +3054,7 @@ EXCEL_METHOD(Sheet, rowColToAddr) SheetHandle sheet; zval *object = getThis(); zend_bool row_relative = 1, col_relative = 1; - long row, col; + zend_long row, col; const char *cel_ref; if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll|bb", &row, &col, &row_relative, &col_relative) == FAILURE) { @@ -3384,9 +3384,9 @@ EXCEL_METHOD(Sheet, setNamedRange) { SheetHandle sheet; zval *object = getThis(); - long row, to_row, col, to_col; + zend_long row, to_row, col, to_col; zend_string *name_zs = NULL; - long scope_id = SCOPE_WORKBOOK; + zend_long scope_id = SCOPE_WORKBOOK; if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sllll|l", &name_zs, &row, &to_row, &col, &to_col, &scope_id) == FAILURE) { RETURN_FALSE; @@ -3418,7 +3418,7 @@ EXCEL_METHOD(Sheet, delNamedRange) SheetHandle sheet; zval *object = getThis(); zend_string *val_zs = NULL; - long scope_id = SCOPE_WORKBOOK; + zend_long scope_id = SCOPE_WORKBOOK; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|l", &val_zs, &scope_id) == FAILURE) { RETURN_FALSE; @@ -3439,7 +3439,7 @@ EXCEL_METHOD(Sheet, delNamedRange) { \ SheetHandle sheet; \ zval *object = getThis(); \ - long s, e; \ + zend_long s, e; \ if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll", &s, &e) == FAILURE) { \ RETURN_FALSE; \ } \ @@ -3544,7 +3544,7 @@ EXCEL_METHOD(Sheet, setPrintFit) { SheetHandle sheet; zval *object = getThis(); - long wPages, hPages; + zend_long wPages, hPages; if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll", &wPages, &hPages) == FAILURE) { RETURN_FALSE; @@ -3588,7 +3588,7 @@ EXCEL_METHOD(Sheet, getNamedRange) zval *object = getThis(); zend_string *name_zs = NULL; int rf, rl, cf, cl; - long scope_id = SCOPE_WORKBOOK; + zend_long scope_id = SCOPE_WORKBOOK; int hidden = 0; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|l", &name_zs, &scope_id) == FAILURE) { @@ -3619,10 +3619,10 @@ EXCEL_METHOD(Sheet, getIndexRange) { SheetHandle sheet; zval *object = getThis(); - long index; + zend_long index; int rf, rl, cf, cl; int hidden = 0; - long scope_id = SCOPE_WORKBOOK; + zend_long scope_id = SCOPE_WORKBOOK; if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|l", &index, &scope_id) == FAILURE) { RETURN_FALSE; @@ -3665,7 +3665,7 @@ EXCEL_METHOD(Sheet, getVerPageBreak) { SheetHandle sheet; zval *object = getThis(); - long index; + zend_long index; if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) { RETURN_FALSE; @@ -3698,7 +3698,7 @@ EXCEL_METHOD(Sheet, getHorPageBreak) { SheetHandle sheet; zval *object = getThis(); - long index; + zend_long index; if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) { RETURN_FALSE; @@ -3731,7 +3731,7 @@ EXCEL_METHOD(Sheet, getPictureInfo) { SheetHandle sheet; zval *object = getThis(); - long index; + zend_long index; int rowTop, colLeft, rowBottom, colRight, width, height, offset_x, offset_y; int pic_index; @@ -3834,7 +3834,7 @@ EXCEL_METHOD(Book, getPicture) { BookHandle book; zval *object = getThis(); - long index; + zend_long index; int type; const char *buf; unsigned int buf_len; @@ -3882,7 +3882,7 @@ EXCEL_METHOD(Book, insertSheet) SheetHandle sh, sheet; excel_sheet_object *fo; zend_string *name_zs = NULL; - long index; + zend_long index; if (zend_parse_parameters(ZEND_NUM_ARGS(), "lS|o", &index, &name_zs, &shz) == FAILURE) { RETURN_FALSE; @@ -3966,7 +3966,7 @@ EXCEL_METHOD(Sheet, setRightToLeft) { SheetHandle sheet; zval *object = getThis(); - long mode; + zend_long mode; if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &mode) == FAILURE) { RETURN_FALSE; @@ -3983,7 +3983,7 @@ EXCEL_METHOD(Sheet, setPrintArea) { zval *object = getThis(); SheetHandle sheet; - long row, col, to_row, to_col; + zend_long row, col, to_row, to_col; if (zend_parse_parameters(ZEND_NUM_ARGS(), "llll", &row, &to_row, &col, &to_col) == FAILURE) { RETURN_FALSE; @@ -4077,7 +4077,7 @@ EXCEL_METHOD(Sheet, hyperlink) { SheetHandle sheet; zval *object = getThis(); - long index; + zend_long index; int rowFirst, rowLast, colFirst, colLast; const char *s; @@ -4108,7 +4108,7 @@ EXCEL_METHOD(Sheet, delHyperlink) { zval *object = getThis(); SheetHandle sheet; - long index; + zend_long index; if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) { RETURN_FALSE; @@ -4130,7 +4130,7 @@ EXCEL_METHOD(Sheet, addHyperlink) SheetHandle sheet; zval *object = getThis(); zend_string *val_zs = NULL; - long row_first, row_last, col_first, col_last; + zend_long row_first, row_last, col_first, col_last; if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sllll", &val_zs, &row_first, &row_last, &col_first, &col_last) == FAILURE) { RETURN_FALSE; @@ -4170,7 +4170,7 @@ EXCEL_METHOD(Sheet, merge) { SheetHandle sheet; zval *object = getThis(); - long index; + zend_long index; int rowFirst, rowLast, colFirst, colLast; if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) { @@ -4201,7 +4201,7 @@ EXCEL_METHOD(Sheet, delMergeByIndex) { zval *object = getThis(); SheetHandle sheet; - long index; + zend_long index; if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) { RETURN_FALSE; @@ -4242,7 +4242,7 @@ EXCEL_METHOD(Sheet, rowHidden) { zval *object = getThis(); SheetHandle sheet; - long row; + zend_long row; if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &row) == FAILURE) { RETURN_FALSE; @@ -4263,7 +4263,7 @@ EXCEL_METHOD(Sheet, setRowHidden) { zval *object = getThis(); SheetHandle sheet; - long row; + zend_long row; zend_bool hidden; if (zend_parse_parameters(ZEND_NUM_ARGS(), "lb", &row, &hidden) == FAILURE) { @@ -4285,7 +4285,7 @@ EXCEL_METHOD(Sheet, colHidden) { zval *object = getThis(); SheetHandle sheet; - long col; + zend_long col; if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &col) == FAILURE) { RETURN_FALSE; @@ -4306,7 +4306,7 @@ EXCEL_METHOD(Sheet, setColHidden) { zval *object = getThis(); SheetHandle sheet; - long col; + zend_long col; zend_bool hidden; if (zend_parse_parameters(ZEND_NUM_ARGS(), "lb", &col, &hidden) == FAILURE) { @@ -4328,7 +4328,7 @@ EXCEL_METHOD(Book, sheetType) { zval *object = getThis(); BookHandle book; - long index; + zend_long index; if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) { RETURN_FALSE; @@ -4380,7 +4380,7 @@ EXCEL_METHOD(Sheet, setAutoFitArea) { zval *object = getThis(); SheetHandle sheet; - long rowFirst=0, colFirst=0, rowLast=-1, colLast=-1; + zend_long rowFirst=0, colFirst=0, rowLast=-1, colLast=-1; if (zend_parse_parameters(ZEND_NUM_ARGS(), "|llll", &rowFirst, &rowLast, &colFirst, &colLast) == FAILURE) { RETURN_FALSE; From ae4ff389ccce436d945305b48866b7728a9f4169 Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Thu, 23 Jun 2016 08:51:18 -0400 Subject: [PATCH 32/68] Use PHP's string access macros --- excel.c | 96 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/excel.c b/excel.c index f7aa4e6..da62d11 100644 --- a/excel.c +++ b/excel.c @@ -360,13 +360,13 @@ EXCEL_METHOD(Book, load) RETURN_FALSE; } - if (!data_zs || data_zs->len < 1) { + if (!data_zs || ZSTR_LEN(data_zs) < 1) { RETURN_FALSE; } BOOK_FROM_OBJECT(book, object); - RETURN_BOOL(xlBookLoadRaw(book, data_zs->val, data_zs->len)); + RETURN_BOOL(xlBookLoadRaw(book, ZSTR_VAL(data_zs), ZSTR_LEN(data_zs))); } /* }}} */ @@ -384,13 +384,13 @@ EXCEL_METHOD(Book, loadFile) RETURN_FALSE; } - if (!filename_zs || filename_zs->len < 1) { + if (!filename_zs || ZSTR_LEN(filename_zs) < 1) { RETURN_FALSE; } BOOK_FROM_OBJECT(book, object); - stream = php_stream_open_wrapper(filename_zs->val, "rb", REPORT_ERRORS, NULL); + stream = php_stream_open_wrapper(ZSTR_VAL(filename_zs), "rb", REPORT_ERRORS, NULL); if (!stream) { RETURN_FALSE; @@ -399,12 +399,12 @@ EXCEL_METHOD(Book, loadFile) contents = php_stream_copy_to_mem(stream, PHP_STREAM_COPY_ALL, 0); php_stream_close(stream); - if (!contents || contents->len < 1) { + if (!contents || ZSTR_LEN(contents) < 1) { zend_string_release(contents); RETURN_FALSE; } - RETVAL_BOOL(xlBookLoadRaw(book, contents->val, contents->len)); + RETVAL_BOOL(xlBookLoadRaw(book, ZSTR_VAL(contents), ZSTR_LEN(contents))); zend_string_release(contents); } /* }}} */ @@ -429,9 +429,9 @@ EXCEL_METHOD(Book, save) RETURN_FALSE; } - if (filename_zs && filename_zs->len > 0) { + if (filename_zs && ZSTR_LEN(filename_zs) > 0) { int numbytes; - php_stream *stream = php_stream_open_wrapper(filename_zs->val, "wb", REPORT_ERRORS, NULL); + php_stream *stream = php_stream_open_wrapper(ZSTR_VAL(filename_zs), "wb", REPORT_ERRORS, NULL); if (!stream) { RETURN_FALSE; @@ -500,7 +500,7 @@ EXCEL_METHOD(Book, getSheetByName) RETURN_FALSE; } - if (!sheet_name_zs || sheet_name_zs->len < 1) { + if (!sheet_name_zs || ZSTR_LEN(sheet_name_zs) < 1) { RETURN_FALSE; } @@ -512,7 +512,7 @@ EXCEL_METHOD(Book, getSheetByName) if (sh) { s = xlSheetName(sh); if (s) { - if ((case_s && !strcasecmp(s, sheet_name_zs->val)) || (!case_s && !strcmp(s, sheet_name_zs->val))) { + if ((case_s && !strcasecmp(s, ZSTR_VAL(sheet_name_zs))) || (!case_s && !strcmp(s, ZSTR_VAL(sheet_name_zs)))) { ZVAL_OBJ(return_value, excel_object_new_sheet(excel_ce_sheet)); fo = Z_EXCEL_SHEET_OBJ_P(return_value); fo->sheet = sh; @@ -591,13 +591,13 @@ EXCEL_METHOD(Book, addSheet) RETURN_FALSE; } - if (!name_zs || name_zs->len < 1) { + if (!name_zs || ZSTR_LEN(name_zs) < 1) { RETURN_FALSE; } BOOK_FROM_OBJECT(book, object); - sh = xlBookAddSheet(book, name_zs->val, 0); + sh = xlBookAddSheet(book, ZSTR_VAL(name_zs), 0); if (!sh) { RETURN_FALSE; } @@ -629,7 +629,7 @@ EXCEL_METHOD(Book, copySheet) RETURN_FALSE; } - if (!name_zs || name_zs->len < 1) { + if (!name_zs || ZSTR_LEN(name_zs) < 1) { RETURN_FALSE; } @@ -638,7 +638,7 @@ EXCEL_METHOD(Book, copySheet) if (!(osh = xlBookGetSheet(book, num))) { RETURN_FALSE; } - sh = xlBookAddSheet(book, name_zs->val, osh); + sh = xlBookAddSheet(book, ZSTR_VAL(name_zs), osh); if (!sh) { RETURN_FALSE; @@ -812,13 +812,13 @@ EXCEL_METHOD(Book, addCustomFormat) RETURN_FALSE; } - if (!format_zs || format_zs->len < 1) { + if (!format_zs || ZSTR_LEN(format_zs) < 1) { RETURN_FALSE; } BOOK_FROM_OBJECT(book, object); - if (!(id = xlBookAddCustomNumFormat(book, format_zs->val))) { + if (!(id = xlBookAddCustomNumFormat(book, ZSTR_VAL(format_zs)))) { RETURN_FALSE; } RETURN_LONG(id); @@ -1084,13 +1084,13 @@ EXCEL_METHOD(Book, setDefaultFont) RETURN_FALSE; } - if (!font_zs || font_zs->len < 1) { + if (!font_zs || ZSTR_LEN(font_zs) < 1) { RETURN_FALSE; } BOOK_FROM_OBJECT(book, object); - xlBookSetDefaultFont(book, font_zs->val, (int)font_size); + xlBookSetDefaultFont(book, ZSTR_VAL(font_zs), (int)font_size); } /* }}} */ @@ -1106,13 +1106,13 @@ EXCEL_METHOD(Book, setLocale) RETURN_FALSE; } - if (!locale_zs || locale_zs->len < 1) { + if (!locale_zs || ZSTR_LEN(locale_zs) < 1) { RETURN_FALSE; } BOOK_FROM_OBJECT(book, object); - xlBookSetLocale(book, locale_zs->val); + xlBookSetLocale(book, ZSTR_VAL(locale_zs)); } /* }}} */ @@ -1189,16 +1189,16 @@ static void php_excel_add_picture(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{ RETURN_FALSE; } - if (!data_zs || data_zs->len < 1) { + if (!data_zs || ZSTR_LEN(data_zs) < 1) { RETURN_FALSE; } BOOK_FROM_OBJECT(book, object); if (mode == 1) { - ret = xlBookAddPicture2(book, data_zs->val, data_zs->len); + ret = xlBookAddPicture2(book, ZSTR_VAL(data_zs), ZSTR_LEN(data_zs)); } else { - stream = php_stream_open_wrapper(data_zs->val, "rb", REPORT_ERRORS, NULL); + stream = php_stream_open_wrapper(ZSTR_VAL(data_zs), "rb", REPORT_ERRORS, NULL); if (!stream) { RETURN_FALSE; @@ -1207,11 +1207,11 @@ static void php_excel_add_picture(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{ contents = php_stream_copy_to_mem(stream, PHP_STREAM_COPY_ALL, 0); php_stream_close(stream); - if (!contents || contents->len < 1) { + if (!contents || ZSTR_LEN(contents) < 1) { zend_string_release(contents); RETURN_FALSE; } - ret = xlBookAddPicture2(book, contents->val, contents->len); + ret = xlBookAddPicture2(book, ZSTR_VAL(contents), ZSTR_LEN(contents)); zend_string_release(contents); } @@ -1500,7 +1500,7 @@ EXCEL_METHOD(Font, name) FONT_FROM_OBJECT(font, object); if (name_zs) { - xlFontSetName(font, name_zs->val); + xlFontSetName(font, ZSTR_VAL(name_zs)); } RETURN_STRING((char *)xlFontName(font)); @@ -1906,7 +1906,7 @@ EXCEL_METHOD(Sheet, __construct) } PHP_EXCEL_RESTORE_ERRORS(); - if (!zbook || !name_zs || name_zs->len < 1) { + if (!zbook || !name_zs || ZSTR_LEN(name_zs) < 1) { RETURN_FALSE; } @@ -1914,7 +1914,7 @@ EXCEL_METHOD(Sheet, __construct) obj = Z_EXCEL_SHEET_OBJ_P(object); - sh = xlBookAddSheet(book, name_zs->val, 0); + sh = xlBookAddSheet(book, ZSTR_VAL(name_zs), 0); if (!sh) { RETURN_FALSE; @@ -2250,7 +2250,7 @@ zend_bool php_excel_write_cell(SheetHandle sheet, BookHandle book, int row, int case IS_STRING: data_zs = Z_STR_P(data); if (Z_STRLEN_P(data) > 0 && '\'' == Z_STRVAL_P(data)[0]) { - return xlSheetWriteStr(sheet, row, col, (const char*) data_zs->val + 1, format); + return xlSheetWriteStr(sheet, row, col, (const char*) ZSTR_VAL(data_zs) + 1, format); } if (Z_STRLEN_P(data) > 0 && '=' == Z_STRVAL_P(data)[0]) { dtype = PHP_EXCEL_FORMULA; @@ -2273,7 +2273,7 @@ zend_bool php_excel_write_cell(SheetHandle sheet, BookHandle book, int row, int if (Z_STRLEN_P(data) == 0 && INI_INT("excel.skip_empty") == 2) { return 1; } - return xlSheetWriteStr(sheet, row, col, (const char*) data_zs->val, format); + return xlSheetWriteStr(sheet, row, col, (const char*) ZSTR_VAL(data_zs), format); } case IS_TRUE: @@ -2560,13 +2560,13 @@ EXCEL_METHOD(Sheet, writeComment) RETURN_FALSE; } - if (!val_zs || val_zs->len < 1 || !auth_zs || auth_zs->len < 1) { + if (!val_zs || ZSTR_LEN(val_zs) < 1 || !auth_zs || ZSTR_LEN(auth_zs) < 1) { RETURN_FALSE; } SHEET_FROM_OBJECT(sheet, object); - xlSheetWriteComment(sheet, r, c, val_zs->val, auth_zs->val, w, h); + xlSheetWriteComment(sheet, r, c, ZSTR_VAL(val_zs), ZSTR_VAL(auth_zs), w, h); } /* }}} */ @@ -3084,14 +3084,14 @@ EXCEL_METHOD(Sheet, addrToRowCol) RETURN_FALSE; } - if (!cell_reference_zs || cell_reference_zs->len < 1) { + if (!cell_reference_zs || ZSTR_LEN(cell_reference_zs) < 1) { php_error_docref(NULL, E_WARNING, "Cell reference cannot be empty"); RETURN_FALSE; } SHEET_FROM_OBJECT(sheet, object); - xlSheetAddrToRowCol(sheet, cell_reference_zs->val, &row, &col, &rowRelative, &colRelative); + xlSheetAddrToRowCol(sheet, ZSTR_VAL(cell_reference_zs), &row, &col, &rowRelative, &colRelative); array_init(return_value); add_assoc_long(return_value, "row", row); add_assoc_long(return_value, "column", col); @@ -3197,11 +3197,11 @@ EXCEL_METHOD(Sheet, footer) if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sd", &val_zs, &margin) == FAILURE) { \ RETURN_FALSE; \ } \ - if (!val_zs || val_zs->len > 255) { \ + if (!val_zs || ZSTR_LEN(val_zs) > 255) { \ RETURN_FALSE; \ } \ SHEET_FROM_OBJECT(sheet, object); \ - RETURN_BOOL(xlSheet ## func_name (sheet, val_zs->val, margin)); \ + RETURN_BOOL(xlSheet ## func_name (sheet, ZSTR_VAL(val_zs), margin)); \ } /* {{{ proto bool ExcelSheet::setHeader(string header, double margin) @@ -3374,7 +3374,7 @@ EXCEL_METHOD(Sheet, setName) SHEET_FROM_OBJECT(sheet, object); - xlSheetSetName(sheet, val_zs->val); + xlSheetSetName(sheet, ZSTR_VAL(val_zs)); } /* }}} */ @@ -3392,7 +3392,7 @@ EXCEL_METHOD(Sheet, setNamedRange) RETURN_FALSE; } - if (!name_zs || name_zs->len < 1) { + if (!name_zs || ZSTR_LEN(name_zs) < 1) { php_error_docref(NULL, E_WARNING, "The range name cannot be empty."); RETURN_FALSE; } @@ -3407,7 +3407,7 @@ EXCEL_METHOD(Sheet, setNamedRange) SHEET_FROM_OBJECT(sheet, object); - RETURN_BOOL(xlSheetSetNamedRange(sheet, name_zs->val, row, to_row, col, to_col, scope_id)); + RETURN_BOOL(xlSheetSetNamedRange(sheet, ZSTR_VAL(name_zs), row, to_row, col, to_col, scope_id)); } /* }}} */ @@ -3424,14 +3424,14 @@ EXCEL_METHOD(Sheet, delNamedRange) RETURN_FALSE; } - if (!val_zs || val_zs->len < 1) { + if (!val_zs || ZSTR_LEN(val_zs) < 1) { php_error_docref(NULL, E_WARNING, "The range name cannot be empty."); RETURN_FALSE; } SHEET_FROM_OBJECT(sheet, object); - RETURN_BOOL(xlSheetDelNamedRange(sheet, val_zs->val, scope_id)); + RETURN_BOOL(xlSheetDelNamedRange(sheet, ZSTR_VAL(val_zs), scope_id)); } /* }}} */ @@ -3595,13 +3595,13 @@ EXCEL_METHOD(Sheet, getNamedRange) RETURN_FALSE; } - if (!name_zs || name_zs->len < 1) { + if (!name_zs || ZSTR_LEN(name_zs) < 1) { RETURN_FALSE; } SHEET_FROM_OBJECT(sheet, object); - if (xlSheetGetNamedRange(sheet, name_zs->val, &rf, &rl, &cf, &cl, scope_id, &hidden)) { + if (xlSheetGetNamedRange(sheet, ZSTR_VAL(name_zs), &rf, &rl, &cf, &cl, scope_id, &hidden)) { array_init(return_value); add_assoc_long(return_value, "row_first", rf); add_assoc_long(return_value, "row_last", rl); @@ -3888,18 +3888,18 @@ EXCEL_METHOD(Book, insertSheet) RETURN_FALSE; } - if (!name_zs || name_zs->len < 1) { + if (!name_zs || ZSTR_LEN(name_zs) < 1) { RETURN_FALSE; } BOOK_FROM_OBJECT(book, object); if (shz) { SHEET_FROM_OBJECT(sheet, shz); - if (!(sh = xlBookInsertSheet(book, index, name_zs->val, sheet))) { + if (!(sh = xlBookInsertSheet(book, index, ZSTR_VAL(name_zs), sheet))) { RETURN_FALSE; } } else { - if (!(sh = xlBookInsertSheet(book, index, name_zs->val, 0))) { + if (!(sh = xlBookInsertSheet(book, index, ZSTR_VAL(name_zs), 0))) { RETURN_FALSE; } } @@ -4136,13 +4136,13 @@ EXCEL_METHOD(Sheet, addHyperlink) RETURN_FALSE; } - if (!val_zs || val_zs->len < 1) { + if (!val_zs || ZSTR_LEN(val_zs) < 1) { RETURN_FALSE; } SHEET_FROM_OBJECT(sheet, object); - xlSheetAddHyperlink(sheet, val_zs->val, row_first, row_last, col_first, col_last); + xlSheetAddHyperlink(sheet, ZSTR_VAL(val_zs), row_first, row_last, col_first, col_last); RETURN_TRUE; } From dec3e0eabed2297429caa7cc44ff7106bd611d68 Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Thu, 23 Jun 2016 08:59:39 -0400 Subject: [PATCH 33/68] Normalize empty string checks --- excel.c | 65 +++++++++++++++++++-------------------------------------- 1 file changed, 22 insertions(+), 43 deletions(-) diff --git a/excel.c b/excel.c index da62d11..6dc03ec 100644 --- a/excel.c +++ b/excel.c @@ -348,6 +348,11 @@ static zend_object *excel_format_object_clone(zval *this_ptr) #define EXCEL_METHOD(class_name, function_name) \ PHP_METHOD(Excel ## class_name, function_name) +#define EXCEL_NON_EMPTY_STRING(string_zval) \ + if (!string_zval || ZSTR_LEN(string_zval) < 1) { \ + RETURN_FALSE; \ + } + /* {{{ proto bool ExcelBook::load(string data) Load Excel data string. */ EXCEL_METHOD(Book, load) @@ -360,9 +365,7 @@ EXCEL_METHOD(Book, load) RETURN_FALSE; } - if (!data_zs || ZSTR_LEN(data_zs) < 1) { - RETURN_FALSE; - } + EXCEL_NON_EMPTY_STRING(data_zs) BOOK_FROM_OBJECT(book, object); @@ -384,9 +387,7 @@ EXCEL_METHOD(Book, loadFile) RETURN_FALSE; } - if (!filename_zs || ZSTR_LEN(filename_zs) < 1) { - RETURN_FALSE; - } + EXCEL_NON_EMPTY_STRING(filename_zs) BOOK_FROM_OBJECT(book, object); @@ -500,9 +501,7 @@ EXCEL_METHOD(Book, getSheetByName) RETURN_FALSE; } - if (!sheet_name_zs || ZSTR_LEN(sheet_name_zs) < 1) { - RETURN_FALSE; - } + EXCEL_NON_EMPTY_STRING(sheet_name_zs) BOOK_FROM_OBJECT(book, object); @@ -591,9 +590,7 @@ EXCEL_METHOD(Book, addSheet) RETURN_FALSE; } - if (!name_zs || ZSTR_LEN(name_zs) < 1) { - RETURN_FALSE; - } + EXCEL_NON_EMPTY_STRING(name_zs) BOOK_FROM_OBJECT(book, object); @@ -629,9 +626,7 @@ EXCEL_METHOD(Book, copySheet) RETURN_FALSE; } - if (!name_zs || ZSTR_LEN(name_zs) < 1) { - RETURN_FALSE; - } + EXCEL_NON_EMPTY_STRING(name_zs) BOOK_FROM_OBJECT(book, object); @@ -812,9 +807,7 @@ EXCEL_METHOD(Book, addCustomFormat) RETURN_FALSE; } - if (!format_zs || ZSTR_LEN(format_zs) < 1) { - RETURN_FALSE; - } + EXCEL_NON_EMPTY_STRING(format_zs) BOOK_FROM_OBJECT(book, object); @@ -1084,9 +1077,7 @@ EXCEL_METHOD(Book, setDefaultFont) RETURN_FALSE; } - if (!font_zs || ZSTR_LEN(font_zs) < 1) { - RETURN_FALSE; - } + EXCEL_NON_EMPTY_STRING(font_zs) BOOK_FROM_OBJECT(book, object); @@ -1106,9 +1097,7 @@ EXCEL_METHOD(Book, setLocale) RETURN_FALSE; } - if (!locale_zs || ZSTR_LEN(locale_zs) < 1) { - RETURN_FALSE; - } + EXCEL_NON_EMPTY_STRING(locale_zs) BOOK_FROM_OBJECT(book, object); @@ -1189,9 +1178,7 @@ static void php_excel_add_picture(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{ RETURN_FALSE; } - if (!data_zs || ZSTR_LEN(data_zs) < 1) { - RETURN_FALSE; - } + EXCEL_NON_EMPTY_STRING(data_zs) BOOK_FROM_OBJECT(book, object); @@ -1906,9 +1893,10 @@ EXCEL_METHOD(Sheet, __construct) } PHP_EXCEL_RESTORE_ERRORS(); - if (!zbook || !name_zs || ZSTR_LEN(name_zs) < 1) { + if (!zbook) { RETURN_FALSE; } + EXCEL_NON_EMPTY_STRING(name_zs) BOOK_FROM_OBJECT(book, zbook); @@ -2560,9 +2548,8 @@ EXCEL_METHOD(Sheet, writeComment) RETURN_FALSE; } - if (!val_zs || ZSTR_LEN(val_zs) < 1 || !auth_zs || ZSTR_LEN(auth_zs) < 1) { - RETURN_FALSE; - } + EXCEL_NON_EMPTY_STRING(auth_zs) + EXCEL_NON_EMPTY_STRING(val_zs) SHEET_FROM_OBJECT(sheet, object); @@ -3368,9 +3355,7 @@ EXCEL_METHOD(Sheet, setName) RETURN_FALSE; } - if (!val_zs) { - RETURN_FALSE; - } + EXCEL_NON_EMPTY_STRING(val_zs) SHEET_FROM_OBJECT(sheet, object); @@ -3595,9 +3580,7 @@ EXCEL_METHOD(Sheet, getNamedRange) RETURN_FALSE; } - if (!name_zs || ZSTR_LEN(name_zs) < 1) { - RETURN_FALSE; - } + EXCEL_NON_EMPTY_STRING(name_zs) SHEET_FROM_OBJECT(sheet, object); @@ -3888,9 +3871,7 @@ EXCEL_METHOD(Book, insertSheet) RETURN_FALSE; } - if (!name_zs || ZSTR_LEN(name_zs) < 1) { - RETURN_FALSE; - } + EXCEL_NON_EMPTY_STRING(name_zs) BOOK_FROM_OBJECT(book, object); if (shz) { @@ -4136,9 +4117,7 @@ EXCEL_METHOD(Sheet, addHyperlink) RETURN_FALSE; } - if (!val_zs || ZSTR_LEN(val_zs) < 1) { - RETURN_FALSE; - } + EXCEL_NON_EMPTY_STRING(val_zs) SHEET_FROM_OBJECT(sheet, object); From 9f8948f939b0469332a402eb43af637f58b827b4 Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Thu, 23 Jun 2016 09:08:55 -0400 Subject: [PATCH 34/68] removed no longer needed for code php7 --- php_excel.h | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/php_excel.h b/php_excel.h index 7c281c3..654528d 100644 --- a/php_excel.h +++ b/php_excel.h @@ -39,21 +39,10 @@ ZEND_END_MODULE_GLOBALS(excel) #include "TSRM.h" #endif -#if ZEND_MODULE_API_NO >= 20100409 -#ifndef ZEND_ENGINE_2_4 -#define ZEND_ENGINE_2_4 -#endif -#endif - -#if PHP_VERSION_ID >= 50300 # define PHP_EXCEL_ERROR_HANDLING() \ zend_error_handling error_handling; \ zend_replace_error_handling(EH_THROW, NULL, &error_handling TSRMLS_CC); # define PHP_EXCEL_RESTORE_ERRORS() zend_restore_error_handling(&error_handling TSRMLS_CC); -#else -# define PHP_EXCEL_ERROR_HANDLING() php_set_error_handling(EH_THROW, NULL TSRMLS_CC); -# define PHP_EXCEL_RESTORE_ERRORS() php_std_error_handling(); -#endif #ifndef Z_SET_ISREF_P # define Z_SET_ISREF_P(pz) (pz)->is_ref = 1 From 885c754429c6b169c110f2582dabe7118ee05402 Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Thu, 23 Jun 2016 09:35:22 -0400 Subject: [PATCH 35/68] news --- ChangeLog | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ChangeLog b/ChangeLog index 688ba84..d4a324c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,8 @@ - ExcelBook::printRepeatRows() * Added support for LibXL 3.6.3 * ExcelSheet::addPictureDim() & ExcelSheet::addPictureScaled() now support position parameters + * Includes official PHP7 release + * Added support for libxl compiled from source [2015-02-26] - Version 1.0.1 * Added methods From bb3bc509469f797778f45448cfdadd9e6401c153 Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Thu, 23 Jun 2016 09:47:44 -0400 Subject: [PATCH 36/68] fixed issue #149 --- config.m4 | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/config.m4 b/config.m4 index 94426e9..935a3db 100644 --- a/config.m4 +++ b/config.m4 @@ -18,13 +18,13 @@ if test "$PHP_EXCEL" != "no"; then SEARCH_FOR="libxl.h" AC_MSG_CHECKING([for excel includes]) - if test -r $PHP_LIBXL_INCDIR/include/$SEARCH_FOR; then + if test -r "$PHP_LIBXL_INCDIR/include/$SEARCH_FOR"; then EXCEL_INCDIR=$PHP_LIBXL_INCDIR/include - elif test -r $PHP_LIBXL_INCDIR/$SEARCH_FOR; then + elif test -r "$PHP_LIBXL_INCDIR/$SEARCH_FOR"; then EXCEL_INCDIR=$PHP_LIBXL_INCDIR else # search default path list for i in $SEARCH_PATH ; do - if test -r $i/include/$SEARCH_FOR; then + if test -r "$i/include/$SEARCH_FOR"; then EXCEL_INCDIR=$i/include fi done @@ -40,13 +40,13 @@ if test "$PHP_EXCEL" != "no"; then SEARCH_FOR="libxl.${SHLIB_SUFFIX_NAME}" AC_MSG_CHECKING([for excel libraries]) - if test -r $PHP_LIBXL_LIBDIR/$PHP_LIBDIR/$SEARCH_FOR; then + if test -r "$PHP_LIBXL_LIBDIR/$PHP_LIBDIR/$SEARCH_FOR"; then EXCEL_LIBDIR=$PHP_LIBXL_LIBDIR/$PHP_LIBDIR - elif test -r $PHP_LIBXL_LIBDIR/$SEARCH_FOR; then + elif test -r "$PHP_LIBXL_LIBDIR/$SEARCH_FOR"; then EXCEL_LIBDIR=$PHP_LIBXL_LIBDIR elif test -z "$EXCEL_LIBDIR"; then for i in $SEARCH_PATH ; do - if test -r $i/$PHP_LIBDIR/$SEARCH_FOR; then + if test -r "$i/$PHP_LIBDIR/$SEARCH_FOR"; then EXCEL_LIBDIR=$i/$PHP_LIBDIR fi done @@ -60,13 +60,13 @@ if test "$PHP_EXCEL" != "no"; then fi AC_MSG_CHECKING([for libxml2]) - if test -r $PHP_LIBXML_DIR/libxml; then + if test -r "$PHP_LIBXML_DIR/libxml"; then LIBXML_INCDIR=$PHP_LIBXML_DIR fi if test -z "$LIBXML_INCDIR"; then AC_MSG_RESULT([not found]) - if test $PHP_ENABLE_LIBXML != "no"; then + if test "$PHP_ENABLE_LIBXML" != "no"; then AC_DEFINE(EXCEL_WITH_LIBXML, 1, [ ]) fi else From 34f4557957f1999c55df436fda450a0751c9762d Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Thu, 23 Jun 2016 10:15:38 -0400 Subject: [PATCH 37/68] 1.0.2 for php7 --- ChangeLog | 2 +- excel.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index d4a324c..023f4e9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,4 @@ -[2015-??-??] - Version 1.0.2 +[2016-06-23] - Version 1.0.2 * Fixed bug in ExcelSheet::addPictureDim() (see issue #120) * Fixed bug in ExcelSheet::isLicensed() (see issue #122) * Added new methods (requires LibXL 3.6.2) diff --git a/excel.c b/excel.c index 75a3ceb..d9c0ca8 100644 --- a/excel.c +++ b/excel.c @@ -54,7 +54,7 @@ static long xlFormatBorderColor(FormatHandle f) #define PHP_EXCEL_FORMULA 2 #define PHP_EXCEL_NUMERIC_STRING 3 -#define PHP_EXCEL_VERSION "1.0.2dev" +#define PHP_EXCEL_VERSION "1.0.2" #ifdef COMPILE_DL_EXCEL ZEND_GET_MODULE(excel) From de8111b667a2e8443d72362f9d9c20813dbe7d80 Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Thu, 23 Jun 2016 10:43:27 -0400 Subject: [PATCH 38/68] Back to dev --- ChangeLog | 2 ++ excel.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 023f4e9..ed8ae7a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,5 @@ +[2016-??-??] - Version 1.0.3dev + [2016-06-23] - Version 1.0.2 * Fixed bug in ExcelSheet::addPictureDim() (see issue #120) * Fixed bug in ExcelSheet::isLicensed() (see issue #122) diff --git a/excel.c b/excel.c index d9c0ca8..79bb5c0 100644 --- a/excel.c +++ b/excel.c @@ -54,7 +54,7 @@ static long xlFormatBorderColor(FormatHandle f) #define PHP_EXCEL_FORMULA 2 #define PHP_EXCEL_NUMERIC_STRING 3 -#define PHP_EXCEL_VERSION "1.0.2" +#define PHP_EXCEL_VERSION "1.0.3dev" #ifdef COMPILE_DL_EXCEL ZEND_GET_MODULE(excel) From d3a245c7b0c22ec726bab4257ec65fa6b717a7ce Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Sun, 26 Jun 2016 11:22:55 -0400 Subject: [PATCH 39/68] Fix for bug #163 --- config.m4 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/config.m4 b/config.m4 index 935a3db..4d22594 100644 --- a/config.m4 +++ b/config.m4 @@ -86,10 +86,15 @@ if test "$PHP_EXCEL" != "no"; then -L$EXCEL_LIBDIR ]) - PHP_CHECK_LIBRARY(xl,xlBookSetKeyA, + PHP_CHECK_LIBRARY(xl, xlBookSetKeyA, [ + PHP_ADD_INCLUDE($EXCEL_INCDIR) + PHP_ADD_INCLUDE($LIBXML_INCDIR) + PHP_ADD_LIBRARY_WITH_PATH(xl, $EXCEL_LIBDIR, EXCEL_SHARED_LIBADD) AC_DEFINE(HAVE_LIBXL_SETKEY,1,[ ]) - ],[],[]) + ],[],[ + -L$EXCEL_LIBDIR + ]) if test `grep -c FILLPATTERN_HORSTRIPE $EXCEL_INCDIR/enum.h` -eq 1; then AC_DEFINE(HAVE_LIBXL_243_PLUS,1,[ ]) From ce01f54fbdc6296d86cd8599f6d998e70a8112e9 Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Mon, 4 Jul 2016 10:17:15 -0400 Subject: [PATCH 40/68] Fixed crash when trying to read an empty file --- ChangeLog | 1 + excel.c | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index ed8ae7a..77ff90c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,5 @@ [2016-??-??] - Version 1.0.3dev + * Fixed crash when trying to read an empty file [2016-06-23] - Version 1.0.2 * Fixed bug in ExcelSheet::addPictureDim() (see issue #120) diff --git a/excel.c b/excel.c index 79bb5c0..7786929 100644 --- a/excel.c +++ b/excel.c @@ -414,7 +414,13 @@ EXCEL_METHOD(Book, loadFile) contents = php_stream_copy_to_mem(stream, PHP_STREAM_COPY_ALL, 0); php_stream_close(stream); - if (!contents || ZSTR_LEN(contents) < 1) { + if (!contents) { + php_error_docref(NULL, E_WARNING, "Source file is empty"); + RETURN_FALSE; + } + + if (ZSTR_LEN(contents) < 1) { + php_error_docref(NULL, E_WARNING, "Source file is empty"); zend_string_release(contents); RETURN_FALSE; } From 77f49b5af2421f1627b9e8ecd228afbc62fcb4ee Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Mon, 4 Jul 2016 19:44:42 -0400 Subject: [PATCH 41/68] Pecl package.xml for issue #124 --- ChangeLog | 1 + package.xml | 165 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 166 insertions(+) create mode 100644 package.xml diff --git a/ChangeLog b/ChangeLog index 77ff90c..742391b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ [2016-??-??] - Version 1.0.3dev * Fixed crash when trying to read an empty file + * Added PECL package.xml to allow installation via pecl [2016-06-23] - Version 1.0.2 * Fixed bug in ExcelSheet::addPictureDim() (see issue #120) diff --git a/package.xml b/package.xml new file mode 100644 index 0000000..9cf103b --- /dev/null +++ b/package.xml @@ -0,0 +1,165 @@ + + +excel + pecl.php.net + excel extension + +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... + + + Ilia Alshanetsky + iliaa + ilia@ilia.ws + yes + + 2016-07-04 + + 1.0.2 + 1.0.2 + + + stable + stable + + PHP + + - Version 1.0.9 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 7.0.0 + + + 1.4.0b1 + + + + excel + + + From a6b8cc4605801b173dc3dc4ec5b42442356f3cd1 Mon Sep 17 00:00:00 2001 From: Johannes Mueller Date: Wed, 7 Sep 2016 23:08:30 +0200 Subject: [PATCH 42/68] patch for issue #168 --- excel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/excel.c b/excel.c index 7786929..7974ea3 100644 --- a/excel.c +++ b/excel.c @@ -5015,7 +5015,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_clear, 0, 0, 4) ZEND_ARG_INFO(0, row_s) ZEND_ARG_INFO(0, row_e) ZEND_ARG_INFO(0, col_s) - ZEND_ARG_INFO(0, col_s) + ZEND_ARG_INFO(0, col_e) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_copy, 0, 0, 4) From d1cb308b2799ce90052631b13c3748623480ea1d Mon Sep 17 00:00:00 2001 From: Johannes Mueller Date: Mon, 24 Oct 2016 00:35:20 +0200 Subject: [PATCH 43/68] initial commit for libxl 3.7.x --- docs/ExcelAutoFilter.php | 107 ++++ docs/ExcelFilterColumn.php | 143 +++++ docs/ExcelSheet.php | 116 +++- excel.c | 1188 ++++++++++++++++++++++++++++++++---- 4 files changed, 1438 insertions(+), 116 deletions(-) create mode 100644 docs/ExcelAutoFilter.php create mode 100644 docs/ExcelFilterColumn.php diff --git a/docs/ExcelAutoFilter.php b/docs/ExcelAutoFilter.php new file mode 100644 index 0000000..913fdea --- /dev/null +++ b/docs/ExcelAutoFilter.php @@ -0,0 +1,107 @@ + | + | | + | php_excel "PECL" style module (http://github.com/iliaal/php_excel) | + | libxl library (http://www.libxl.com) | + | | + +---------------------------------------------------------------------------+ +*/ +class ExcelAutoFilter +{ + /** + * Create a AutoFilter within an Excel sheet + * + * @see ExcelSheet::autofilter() + * @param ExcelSheet $sheet + * @return ExcelAutoFilter + */ + public function __construct($sheet) + { + } // __construct + + /** + * Gets the cell range of AutoFilter with header. + * + * @return array with keys "row_first"(int), "col_first"(int), "row_last"(int), "col_last"(int) + */ + public function getRef() + { + } // getRef + + /** + * Sets the cell range of AutoFilter with header. + * + * @param int $row_first 0-based (optional, default = 0) + * @param int $col_first 0-based (optional, default = 0) + * @param int $row_last 0-based (optional, default = 0) + * @param int $col_last 0-based (optional, default = 0) + * @return void + */ + public function setRef($row_first=0, $col_first=0, $row_last=0, $col_last=0) + { + } // setRef + + /** + * Returns the AutoFilter column by zero-based index. Creates it if it doesn't exist. + * + * @param int $colId 0-based + * @return ExcelFilterColumn + */ + public function column($colId) + { + } // column + + /** + * Returns the number of specified AutoFilter columns which have a filter information. + * + * @return int + */ + public function columnSize() + { + } // columnSize + + /** + * Returns the specified AutoFilter column which have a filter information by index. + * + * @param int $index 0-based + * @return ExcelFilterColumn + */ + public function columnByIndex($index) + { + } // columnByIndex + + /** + * Gets the whole range of data to sort. + * + * @return array with keys "row_first"(int), "col_first"(int), "row_last"(int), "col_last"(int) + */ + public function getSortRange() + { + } // getSortRange + + /** + * Gets the zero-based index of sorted column in AutoFilter and its sort order. + * + * @return array with keys "column_index"(int), "descending"(bool), + */ + public function getSort() + { + } // getSort + + /** + * Sets the sorted column in AutoFilter by zero-based index and its sort order. + * + * @param int $columnIndex 0-based + * @param bool $descending + * @return bool + */ + public function setSort($columnIndex, $descending) + { + } // setSort + +} // end ExcelAutoFilter diff --git a/docs/ExcelFilterColumn.php b/docs/ExcelFilterColumn.php new file mode 100644 index 0000000..a8db48a --- /dev/null +++ b/docs/ExcelFilterColumn.php @@ -0,0 +1,143 @@ + | + | | + | php_excel "PECL" style module (http://github.com/iliaal/php_excel) | + | libxl library (http://www.libxl.com) | + | | + +---------------------------------------------------------------------------+ +*/ +class ExcelFilterColumn +{ + const FILTER_VALUE = 0; + const FILTER_TOP10 = 1; + const FILTER_CUSTOM = 2; + const FILTER_DYNAMIC = 3; + const FILTER_COLOR = 4; + const FILTER_ICON = 5; + const FILTER_EXT = 6; + const FILTER_NOT_SET = 7; + + const OPERATOR_EQUAL = 0; + const OPERATOR_GREATER_THAN = 1; + const OPERATOR_GREATER_THAN_OR_EQUAL = 2; + const OPERATOR_LESS_THAN = 3; + const OPERATOR_LESS_THAN_OR_EQUAL = 4; + const OPERATOR_NOT_EQUAL = 5; + + /** + * Create a filter column within an Excel auto filter + * + * @see ExcelAutoFilter::column() + * @param ExcelAutoFilter $autoFilter + * @return ExcelFilterColumn + */ + public function __construct($autoFilter) + { + } // __construct + + /** + * Returns the zero-based index of this AutoFilter column. + * + * @return int + */ + public function index() + { + } // index + + /** + * Returns the filter type of this AutoFilter column. + * + * @return int One of ExcelFilterColumn::FILTER_* constants + */ + public function filterType() + { + } // filterType + + /** + * Returns the number of filter values. + * + * @return int + */ + public function filterSize() + { + } // filterSize + + /** + * Returns the filter value by index. + * + * @param int $index + * @return string filter value + */ + public function filter($index) + { + } // filter + + /** + * Adds the filter value. + * + * @param string $filterValue + * @return void + */ + public function addFilter($filterValue) + { + } // addFilter + + /** + * Gets the number of top or bottom items: + * + * @return array with keys "value"(float), "top"(bool) and "percent"(bool) + */ + public function getTop10() + { + } // getTop10 + + /** + * Sets the number of top or bottom items: + * + * @param float $value - number of items; + * @param bool $top - top items if true otherwise bottom items; (optional, default = true) + * @param bool $percent - using percent instead of number items. (optional, default = false) + * @return bool + */ + public function setTop10($value, $top=true, $percent=false) + { + } // setTop10 + + /** + * Gets the custom filter criteria: + * + * @return array with keys "operator_1"(int), "value_1"(string), "operator_2"(int), "value_2"(string) and "andOp"(bool) + */ + public function getCustomFilter() + { + } // getCustomFilter + + /** + * Sets the custom filter criteria. + * + * @param int $op1 - one of ExcelFilterColumn::OPERATOR_* constants - operator used by the filter comparison in the first filter criteria; + * @param string $v1 - value used in the first filter criteria; + * @param int $op2 - one of ExcelFilterColumn::OPERATOR_* constants - operator used by the filter comparison in the second filter criteria; (optional, default = -1) + * @param string $v2 - value used in the second filter criteria; (optional, default = null) + * @param bool $andOp - flag indicating whether the two criterias have an "and" relationship. True indicates "and", false indicates "or". (optional, default = false) + * @return void + */ + public function setCustomFilter($op1, $v1, $op2=-1, $v2=null, $andOp=false) + { + } // setCustomFilter + + /** + * Clear the filter criteria. + * + * @return bool + */ + public function clear() + { + } // clear + +} // end ExcelFilterColumn diff --git a/docs/ExcelSheet.php b/docs/ExcelSheet.php index 372e9f0..28b1fce 100644 --- a/docs/ExcelSheet.php +++ b/docs/ExcelSheet.php @@ -75,6 +75,33 @@ class ExcelSheet const LEFT_TO_RIGHT = 0; const RIGHT_TO_LEFT = 1; + const IERR_EVAL_ERROR = 1; + const IERR_EMPTY_CELLREF = 2; + const IERR_NUMBER_STORED_AS_TEXT = 4; + const IERR_INCONSIST_RANGE = 8; + const IERR_INCONSIST_FMLA = 16; + const IERR_TWODIG_TEXTYEAR = 32; + const IERR_UNLOCK_FMLA = 64; + const IERR_DATA_VALIDATION = 128; + + const PROT_DEFAULT = -1; + const PROT_ALL = 0; + const PROT_OBJECTS = 1; + const PROT_SCENARIOS = 2; + const PROT_FORMAT_CELLS = 4; + const PROT_FORMAT_COLUMNS = 8; + const PROT_FORMAT_ROWS = 16; + const PROT_INSERT_COLUMNS = 32; + const PROT_INSERT_ROWS = 64; + const PROT_INSERT_HYPERLINKS = 128; + const PROT_DELETE_COLUMNS = 256; + const PROT_DELETE_ROWS = 512; + const PROT_SEL_LOCKED_CELLS = 1024; + const PROT_SORT = 2048; + const PROT_AUTOFILTER = 4096; + const PROT_PIVOTTABLES = 8192; + const PROT_SEL_UNLOCKED_CELLS = 16384; + /** * Create an ExcelSheet in given Workbook * @@ -100,6 +127,20 @@ public function addHyperlink($hyperlink, $row_first, $row_last, $col_first, $col { } // addHyperlink + /** + * Adds the ignored error for specified range. It allows to hide green triangles on left sides of cells. + * + * @param int $error - one of the ExcelSheet::IERR_* constants + * @param int $row_first 0-based (optional, default = 0) + * @param int $col_first 0-based (optional, default = 0) + * @param int $row_last 0-based (optional, default = 0) + * @param int $col_last 0-based (optional, default = 0) + * @return bool + */ + public function addIgnoredError($error, $row_first=0, $col_first=0, $row_last=0, $col_last=0) + { + } // addIgnoredError + /** * Insert a picture into a cell with given dimensions * @@ -147,6 +188,33 @@ public function addrToRowCol($cell_reference) { } // addrToRowCol + /** + * Returns the AutoFilter. Creates it if it doesn't exist. + * + * @return ExcelAutoFilter + */ + public function autoFilter() + { + } // autoFilter + + /** + * Applies the AutoFilter to the sheet. + * + * @return bool + */ + public function applyFilter() + { + } // applyFilter + + /** + * Removes the AutoFilter from the sheet. + * + * @return bool + */ + public function removeFilter() + { + } // removeFilter + /** * Get the cell format * @@ -163,7 +231,7 @@ public function cellFormat($row, $column) * * @param int $row 0-based row number * @param int $column 0-based column number - * @return int One of ExcelSheet:CELLTYPE_* constants + * @return int One of ExcelSheet::CELLTYPE_* constants */ public function cellType($row, $column) { @@ -1237,6 +1305,16 @@ public function setPrintRepeatCols($column_start, $column_end) { } // setPrintRepeatCols + /** + * Sets the color for the sheet's tab. + * + * @param int $color - one of the ExcelSheet::COLOR_* constants (optional, default=0) + * @return bool + */ + public function setTabColor($color=0) + { + } // setTabColor + /** * Gets repeated columns on each page from colFirst to colLast. Returns false * if repeated columns aren't found. @@ -1275,9 +1353,11 @@ public function printRepeatRows() * * @see ExcelSheet::protect() * @param bool $value + * @param string $password (optional, default="") + * @param int ExcelSheet::PROT_ALL (optional, default=ExcelSheet::PROT_DEFAULT) * @return void */ - public function setProtect($value) + public function setProtect($value, $password="", $enhancedProtection=ExcelSheet::PROT_DEFAULT) { } // setProtect @@ -1384,6 +1464,25 @@ public function splitSheet($row, $column) { } // splitSheet + /** + * Gets the table parameters by index. + * + * @param int $index (optional, default = 0) + * @return array with keys "name"(string), "row_first"(int), "col_first"(int), "row_last"(int), "col_last"(int), "header_row_count"(int) and "totals_row_count"(int) + */ + public function table($index=0) + { + } // table + + /** + * Returns the number of tables in the sheet. + * + * @return int + */ + public function tableSize() + { + } // tableSize + /** * Returns whether the sheet is centered vertically when printed * @@ -1450,6 +1549,19 @@ public function writeComment($row, $column, $comment, $author, $width, $height) { } // writeComment + /** + * Writes error into the cell with specified format. If format equals 0 then format is ignored. + * + * @param int $row (optional, default = 0) + * @param int $col (optional, default = 0) + * @param int $error - one of ExcelSheet::ERRORTYPE_* constants (optional, default = 0) + * @param ExcelFormat $format (optional, default = null) + * @return bool + */ + public function writeError($row=0, $col=0, $error=0, $format=null) + { + } // writeError + /** * Write an array of values into a row * diff --git a/excel.c b/excel.c index 7974ea3..8593331 100644 --- a/excel.c +++ b/excel.c @@ -85,12 +85,20 @@ PHP_INI_END() excel_object_handlers_ ## c_name .clone_obj = clone; \ } +#if LIBXL_VERSION < 0x03070000 zend_class_entry *excel_ce_book, *excel_ce_sheet, *excel_ce_format, *excel_ce_font; +#else +zend_class_entry *excel_ce_book, *excel_ce_sheet, *excel_ce_format, *excel_ce_font, *excel_ce_filtercolumn, *excel_ce_autofilter; +#endif static zend_object_handlers excel_object_handlers_book; static zend_object_handlers excel_object_handlers_sheet; static zend_object_handlers excel_object_handlers_format; static zend_object_handlers excel_object_handlers_font; +#if LIBXL_VERSION >= 0x03070000 +static zend_object_handlers excel_object_handlers_autofilter; +static zend_object_handlers excel_object_handlers_filtercolumn; +#endif typedef struct _excel_book_object { BookHandle book; @@ -177,6 +185,28 @@ static inline excel_font_object *php_excel_font_object_fetch_object(zend_object } \ } +#if LIBXL_VERSION >= 0x03070000 +#define AUTOFILTER_FROM_OBJECT(autofilter, object) \ + { \ + excel_autofilter_object *obj = Z_EXCEL_AUTOFILTER_OBJ_P(object); \ + autofilter = obj->autofilter; \ + if (!autofilter) { \ + php_error_docref(NULL, E_WARNING, "The autofilter wasn't initialized"); \ + RETURN_FALSE; \ + } \ + } + +#define FILTERCOLUMN_FROM_OBJECT(filtercolumn, object) \ + { \ + excel_filtercolumn_object *obj = Z_EXCEL_FILTERCOLUMN_OBJ_P(object); \ + filtercolumn = obj->filtercolumn; \ + if (!filtercolumn) { \ + php_error_docref(NULL, E_WARNING, "The filtercolumn wasn't initialized"); \ + RETURN_FALSE; \ + } \ + } +#endif + typedef struct _excel_format_object { FormatHandle format; BookHandle book; @@ -188,6 +218,30 @@ static inline excel_format_object *php_excel_format_object_fetch_object(zend_obj } #define Z_EXCEL_FORMAT_OBJ_P(zv) php_excel_format_object_fetch_object(Z_OBJ_P(zv)); +#if LIBXL_VERSION >= 0x03070000 +typedef struct _excel_autofilter_object { + AutoFilterHandle autofilter; + SheetHandle sheet; + zend_object std; +} excel_autofilter_object; + +static inline excel_autofilter_object *php_excel_autofilter_object_fetch_object(zend_object *obj) { + return (excel_autofilter_object *)((char *)(obj) - XtOffsetOf(excel_autofilter_object, std)); +} +#define Z_EXCEL_AUTOFILTER_OBJ_P(zv) php_excel_autofilter_object_fetch_object(Z_OBJ_P(zv)); + +typedef struct _excel_filtercolumn_object { + FilterColumnHandle filtercolumn; + AutoFilterHandle autofilter; + zend_object std; +} excel_filtercolumn_object; + +static inline excel_filtercolumn_object *php_excel_filtercolumn_object_fetch_object(zend_object *obj) { + return (excel_filtercolumn_object *)((char *)(obj) - XtOffsetOf(excel_filtercolumn_object, std)); +} +#define Z_EXCEL_FILTERCOLUMN_OBJ_P(zv) php_excel_filtercolumn_object_fetch_object(Z_OBJ_P(zv)); +#endif + static void excel_book_object_free_storage(zend_object *object) { excel_book_object *intern = php_excel_book_object_fetch_object(object); @@ -347,6 +401,70 @@ static zend_object *excel_format_object_clone(zval *this_ptr) return new_ov; } +#if LIBXL_VERSION >= 0x03070000 +static void excel_autofilter_object_free_storage(zend_object *object) +{ + excel_autofilter_object *intern = php_excel_autofilter_object_fetch_object(object); + zend_object_std_dtor(&intern->std); +} + +static zend_object *excel_object_new_autofilter_ex(zend_class_entry *class_type, excel_autofilter_object **ptr) +{ + excel_autofilter_object *intern; + + intern = ecalloc(1, + sizeof(excel_autofilter_object) + + sizeof(zval) * (class_type->default_properties_count - 1)); + + if (ptr) { + *ptr = intern; + } + + zend_object_std_init(&intern->std, class_type); + object_properties_init(&intern->std, class_type); + + intern->std.handlers = &excel_object_handlers_autofilter; + + return &intern->std; +} + +static zend_object *excel_object_new_autofilter(zend_class_entry *class_type) +{ + return excel_object_new_autofilter_ex(class_type, NULL); +} + +static void excel_filtercolumn_object_free_storage(zend_object *object) +{ + excel_filtercolumn_object *intern = php_excel_filtercolumn_object_fetch_object(object); + zend_object_std_dtor(&intern->std); +} + +static zend_object *excel_object_new_filtercolumn_ex(zend_class_entry *class_type, excel_filtercolumn_object **ptr) +{ + excel_filtercolumn_object *intern; + + intern = ecalloc(1, + sizeof(excel_filtercolumn_object) + + sizeof(zval) * (class_type->default_properties_count - 1)); + + if (ptr) { + *ptr = intern; + } + + zend_object_std_init(&intern->std, class_type); + object_properties_init(&intern->std, class_type); + + intern->std.handlers = &excel_object_handlers_filtercolumn; + + return &intern->std; +} + +static zend_object *excel_object_new_filtercolumn(zend_class_entry *class_type) +{ + return excel_object_new_filtercolumn_ex(class_type, NULL); +} +#endif + #define EXCEL_METHOD(class_name, function_name) \ PHP_METHOD(Excel ## class_name, function_name) @@ -4052,6 +4170,7 @@ EXCEL_METHOD(Sheet, protect) } /* }}} */ +#if LIBXL_VERSION < 0x03070000 /* {{{ proto void ExcelSheet::setProtect(bool value) Protects (protect = 1) or unprotects (protect = 0) the sheet. */ EXCEL_METHOD(Sheet, setProtect) @@ -4059,6 +4178,7 @@ EXCEL_METHOD(Sheet, setProtect) PHP_EXCEL_SET_BOOL_VAL(SetProtect) } /* }}} */ +#endif /* {{{ proto long ExcelSheet::hyperlinkSize() Returns the number of hyperlinks in the sheet. */ @@ -4486,149 +4606,771 @@ EXCEL_METHOD(Sheet, printArea) #endif -ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_requiresKey, 0, 0, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_load, 0, 0, 1) - ZEND_ARG_INFO(0, data) -ZEND_END_ARG_INFO() +#if LIBXL_VERSION >= 0x03070000 +/* {{{ proto void ExcelSheet::setProtect(bool protect, string password, int enhancedProtection) + Protects the sheet with password and enchanced parameters below. It is possible to combine a few EnhancedProtection values with operator |. */ +EXCEL_METHOD(Sheet, setProtect) +{ + zval *object = getThis(); + SheetHandle sheet; + zend_bool protect; + zend_string *password_zs = zend_string_init("", sizeof("")-1, 0); + zend_long enhancedProtection = PROT_DEFAULT; -ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_loadFile, 0, 0, 1) - ZEND_ARG_INFO(0, filename) -ZEND_END_ARG_INFO() + if (zend_parse_parameters(ZEND_NUM_ARGS(), "b|Sl", &protect, &password_zs, &enhancedProtection) == FAILURE) { + RETURN_FALSE; + } -ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_save, 0, 0, 0) - ZEND_ARG_INFO(0, filename) -ZEND_END_ARG_INFO() + SHEET_FROM_OBJECT(sheet, object); -ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_getSheet, 0, 0, 0) - ZEND_ARG_INFO(0, sheet) -ZEND_END_ARG_INFO() + xlSheetSetProtectEx(sheet, protect, ZSTR_VAL(password_zs), enhancedProtection); -ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_getSheetByName, 0, 0, 1) - ZEND_ARG_INFO(0, name) - ZEND_ARG_INFO(0, case_insensitive) -ZEND_END_ARG_INFO() + RETURN_TRUE; +} +/* }}} */ -ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_deleteSheet, 0, 0, 1) - ZEND_ARG_INFO(0, sheet) -ZEND_END_ARG_INFO() +/* {{{ proto long ExcelSheet::table() + Gets the table parameters by index. */ +EXCEL_METHOD(Sheet, table) +{ + zval *object = getThis(); + SheetHandle sheet; + zend_long index=0, rowFirst, rowLast, colFirst, colLast, headerRowCount, totalsRowCount; + const char *name; -ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_activeSheet, 0, 0, 0) - ZEND_ARG_INFO(0, sheet) -ZEND_END_ARG_INFO() + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) { + RETURN_FALSE; + } -ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_addSheet, 0, 0, 1) - ZEND_ARG_INFO(0, name) -ZEND_END_ARG_INFO() + SHEET_FROM_OBJECT(sheet, object); -ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_copySheet, 0, 0, 2) - ZEND_ARG_INFO(0, name) - ZEND_ARG_INFO(0, sheet_number) -ZEND_END_ARG_INFO() + // @todo check for XLSX format + if (!(name = xlSheetTable(sheet, index, &rowFirst, &rowLast, &colFirst, &colLast, &headerRowCount, &totalsRowCount))) { + RETURN_FALSE; + } -ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_sheetCount, 0, 0, 0) -ZEND_END_ARG_INFO() + array_init(return_value); + add_assoc_string(return_value, "name", (char *)name); + add_assoc_long(return_value, "row_first", rowFirst); + add_assoc_long(return_value, "col_first", colFirst); + add_assoc_long(return_value, "row_last", rowLast); + add_assoc_long(return_value, "col_last", colLast); + add_assoc_long(return_value, "header_row_count", headerRowCount); + add_assoc_long(return_value, "totals_row_count", totalsRowCount); +} +/* }}} */ -ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_getError, 0, 0, 0) -ZEND_END_ARG_INFO() +/* {{{ proto long ExcelSheet::setTabColor([int color]) + Sets the color for the sheet's tab. */ +EXCEL_METHOD(Sheet, setTabColor) +{ + zval *object = getThis(); + SheetHandle sheet; + zend_long color = 0; -ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_addFont, 0, 0, 0) - ZEND_ARG_OBJ_INFO(0, font, ExcelFont, 0) -ZEND_END_ARG_INFO() + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &color) == FAILURE) { + RETURN_FALSE; + } -ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_addFormat, 0, 0, 0) - ZEND_ARG_OBJ_INFO(0, format, ExcelFormat, 1) -ZEND_END_ARG_INFO() + SHEET_FROM_OBJECT(sheet, object); -ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_getAllFormats, 0, 0, 0) -ZEND_END_ARG_INFO() + // @todo check for XLSX format + xlSheetSetTabColor(sheet, color); + RETURN_TRUE; +} +/* }}} */ -ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_addCustomFormat, 0, 0, 1) - ZEND_ARG_INFO(0, format) -ZEND_END_ARG_INFO() +/* {{{ proto long ExcelSheet::autoFilter() + Returns the AutoFilter. Creates it if it doesn't exist. */ +EXCEL_METHOD(Sheet, autoFilter) +{ + zval *object = getThis(); + excel_autofilter_object *obj; + SheetHandle sheet; -ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_getCustomFormat, 0, 0, 1) - ZEND_ARG_INFO(0, id) -ZEND_END_ARG_INFO() + SHEET_FROM_OBJECT(sheet, object); -ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_packDate, 0, 0, 1) - ZEND_ARG_INFO(0, timestamp) -ZEND_END_ARG_INFO() + // @todo check for XLSX format + AutoFilterHandle ah = xlSheetAutoFilter(sheet); -ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_packDateValues, 0, 0, 6) - ZEND_ARG_INFO(0, year) - ZEND_ARG_INFO(0, month) - ZEND_ARG_INFO(0, day) - ZEND_ARG_INFO(0, hour) - ZEND_ARG_INFO(0, min) - ZEND_ARG_INFO(0, sec) -ZEND_END_ARG_INFO() + ZVAL_OBJ(return_value, excel_object_new_autofilter(excel_ce_autofilter)); + obj = Z_EXCEL_AUTOFILTER_OBJ_P(return_value); + obj->autofilter = ah; + obj->sheet = sheet; -ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_unpackDate, 0, 0, 1) - ZEND_ARG_INFO(0, date) -ZEND_END_ARG_INFO() + RETURN_TRUE; +} +/* }}} */ -ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_getActiveSheet, 0, 0, 0) -ZEND_END_ARG_INFO() +/* {{{ proto long ExcelSheet::applyFilter() + Applies the AutoFilter to the sheet. */ +EXCEL_METHOD(Sheet, applyFilter) +{ + zval *object = getThis(); + SheetHandle sheet; -ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_getDefaultFont, 0, 0, 0) -ZEND_END_ARG_INFO() + SHEET_FROM_OBJECT(sheet, object); -ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_isDate1904, 0, 0, 0) -ZEND_END_ARG_INFO() + // @todo check for XLSX format + xlSheetApplyFilter(sheet); -ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_setDate1904, 0, 0, 1) - ZEND_ARG_INFO(0, date_type) -ZEND_END_ARG_INFO() + RETURN_TRUE; +} +/* }}} */ -ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_setDefaultFont, 0, 0, 2) - ZEND_ARG_INFO(0, font) - ZEND_ARG_INFO(0, font_size) -ZEND_END_ARG_INFO() +/* {{{ proto long ExcelSheet::removeFilter() + Removes the AutoFilter from the sheet. */ +EXCEL_METHOD(Sheet, removeFilter) +{ + zval *object = getThis(); + SheetHandle sheet; -ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_setLocale, 0, 0, 1) - ZEND_ARG_INFO(0, locale) -ZEND_END_ARG_INFO() + SHEET_FROM_OBJECT(sheet, object); -ZEND_BEGIN_ARG_INFO_EX(arginfo_Book___construct, 0, 0, 0) - ZEND_ARG_INFO(0, license_name) - ZEND_ARG_INFO(0, license_key) - ZEND_ARG_INFO(0, excel_2007) -ZEND_END_ARG_INFO() + // @todo check for XLSX format + xlSheetRemoveFilter(sheet); -ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_setActiveSheet, 0, 0, 1) - ZEND_ARG_INFO(0, sheet) -ZEND_END_ARG_INFO() + RETURN_TRUE; +} +/* }}} */ -ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_addPictureFromFile, 0, 0, 1) - ZEND_ARG_INFO(0, filename) -ZEND_END_ARG_INFO() +/* {{{ proto long ExcelSheet::addIgnoredError() + Adds the ignored error for specified range. It allows to hide green triangles on left sides of cells. */ +EXCEL_METHOD(Sheet, addIgnoredError) +{ + zval *object = getThis(); + SheetHandle sheet; + zend_long iError, rowFirst=0, colFirst=0, rowLast=0, colLast=0; -ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_addPictureFromString, 0, 0, 1) - ZEND_ARG_INFO(0, data) -ZEND_END_ARG_INFO() + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|llll", &iError, &rowFirst, &colFirst, &rowLast, &colLast) == FAILURE) { + RETURN_FALSE; + } -ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_rgbMode, 0, 0, 0) -ZEND_END_ARG_INFO() + SHEET_FROM_OBJECT(sheet, object); -ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_setRGBMode, 0, 0, 1) - ZEND_ARG_INFO(0, mode) -ZEND_END_ARG_INFO() + if (!xlSheetAddIgnoredError(sheet, rowFirst, colFirst, rowLast, colLast, iError)) { + RETURN_FALSE + } -ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_colorPack, 0, 0, 3) - ZEND_ARG_INFO(0, r) - ZEND_ARG_INFO(0, g) - ZEND_ARG_INFO(0, b) -ZEND_END_ARG_INFO() + RETURN_TRUE; +} +/* }}} */ -ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_colorUnpack, 0, 0, 1) - ZEND_ARG_INFO(0, color) -ZEND_END_ARG_INFO() +/* {{{ proto long ExcelSheet::writeError() + Writes error into the cell with specified format. If format equals 0 then format is ignored. */ +EXCEL_METHOD(Sheet, writeError) +{ + zval *object = getThis(); + SheetHandle sheet; + zend_long iError=0, row=0, col=0; + zval *oformat = NULL; + FormatHandle format = NULL; -ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_setRefR1C1, 0, 0, 1) - ZEND_ARG_INFO(0, active) -ZEND_END_ARG_INFO() + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|lllo", &row, &col, &iError, &oformat, excel_ce_format) == FAILURE) { + RETURN_FALSE; + } + + SHEET_FROM_OBJECT(sheet, object); + FORMAT_FROM_OBJECT(format, oformat); + + xlSheetWriteError(sheet, row, col, iError, format); +} +/* }}} */ + +/* {{{ proto long ExcelSheet::removeComment() + Removes a comment from the cell (only for xls format). */ +EXCEL_METHOD(Sheet, removeComment) +{ + zval *object = getThis(); + SheetHandle sheet; + zend_long row=0, col=0; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll", &row, &col) == FAILURE) { + RETURN_FALSE; + } + + SHEET_FROM_OBJECT(sheet, object); + + xlSheetRemoveComment(sheet, row, col); +} +/* }}} */ + +/* {{{ proto ExcelAutoFilter ExcelAutoFilter::__construct(ExcelSheet sheet) + Sheet Constructor. */ +EXCEL_METHOD(AutoFilter, __construct) +{ + AutoFilterHandle afh; + SheetHandle sheet; + zval *object = getThis(); + excel_autofilter_object *obj; + zval *zsheet = NULL; + + PHP_EXCEL_ERROR_HANDLING(); + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &zsheet, excel_ce_sheet) == FAILURE) { + PHP_EXCEL_RESTORE_ERRORS(); + return; + } + PHP_EXCEL_RESTORE_ERRORS(); + + if (!zsheet) { + RETURN_FALSE; + } + + SHEET_FROM_OBJECT(sheet, zsheet); + + obj = Z_EXCEL_AUTOFILTER_OBJ_P(object); + + afh = xlSheetAutoFilter(sheet); + + if (!afh) { + RETURN_FALSE; + } + + obj->sheet = sheet; + obj->autofilter = afh; +} +/* }}} */ + +/* {{{ proto long AutoFilter::getRef() + Gets the cell range of AutoFilter with header. Returns 0 if error. */ +EXCEL_METHOD(AutoFilter, getRef) +{ + zval *object = getThis(); + AutoFilterHandle autofilter; + int rowFirst=0, colFirst=0, rowLast=0, colLast=0; + + AUTOFILTER_FROM_OBJECT(autofilter, object); + + if (!xlAutoFilterGetRef(autofilter, &rowFirst, &colFirst, &rowLast, &colLast)) { + RETURN_FALSE; + } + + array_init(return_value); + add_assoc_long(return_value, "row_first", rowFirst); + add_assoc_long(return_value, "col_first", colFirst); + add_assoc_long(return_value, "row_last", rowLast); + add_assoc_long(return_value, "col_last", rowLast); +} +/* }}} */ + +/* {{{ proto long AutoFilter::setRef() + Sets the cell range of AutoFilter with header. */ +EXCEL_METHOD(AutoFilter, setRef) +{ + zval *object = getThis(); + AutoFilterHandle autofilter; + zend_long rowFirst=0, colFirst=0, rowLast=0, colLast=0; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "llll", &rowFirst, &colFirst, &rowLast, &colLast) == FAILURE) { + RETURN_FALSE; + } + + AUTOFILTER_FROM_OBJECT(autofilter, object); + + xlAutoFilterSetRef(autofilter, rowFirst, colFirst, rowLast, colLast); +} +/* }}} */ + +/* {{{ proto long AutoFilter::column() + Returns the AutoFilter column by zero-based index. Creates it if it doesn't exist. */ +EXCEL_METHOD(AutoFilter, column) +{ + zval *object = getThis(); + AutoFilterHandle autofilter; + zend_long colId; + excel_filtercolumn_object *obj; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &colId) == FAILURE) { + RETURN_FALSE; + } + + AUTOFILTER_FROM_OBJECT(autofilter, object); + + FilterColumnHandle fch = xlAutoFilterColumn(autofilter, colId); + + ZVAL_OBJ(return_value, excel_object_new_filtercolumn(excel_ce_filtercolumn)); + obj = Z_EXCEL_FILTERCOLUMN_OBJ_P(return_value); + obj->autofilter = autofilter; + obj->filtercolumn = fch; + + RETURN_TRUE; +} +/* }}} */ + +/* {{{ proto long AutoFilter::columnSize() + Returns the number of specified AutoFilter columns which have a filter information. */ +EXCEL_METHOD(AutoFilter, columnSize) +{ + zval *object = getThis(); + AutoFilterHandle autofilter; + + AUTOFILTER_FROM_OBJECT(autofilter, object); + + RETURN_LONG(xlAutoFilterColumnSize(autofilter)); +} +/* }}} */ + +/* {{{ proto long AutoFilter::columnByIndex() + Returns the specified AutoFilter column which have a filter information by index. */ +EXCEL_METHOD(AutoFilter, columnByIndex) +{ + zval *object = getThis(); + AutoFilterHandle autofilter; + excel_filtercolumn_object *obj; + zend_long index; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) { + RETURN_FALSE; + } + + AUTOFILTER_FROM_OBJECT(autofilter, object); + + FilterColumnHandle fch = xlAutoFilterColumnByIndex(autofilter, index); + + ZVAL_OBJ(return_value, excel_object_new_filtercolumn(excel_ce_filtercolumn)); + obj = Z_EXCEL_FILTERCOLUMN_OBJ_P(return_value); + obj->autofilter = autofilter; + obj->filtercolumn = fch; + + RETURN_TRUE; +} +/* }}} */ + +/* {{{ proto long AutoFilter::getSortRange() + Gets the whole range of data to sort. Returns 0 if error. */ +EXCEL_METHOD(AutoFilter, getSortRange) +{ + zval *object = getThis(); + AutoFilterHandle autofilter; + int rowFirst=0, colFirst=0, rowLast=0, colLast=0; + + AUTOFILTER_FROM_OBJECT(autofilter, object); + + if (!xlAutoFilterGetSortRange(autofilter, &rowFirst, &colFirst, &rowLast, &colLast)) { + RETURN_FALSE; + } + + array_init(return_value); + add_assoc_long(return_value, "row_first", rowFirst); + add_assoc_long(return_value, "col_first", colFirst); + add_assoc_long(return_value, "row_last", rowLast); + add_assoc_long(return_value, "col_last", rowLast); +} +/* }}} */ + +/* {{{ proto long AutoFilter::getSort() + Gets the zero-based index of sorted column in AutoFilter and its sort order. Returns 0 if error. */ +EXCEL_METHOD(AutoFilter, getSort) +{ + zval *object = getThis(); + AutoFilterHandle autofilter; + int columnIndex, descending; + + AUTOFILTER_FROM_OBJECT(autofilter, object); + + if (!xlAutoFilterGetSort(autofilter, &columnIndex, &descending)) { + RETURN_FALSE; + } + + array_init(return_value); + add_assoc_long(return_value, "column_index", columnIndex); + add_assoc_long(return_value, "descending", descending); +} +/* }}} */ + +/* {{{ proto long AutoFilter::setSort() + Sets the sorted column in AutoFilter by zero-based index and its sort order. Returns 0 if error. */ +EXCEL_METHOD(AutoFilter, setSort) +{ + zval *object = getThis(); + AutoFilterHandle autofilter; + zend_long columnIndex; + zend_bool descending; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "lb", &columnIndex, &descending) == FAILURE) { + RETURN_FALSE; + } + + AUTOFILTER_FROM_OBJECT(autofilter, object); + + if (!xlAutoFilterSetSort(autofilter, columnIndex, descending)) { + RETURN_FALSE; + } + + RETURN_TRUE; +} +/* }}} */ + +/* {{{ proto ExcelFilterColumn ExcelFilterColumn::__construct(ExcelAutoFilter autofilter) + Sheet Constructor. */ +EXCEL_METHOD(FilterColumn, __construct) +{ + FilterColumnHandle fch; + AutoFilterHandle autofilter; + zval *object = getThis(); + excel_filtercolumn_object *obj; + zval *zautofilter = NULL; + zend_long colId; + + PHP_EXCEL_ERROR_HANDLING(); + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ol", &zautofilter, excel_ce_autofilter, &colId) == FAILURE) { + PHP_EXCEL_RESTORE_ERRORS(); + return; + } + PHP_EXCEL_RESTORE_ERRORS(); + + if (!zautofilter) { + RETURN_FALSE; + } + + AUTOFILTER_FROM_OBJECT(autofilter, zautofilter); + + obj = Z_EXCEL_FILTERCOLUMN_OBJ_P(object); + + fch = xlAutoFilterColumn(autofilter, colId); + + if (!fch) { + RETURN_FALSE; + } + + obj->filtercolumn = fch; + obj->autofilter = autofilter; +} +/* }}} */ + +/* {{{ proto long FilterColumn::index() + Returns the zero-based index of this AutoFilter column. */ +EXCEL_METHOD(FilterColumn, index) +{ + zval *object = getThis(); + FilterColumnHandle filtercolumn; + + FILTERCOLUMN_FROM_OBJECT(filtercolumn, object); + + RETURN_LONG(xlFilterColumnIndex(filtercolumn)); +} +/* }}} */ + +/* {{{ proto long FilterColumn::filterType() + Returns the filter type of this AutoFilter column. */ +EXCEL_METHOD(FilterColumn, filterType) +{ + zval *object = getThis(); + FilterColumnHandle filtercolumn; + + FILTERCOLUMN_FROM_OBJECT(filtercolumn, object); + + RETURN_LONG(xlFilterColumnFilterType(filtercolumn)); +} +/* }}} */ + +/* {{{ proto long FilterColumn::filterSize() + Returns the number of filter values. */ +EXCEL_METHOD(FilterColumn, filterSize) +{ + zval *object = getThis(); + FilterColumnHandle filtercolumn; + + FILTERCOLUMN_FROM_OBJECT(filtercolumn, object); + + RETURN_LONG(xlFilterColumnFilterSize(filtercolumn)); +} +/* }}} */ + +/* {{{ proto long FilterColumn::filter() + Returns the filter value by index. */ +EXCEL_METHOD(FilterColumn, filter) +{ + zval *object = getThis(); + FilterColumnHandle filtercolumn; + zend_long filterIndex; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &filterIndex) == FAILURE) { + RETURN_FALSE; + } + + FILTERCOLUMN_FROM_OBJECT(filtercolumn, object); + + RETURN_STRING((char *)xlFilterColumnFilter(filtercolumn, filterIndex)); +} +/* }}} */ + +/* {{{ proto long FilterColumn::addFilter() + Adds the filter value. */ +EXCEL_METHOD(FilterColumn, addFilter) +{ + zval *object = getThis(); + FilterColumnHandle filtercolumn; + zend_string *filtervalue_zs = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &filtervalue_zs) == FAILURE) { + RETURN_FALSE; + } + + FILTERCOLUMN_FROM_OBJECT(filtercolumn, object); + + xlFilterColumnAddFilter(filtercolumn, ZSTR_VAL(filtervalue_zs)); + + RETURN_TRUE; +} +/* }}} */ + +/* {{{ proto long FilterColumn::getTop10() + Gets the number of top or bottom items: */ +EXCEL_METHOD(FilterColumn, getTop10) +{ + zval *object = getThis(); + FilterColumnHandle filtercolumn; + double value; + int top, percent; + + FILTERCOLUMN_FROM_OBJECT(filtercolumn, object); + + if (!xlFilterColumnGetTop10(filtercolumn, &value, &top, &percent)) { + RETURN_FALSE; + } + + array_init(return_value); + add_assoc_double(return_value, "value", value); + add_assoc_bool(return_value, "top", top); + add_assoc_bool(return_value, "percent", percent); +} +/* }}} */ + +/* {{{ proto long FilterColumn::setTop10() + Sets the number of top or bottom items: */ +EXCEL_METHOD(FilterColumn, setTop10) +{ + zval *object = getThis(); + FilterColumnHandle filtercolumn; + double value; + zend_bool top = 1, percent = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "dbb", &value, &top, &percent) == FAILURE) { + RETURN_FALSE; + } + + FILTERCOLUMN_FROM_OBJECT(filtercolumn, object); + + xlFilterColumnSetTop10(filtercolumn, value, top, percent); + + RETURN_TRUE; +} +/* }}} */ + +/* {{{ proto long FilterColumn::getCustomFilter() + Gets the custom filter criteria: */ +EXCEL_METHOD(FilterColumn, getCustomFilter) +{ + zval *object = getThis(); + FilterColumnHandle filtercolumn; + int op1, op2, andOp; + char *v1 = NULL, *v2 = NULL; + + FILTERCOLUMN_FROM_OBJECT(filtercolumn, object); + + if (!xlFilterColumnGetCustomFilter(filtercolumn, &op1, &v1, &op2, &v2, &andOp)) { + RETURN_FALSE; + } + + array_init(return_value); + add_assoc_long(return_value, "operator_1", op1); + add_assoc_string(return_value, "value_1", v1); + add_assoc_long(return_value, "operator_2", op2); + add_assoc_string(return_value, "value_2", v2); + add_assoc_bool(return_value, "and_operator", andOp); +} +/* }}} */ + +/* {{{ proto long FilterColumn::setCustomFilter() + Sets the custom filter criteria: */ +EXCEL_METHOD(FilterColumn, setCustomFilter) +{ + zval *object = getThis(); + FilterColumnHandle filtercolumn; + zend_long op1, op2 = -1; + zend_string *v1 = NULL, *v2 = NULL; + zend_bool andOp = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "lS|lSb", &op1, &v1, &op2, &v2, &andOp) == FAILURE) { + RETURN_FALSE; + } + + FILTERCOLUMN_FROM_OBJECT(filtercolumn, object); + + EXCEL_NON_EMPTY_STRING(v1) + + if (op2 == -1 || !v2) { + xlFilterColumnSetCustomFilter(filtercolumn, op1, ZSTR_VAL(v1)); + RETURN_TRUE; + } + + EXCEL_NON_EMPTY_STRING(v2) + + xlFilterColumnSetCustomFilterEx(filtercolumn, op1, ZSTR_VAL(v1), op2, ZSTR_VAL(v2), andOp); + RETURN_TRUE; +} +/* }}} */ + +/* {{{ proto long FilterColumn::clear() + Clear the filter criteria. */ +EXCEL_METHOD(FilterColumn, clear) +{ + zval *object = getThis(); + FilterColumnHandle filtercolumn; + + FILTERCOLUMN_FROM_OBJECT(filtercolumn, object); + + xlFilterColumnClear(filtercolumn); + + RETURN_TRUE; +} +/* }}} */ +#endif + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_requiresKey, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_load, 0, 0, 1) + ZEND_ARG_INFO(0, data) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_loadFile, 0, 0, 1) + ZEND_ARG_INFO(0, filename) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_save, 0, 0, 0) + ZEND_ARG_INFO(0, filename) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_getSheet, 0, 0, 0) + ZEND_ARG_INFO(0, sheet) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_getSheetByName, 0, 0, 1) + ZEND_ARG_INFO(0, name) + ZEND_ARG_INFO(0, case_insensitive) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_deleteSheet, 0, 0, 1) + ZEND_ARG_INFO(0, sheet) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_activeSheet, 0, 0, 0) + ZEND_ARG_INFO(0, sheet) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_addSheet, 0, 0, 1) + ZEND_ARG_INFO(0, name) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_copySheet, 0, 0, 2) + ZEND_ARG_INFO(0, name) + ZEND_ARG_INFO(0, sheet_number) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_sheetCount, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_getError, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_addFont, 0, 0, 0) + ZEND_ARG_OBJ_INFO(0, font, ExcelFont, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_addFormat, 0, 0, 0) + ZEND_ARG_OBJ_INFO(0, format, ExcelFormat, 1) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_getAllFormats, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_addCustomFormat, 0, 0, 1) + ZEND_ARG_INFO(0, format) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_getCustomFormat, 0, 0, 1) + ZEND_ARG_INFO(0, id) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_packDate, 0, 0, 1) + ZEND_ARG_INFO(0, timestamp) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_packDateValues, 0, 0, 6) + ZEND_ARG_INFO(0, year) + ZEND_ARG_INFO(0, month) + ZEND_ARG_INFO(0, day) + ZEND_ARG_INFO(0, hour) + ZEND_ARG_INFO(0, min) + ZEND_ARG_INFO(0, sec) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_unpackDate, 0, 0, 1) + ZEND_ARG_INFO(0, date) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_getActiveSheet, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_getDefaultFont, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_isDate1904, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_setDate1904, 0, 0, 1) + ZEND_ARG_INFO(0, date_type) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_setDefaultFont, 0, 0, 2) + ZEND_ARG_INFO(0, font) + ZEND_ARG_INFO(0, font_size) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_setLocale, 0, 0, 1) + ZEND_ARG_INFO(0, locale) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Book___construct, 0, 0, 0) + ZEND_ARG_INFO(0, license_name) + ZEND_ARG_INFO(0, license_key) + ZEND_ARG_INFO(0, excel_2007) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_setActiveSheet, 0, 0, 1) + ZEND_ARG_INFO(0, sheet) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_addPictureFromFile, 0, 0, 1) + ZEND_ARG_INFO(0, filename) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_addPictureFromString, 0, 0, 1) + ZEND_ARG_INFO(0, data) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_rgbMode, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_setRGBMode, 0, 0, 1) + ZEND_ARG_INFO(0, mode) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_colorPack, 0, 0, 3) + ZEND_ARG_INFO(0, r) + ZEND_ARG_INFO(0, g) + ZEND_ARG_INFO(0, b) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_colorUnpack, 0, 0, 1) + ZEND_ARG_INFO(0, color) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_setRefR1C1, 0, 0, 1) + ZEND_ARG_INFO(0, active) +ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_biffVersion, 0, 0, 0) ZEND_END_ARG_INFO() @@ -5188,6 +5930,10 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_setProtect, 0, 0, 1) ZEND_ARG_INFO(0, value) +#if LIBXL_VERSION >= 0x03070000 + ZEND_ARG_INFO(0, password) + ZEND_ARG_INFO(0, enhancedProtection) +#endif ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_setNamedRange, 0, 0, 5) @@ -5355,6 +6101,126 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_printArea, 0, 0, 0) ZEND_END_ARG_INFO() #endif +#if LIBXL_VERSION >= 0x03070000 +ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_setTabColor, 0, 0, 0) + ZEND_ARG_INFO(0, color) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_table, 0, 0, 1) + ZEND_ARG_INFO(0, index) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_addIgnoredError, 0, 0, 1) + ZEND_ARG_INFO(0, iError) + ZEND_ARG_INFO(0, rowFirst) + ZEND_ARG_INFO(0, colFirst) + ZEND_ARG_INFO(0, rowLast) + ZEND_ARG_INFO(0, colLast) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_removeComment, 0, 0, 2) + ZEND_ARG_INFO(0, row) + ZEND_ARG_INFO(0, col) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_writeError, 0, 0, 0) + ZEND_ARG_INFO(0, row) + ZEND_ARG_INFO(0, col) + ZEND_ARG_INFO(0, iError) + ZEND_ARG_OBJ_INFO(0, format, ExcelFormat, 1) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_applyFilter, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_autoFilter, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_removeFilter, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_AutoFilter___construct, 0, 0, 0) + ZEND_ARG_OBJ_INFO(0, sheet, ExcelSheet, 1) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_AutoFilter_getRef, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_AutoFilter_setRef, 0, 0, 0) + ZEND_ARG_INFO(0, row_first) + ZEND_ARG_INFO(0, col_first) + ZEND_ARG_INFO(0, row_last) + ZEND_ARG_INFO(0, col_last) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_AutoFilter_column, 0, 0, 1) + ZEND_ARG_INFO(0, colId) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_AutoFilter_columnSize, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_AutoFilter_columnByIndex, 0, 0, 1) + ZEND_ARG_INFO(0, index) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_AutoFilter_getSortRange, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_AutoFilter_getSort, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_AutoFilter_setSort, 0, 0, 2) + ZEND_ARG_INFO(0, columnIndex) + ZEND_ARG_INFO(0, descending) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_FilterColumn___construct, 0, 0, 1) + ZEND_ARG_OBJ_INFO(0, autoFilter, AutoFilter, 1) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_FilterColumn_index, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_FilterColumn_filterType, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_FilterColumn_filterSize, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_FilterColumn_filter, 0, 0, 1) + ZEND_ARG_INFO(0, index) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_FilterColumn_addFilter, 0, 0, 1) + ZEND_ARG_INFO(0, filterValue) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_FilterColumn_getTop10, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_FilterColumn_setTop10, 0, 0, 1) + ZEND_ARG_INFO(0, value) + ZEND_ARG_INFO(0, top) + ZEND_ARG_INFO(0, percent) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_FilterColumn_getCustomFilter, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_FilterColumn_setCustomFilter, 0, 0, 2) + ZEND_ARG_INFO(0, operator_1) + ZEND_ARG_INFO(0, value_1) + ZEND_ARG_INFO(0, operator_2) + ZEND_ARG_INFO(0, value_2) + ZEND_ARG_INFO(0, andOp) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_FilterColumn_clear, 0, 0, 0) +ZEND_END_ARG_INFO() + +#endif + #define EXCEL_ME(class_name, function_name, arg_info, flags) \ PHP_ME(Excel ## class_name, function_name, arg_info, flags) @@ -5529,6 +6395,15 @@ zend_function_entry excel_funcs_sheet[] = { EXCEL_ME(Sheet, printRepeatRows, arginfo_Sheet_printRepeatRows, 0) EXCEL_ME(Sheet, printRepeatCols, arginfo_Sheet_printRepeatCols, 0) EXCEL_ME(Sheet, printArea, arginfo_Sheet_printArea, 0) +#endif +#if LIBXL_VERSION >= 0x03070000 + EXCEL_ME(Sheet, setTabColor, arginfo_Sheet_setTabColor, 0) + EXCEL_ME(Sheet, applyFilter, arginfo_Sheet_applyFilter, 0) + EXCEL_ME(Sheet, autoFilter, arginfo_Sheet_autoFilter, 0) + EXCEL_ME(Sheet, removeFilter, arginfo_Sheet_removeFilter, 0) + EXCEL_ME(Sheet, table, arginfo_Sheet_table, 0) + EXCEL_ME(Sheet, writeError, arginfo_Sheet_writeError, 0) + EXCEL_ME(Sheet, addIgnoredError, arginfo_Sheet_addIgnoredError, 0) #endif {NULL, NULL, NULL} }; @@ -5577,16 +6452,48 @@ zend_function_entry excel_funcs_format[] = { {NULL, NULL, NULL} }; +#if LIBXL_VERSION >= 0x03070000 +zend_function_entry excel_funcs_autofilter[] = { + EXCEL_ME(AutoFilter, __construct, arginfo_AutoFilter___construct, 0) + EXCEL_ME(AutoFilter, getRef, arginfo_AutoFilter_getRef, 0) + EXCEL_ME(AutoFilter, setRef, arginfo_AutoFilter_setRef, 0) + EXCEL_ME(AutoFilter, column, arginfo_AutoFilter_column, 0) + EXCEL_ME(AutoFilter, columnSize, arginfo_AutoFilter_columnSize, 0) + EXCEL_ME(AutoFilter, columnByIndex, arginfo_AutoFilter_columnByIndex, 0) + EXCEL_ME(AutoFilter, getSortRange, arginfo_AutoFilter_getSortRange, 0) + EXCEL_ME(AutoFilter, getSort, arginfo_AutoFilter_getSort, 0) + EXCEL_ME(AutoFilter, setSort, arginfo_AutoFilter_setSort, 0) + {NULL, NULL, NULL} +}; + +zend_function_entry excel_funcs_filtercolumn[] = { + EXCEL_ME(FilterColumn, __construct, arginfo_FilterColumn___construct, 0) + EXCEL_ME(FilterColumn, index, arginfo_FilterColumn_index, 0) + EXCEL_ME(FilterColumn, filterType, arginfo_FilterColumn_filterType, 0) + EXCEL_ME(FilterColumn, filterSize, arginfo_FilterColumn_filterSize, 0) + EXCEL_ME(FilterColumn, filter, arginfo_FilterColumn_filter, 0) + EXCEL_ME(FilterColumn, addFilter, arginfo_FilterColumn_addFilter, 0) + EXCEL_ME(FilterColumn, getTop10, arginfo_FilterColumn_getTop10, 0) + EXCEL_ME(FilterColumn, setTop10, arginfo_FilterColumn_setTop10, 0) + EXCEL_ME(FilterColumn, getCustomFilter, arginfo_FilterColumn_getCustomFilter, 0) + EXCEL_ME(FilterColumn, setCustomFilter, arginfo_FilterColumn_setCustomFilter, 0) + EXCEL_ME(FilterColumn, clear, arginfo_FilterColumn_clear, 0) + {NULL, NULL, NULL} +}; +#endif + /* {{{ PHP_MINIT_FUNCTION */ PHP_MINIT_FUNCTION(excel) { REGISTER_INI_ENTRIES(); - REGISTER_EXCEL_CLASS(Book, book, NULL); - REGISTER_EXCEL_CLASS(Sheet, sheet, NULL); - REGISTER_EXCEL_CLASS(Format, format, excel_format_object_clone); - REGISTER_EXCEL_CLASS(Font, font, excel_font_object_clone); + REGISTER_EXCEL_CLASS(Book, book, NULL); + REGISTER_EXCEL_CLASS(Sheet, sheet, NULL); + REGISTER_EXCEL_CLASS(Format, format, excel_format_object_clone); + REGISTER_EXCEL_CLASS(Font, font, excel_font_object_clone); + REGISTER_EXCEL_CLASS(AutoFilter, autofilter, NULL); + REGISTER_EXCEL_CLASS(FilterColumn, filtercolumn, NULL); REGISTER_EXCEL_CLASS_CONST_LONG(font, "NORMAL", SCRIPT_NORMAL); REGISTER_EXCEL_CLASS_CONST_LONG(font, "SUBSCRIPT", SCRIPT_SUB); @@ -5809,6 +6716,8 @@ PHP_MINIT_FUNCTION(excel) REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "PAPER_FANFOLD", PAPER_FANFOLD); REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "PAPER_GERMAN_STD_FANFOLD", PAPER_GERMAN_STD_FANFOLD); REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "PAPER_GERMAN_LEGAL_FANFOLD", PAPER_GERMAN_LEGAL_FANFOLD); + + REGISTER_EXCEL_CLASS_CONST_LONG(book, "PICTURETYPE_PNG", PICTURETYPE_PNG); REGISTER_EXCEL_CLASS_CONST_LONG(book, "PICTURETYPE_JPEG", PICTURETYPE_JPEG); REGISTER_EXCEL_CLASS_CONST_LONG(book, "PICTURETYPE_WMF", PICTURETYPE_WMF); @@ -5818,8 +6727,10 @@ PHP_MINIT_FUNCTION(excel) REGISTER_EXCEL_CLASS_CONST_LONG(book, "PICTURETYPE_TIFF", PICTURETYPE_TIFF); REGISTER_EXCEL_CLASS_CONST_LONG(book, "SCOPE_UNDEFINED", SCOPE_UNDEFINED); REGISTER_EXCEL_CLASS_CONST_LONG(book, "SCOPE_WORKBOOK", SCOPE_WORKBOOK); + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "RIGHT_TO_LEFT", 1); REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "LEFT_TO_RIGHT", 0); + REGISTER_EXCEL_CLASS_CONST_LONG(book, "SHEETTYPE_SHEET", SHEETTYPE_SHEET); REGISTER_EXCEL_CLASS_CONST_LONG(book, "SHEETTYPE_CHART", SHEETTYPE_CHART); REGISTER_EXCEL_CLASS_CONST_LONG(book, "SHEETTYPE_UNKNOWN", SHEETTYPE_UNKNOWN); @@ -5829,6 +6740,55 @@ PHP_MINIT_FUNCTION(excel) REGISTER_EXCEL_CLASS_CONST_LONG(book, "POSITION_ABSOLUTE", POSITION_ABSOLUTE); #endif +#if LIBXL_VERSION >= 0x03070000 + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "PROT_DEFAULT", PROT_DEFAULT); + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "PROT_ALL", PROT_ALL); + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "PROT_OBJECTS", PROT_OBJECTS); + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "PROT_SCENARIOS", PROT_SCENARIOS); + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "PROT_FORMAT_CELLS", PROT_FORMAT_CELLS); + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "PROT_FORMAT_COLUMNS", PROT_FORMAT_COLUMNS); + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "PROT_FORMAT_ROWS", PROT_FORMAT_ROWS); + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "PROT_INSERT_COLUMNS", PROT_INSERT_COLUMNS); + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "PROT_INSERT_ROWS", PROT_INSERT_ROWS); + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "PROT_INSERT_HYPERLINKS", PROT_INSERT_HYPERLINKS); + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "PROT_DELETE_COLUMNS", PROT_DELETE_COLUMNS); + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "PROT_DELETE_ROWS", PROT_DELETE_ROWS); + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "PROT_SEL_LOCKED_CELLS", PROT_SEL_LOCKED_CELLS); + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "PROT_SORT", PROT_SORT); + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "PROT_AUTOFILTER", PROT_AUTOFILTER); + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "PROT_PIVOTTABLES", PROT_PIVOTTABLES); + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "PROT_SEL_UNLOCKED_CELLS", PROT_SEL_UNLOCKED_CELLS); + + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "SHEETSTATE_VISIBLE", SHEETSTATE_VISIBLE); + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "SHEETSTATE_HIDDEN", SHEETSTATE_HIDDEN); + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "SHEETSTATE_VERYHIDDEN", SHEETSTATE_VERYHIDDEN); + + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "IERR_EVAL_ERROR", IERR_EVAL_ERROR); + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "IERR_EMPTY_CELLREF", IERR_EMPTY_CELLREF); + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "IERR_NUMBER_STORED_AS_TEXT", IERR_NUMBER_STORED_AS_TEXT); + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "IERR_INCONSIST_RANGE", IERR_INCONSIST_RANGE); + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "IERR_INCONSIST_FMLA", IERR_INCONSIST_FMLA); + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "IERR_TWODIG_TEXTYEAR", IERR_TWODIG_TEXTYEAR); + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "IERR_UNLOCK_FMLA", IERR_UNLOCK_FMLA); + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "IERR_DATA_VALIDATION", IERR_DATA_VALIDATION); + + REGISTER_EXCEL_CLASS_CONST_LONG(filtercolumn, "OPERATOR_EQUAL", OPERATOR_EQUAL); + REGISTER_EXCEL_CLASS_CONST_LONG(filtercolumn, "OPERATOR_GREATER_THAN", OPERATOR_GREATER_THAN); + REGISTER_EXCEL_CLASS_CONST_LONG(filtercolumn, "OPERATOR_GREATER_THAN_OR_EQUAL", OPERATOR_GREATER_THAN_OR_EQUAL); + REGISTER_EXCEL_CLASS_CONST_LONG(filtercolumn, "OPERATOR_LESS_THAN", OPERATOR_LESS_THAN); + REGISTER_EXCEL_CLASS_CONST_LONG(filtercolumn, "OPERATOR_LESS_THAN_OR_EQUAL", OPERATOR_LESS_THAN_OR_EQUAL); + REGISTER_EXCEL_CLASS_CONST_LONG(filtercolumn, "OPERATOR_NOT_EQUAL", OPERATOR_NOT_EQUAL); + + REGISTER_EXCEL_CLASS_CONST_LONG(filtercolumn, "FILTER_VALUE", FILTER_VALUE); + REGISTER_EXCEL_CLASS_CONST_LONG(filtercolumn, "FILTER_TOP10", FILTER_TOP10); + REGISTER_EXCEL_CLASS_CONST_LONG(filtercolumn, "FILTER_CUSTOM", FILTER_CUSTOM); + REGISTER_EXCEL_CLASS_CONST_LONG(filtercolumn, "FILTER_DYNAMIC", FILTER_DYNAMIC); + REGISTER_EXCEL_CLASS_CONST_LONG(filtercolumn, "FILTER_COLOR", FILTER_COLOR); + REGISTER_EXCEL_CLASS_CONST_LONG(filtercolumn, "FILTER_ICON", FILTER_ICON); + REGISTER_EXCEL_CLASS_CONST_LONG(filtercolumn, "FILTER_EXT", FILTER_EXT); + REGISTER_EXCEL_CLASS_CONST_LONG(filtercolumn, "FILTER_NOT_SET", FILTER_NOT_SET); +#endif + return SUCCESS; } /* }}} */ From eeb9a813f83a06deca8cb3cf910094b4c40fdbb6 Mon Sep 17 00:00:00 2001 From: "eric.deruiter" Date: Mon, 2 Jan 2017 13:42:31 +0100 Subject: [PATCH 44/68] Added ExcelFormat::AS_STRING const This can be used to explicitly format a cell as a string (same behaviour as starting with a single quote, only this allows to explicitly set the datatype without manipulating the data). --- excel.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/excel.c b/excel.c index 8593331..3ed21f6 100644 --- a/excel.c +++ b/excel.c @@ -53,6 +53,7 @@ static long xlFormatBorderColor(FormatHandle f) #define PHP_EXCEL_DATE 1 #define PHP_EXCEL_FORMULA 2 #define PHP_EXCEL_NUMERIC_STRING 3 +#define PHP_EXCEL_STRING 4 #define PHP_EXCEL_VERSION "1.0.3dev" @@ -2379,6 +2380,9 @@ zend_bool php_excel_write_cell(SheetHandle sheet, BookHandle book, int row, int case IS_STRING: data_zs = Z_STR_P(data); + if (dtype == PHP_EXCEL_STRING) { + return xlSheetWriteStr(sheet, row, col, (const char*) ZSTR_VAL(data_zs), format); + } if (Z_STRLEN_P(data) > 0 && '\'' == Z_STRVAL_P(data)[0]) { return xlSheetWriteStr(sheet, row, col, (const char*) ZSTR_VAL(data_zs) + 1, format); } @@ -6508,6 +6512,7 @@ PHP_MINIT_FUNCTION(excel) REGISTER_EXCEL_CLASS_CONST_LONG(format, "AS_DATE", PHP_EXCEL_DATE); REGISTER_EXCEL_CLASS_CONST_LONG(format, "AS_FORMULA", PHP_EXCEL_FORMULA); REGISTER_EXCEL_CLASS_CONST_LONG(format, "AS_NUMERIC_STRING", PHP_EXCEL_NUMERIC_STRING); + REGISTER_EXCEL_CLASS_CONST_LONG(format, "AS_STRING", PHP_EXCEL_STRING); REGISTER_EXCEL_CLASS_CONST_LONG(format, "COLOR_BLACK", COLOR_BLACK); REGISTER_EXCEL_CLASS_CONST_LONG(format, "COLOR_WHITE", COLOR_WHITE); From 247ce1e6ac3c9ecc95c7d387924c8afd67655431 Mon Sep 17 00:00:00 2001 From: Johannes Mueller Date: Sun, 23 Apr 2017 22:12:22 +0200 Subject: [PATCH 45/68] added new methods for LibXL 3.8.0 --- ChangeLog | 11 +- README.markdown | 8 ++ docs/ExcelBook.php | 46 ++++++++ docs/ExcelSheet.php | 92 ++++++++++++++- excel.c | 267 +++++++++++++++++++++++++++++++++++++++++++- tests/002.phpt | 14 ++- tests/051.phpt | 4 +- tests/092.phpt | 15 +++ tests/093.phpt | 15 +++ tests/094.phpt | 119 ++++++++++++++++++++ tests/095.phpt | 68 +++++++++++ 11 files changed, 646 insertions(+), 13 deletions(-) create mode 100644 tests/092.phpt create mode 100644 tests/093.phpt create mode 100644 tests/094.phpt create mode 100644 tests/095.phpt diff --git a/ChangeLog b/ChangeLog index 742391b..27c57f1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,15 @@ -[2016-??-??] - Version 1.0.3dev +[2017-??-??] - Version 1.0.3dev * Fixed crash when trying to read an empty file * Added PECL package.xml to allow installation via pecl + * Added ExcelSheet::AS_STRING const to use with write operations (see PR 183 by ederuiter) + * Added new methods (requires LibXL 3.8.0) + - ExcelBook::addPictureAsLink() + - ExcelBook::moveSheet() + - ExcelSheet::addDataValidation() + - ExcelSheet::addDataValidationDouble() + - ExcelSheet::removeDataValidations() + * Added ExcelBook::getLibXlVersion() + * Added ExcelBook::getPhpExcelVersion() [2016-06-23] - Version 1.0.2 * Fixed bug in ExcelSheet::addPictureDim() (see issue #120) diff --git a/README.markdown b/README.markdown index 17b634a..84f8670 100644 --- a/README.markdown +++ b/README.markdown @@ -155,6 +155,14 @@ class MyExcelBook extends \ExcelBook } ``` +### Testing (Windows) + +After you have build the extension you can use ```nmake test``` to run the test suite against the php_excel extension. + +``` shell +..\php-7.1.4> nmake test TESTS="-d extension=php_excel.dll -d date.timezone=\"America/Toronto\" -d excel.license_name=\"LICENSE_NAME\" -d excel.license_key=\"LICENSE_KEY\" ./ext/php_excel" +``` + ### Further reading * [Performant-Handling-Excel-Files-PHP](http://blog.mayflower.de/4922-Performant-Handling-Excel-Files-PHP.html) diff --git a/docs/ExcelBook.php b/docs/ExcelBook.php index bac1b5f..a9e0b66 100644 --- a/docs/ExcelBook.php +++ b/docs/ExcelBook.php @@ -84,6 +84,22 @@ public function addFormat(ExcelFormat $format = null) { } // addFormat + /** + * Adds a picture to the workbook as link (only for xlsx files). + * Supports BMP, DIB, PNG, JPG and WMF picture formats. Use picture identifier with + * \ExcelSheet::setPictureDim() or \ExcelSheet::setPictureScale() + * @see \ExcelSheet::setPictureDim() + * @see \ExcelSheet::setPictureScale() + * + * @since libXl 3.8.0.0 + * @param string $filename + * @param bool $insert (optional, default = false) false - stores only a link to file, true - stores a picture and a link to file. + * @return int picture identifier + */ + public function addPictureAsLink($filename, $insert = false) + { + } // addPictureAsLink + /** * Add a picture from file * @@ -224,6 +240,15 @@ public function getError() { } // getError + /** + * Get LibXL version + * + * @return string LibXl library version + */ + public function getLibXlVersion() + { + } // getLibXlVersion + /** * Returns a number of pictures in this workbook. * @@ -233,6 +258,15 @@ public function getNumPictures() { } // getNumPictures + /** + * Get PHP excel extension version + * + * @return string PHP Excel version + */ + public function getPhpExcelVersion() + { + } // getPhpExcelVersion + /** * Returns a picture at position index. * @@ -326,6 +360,18 @@ public function loadFile($filename) { } // loadFile + /** + * Moves a sheet with specified index to a new position. Returns false if error occurs. + * + * @since libXL 3.8.0.0 + * @param int $srcIndex + * @param int $dstIndex + * @return bool + */ + public function moveSheet($srcIndex, $dstIndex) + { + } // moveSheet + /** * Pack a unix timestamp into an Excel double * diff --git a/docs/ExcelSheet.php b/docs/ExcelSheet.php index 28b1fce..c345f2b 100644 --- a/docs/ExcelSheet.php +++ b/docs/ExcelSheet.php @@ -71,6 +71,7 @@ class ExcelSheet const ERRORTYPE_NAME = 29; const ERRORTYPE_NUM = 36; const ERRORTYPE_NA = 42; + const ERRORTYPE_NOERROR = 255; const LEFT_TO_RIGHT = 0; const RIGHT_TO_LEFT = 1; @@ -102,6 +103,32 @@ class ExcelSheet const PROT_PIVOTTABLES = 8192; const PROT_SEL_UNLOCKED_CELLS = 16384; + const SHEETSTATE_VISIBLE = 0; + const SHEETSTATE_HIDDEN = 1; + const SHEETSTATE_VERYHIDDEN = 2; + + const VALIDATION_TYPE_NONE = 0; + const VALIDATION_TYPE_WHOLE = 1; + const VALIDATION_TYPE_DECIMAL = 2; + const VALIDATION_TYPE_LIST = 3; + const VALIDATION_TYPE_DATE = 4; + const VALIDATION_TYPE_TIME = 5; + const VALIDATION_TYPE_TEXTLENGTH = 6; + const VALIDATION_TYPE_CUSTOM = 7; + + const VALIDATION_OP_BETWEEN = 0; + const VALIDATION_OP_NOTBETWEEN = 1; + const VALIDATION_OP_EQUAL = 2; + const VALIDATION_OP_NOTEQUAL = 3; + const VALIDATION_OP_LESSTHAN = 4; + const VALIDATION_OP_LESSTHANOREQUAL = 5; + const VALIDATION_OP_GREATERTHAN = 6; + const VALIDATION_OP_GREATERTHANOREQUAL = 7; + + const VALIDATION_ERRSTYLE_STOP = 0; // stop icon in the error alert + const VALIDATION_ERRSTYLE_WARNING = 1; // warning icon in the error alert + const VALIDATION_ERRSTYLE_INFORMATION = 2; // information icon in the error alert + /** * Create an ExcelSheet in given Workbook * @@ -113,6 +140,59 @@ public function __construct(ExcelBook $book, $name) { } // __construct + /** + * Adds a data validation for the specified range (only for xlsx files). + * + * @since libXL 3.8.0.0 + * @param int $type - one of the ExcelSheet::VALIDATION_TYPE_* constants + * @param int $op - one of the ExcelSheet::VALIDATION_OP_* constants + * @param int $row_first 0-based + * @param int $row_last 0-based + * @param int $col_first 0-based + * @param int $col_last 0-based + * @param string $val_1 the first value for relational operator + * @param string $val_2 the second value for VALIDATION_OP_BETWEEN or VALIDATION_OP_NOTBETWEEN operator + * @param bool $allow_blank (optional, default = true) a boolean value indicating whether the data validation treats empty or blank entries as valid, 'true' means empty entries are OK and do not violate the validation constraints + * @param bool $hide_dropdown (optional, default = false) a boolean value indicating whether to display the dropdown combo box for a list type data validation (ExcelSheet::VALIDATION_TYPE_LIST) + * @param bool $show_inputmessage (optional, default = true) a boolean value indicating whether to display the input prompt message + * @param bool $show_errormessage (optional, default = true) a boolean value indicating whether to display the error alert message when an invalid value has been entered, according to the criteria specified + * @param string $prompt_title (optional, default = '') title bar text of input prompt + * @param string $prompt (optional, default = '') message text of input prompt + * @param string $error_title (optional, default = '') title bar text of error alert + * @param string $error (optional, default = '') message text of error alert + * @param int $error_style - (optional, default = \ExcelSheet::VALIDATION_ERRSTYLE_WARNING) one of the ExcelSheet::VALIDATION_ERRSTYLE_* constants + */ + public function addDataValidation($type, $op, $row_first, $row_last, $col_first, $col_last, $val_1, $val_2 = null, $allow_blank = true, $hide_dropdown = false, $show_inputmessage = true, $show_errormessage = true, $prompt_title = '', $prompt = '', $error_title = '', $error = '', $error_style = \ExcelSheet::VALIDATION_ERRSTYLE_WARNING) + { + } // addDataValidation + + /** + * Adds a data validation for the specified range with double or date values for the relational + * operator (only for xlsx files). + * + * @since libXL 3.8.0.0 + * @param int $type - one of the ExcelSheet::VALIDATION_TYPE_* constants + * @param int $op - one of the ExcelSheet::VALIDATION_OP_* constants + * @param int $row_first 0-based + * @param int $row_last 0-based + * @param int $col_first 0-based + * @param int $col_last 0-based + * @param float $val_1 the first value for relational operator + * @param float $val_2 the second value for VALIDATION_OP_BETWEEN or VALIDATION_OP_NOTBETWEEN operator + * @param bool $allow_blank (optional, default = true) a boolean value indicating whether the data validation treats empty or blank entries as valid, 'true' means empty entries are OK and do not violate the validation constraints + * @param bool $hide_dropdown (optional, default = false) a boolean value indicating whether to display the dropdown combo box for a list type data validation (ExcelSheet::VALIDATION_TYPE_LIST) + * @param bool $show_inputmessage (optional, default = true) a boolean value indicating whether to display the input prompt message + * @param bool $show_errormessage (optional, default = true) a boolean value indicating whether to display the error alert message when an invalid value has been entered, according to the criteria specified + * @param string $prompt_title (optional, default = '') title bar text of input prompt + * @param string $prompt (optional, default = '') message text of input prompt + * @param string $error_title (optional, default = '') title bar text of error alert + * @param string $error (optional, default = '') message text of error alert + * @param int $error_style - (optional, default = \ExcelSheet::VALIDATION_ERRSTYLE_WARNING) one of the ExcelSheet::VALIDATION_ERRSTYLE_* constants + */ + public function addDataValidationDouble($type, $op, $row_first, $row_last, $col_first, $col_last, $val_1, $val_2 = null, $allow_blank = true, $hide_dropdown = false, $show_inputmessage = true, $show_errormessage = true, $prompt_title = '', $prompt = '', $error_title = '', $error = '', $error_style = \ExcelSheet::VALIDATION_ERRSTYLE_WARNING) + { + } // addDataValidationDouble + /** * Adds the new hyperlink. * @@ -140,7 +220,7 @@ public function addHyperlink($hyperlink, $row_first, $row_last, $col_first, $col public function addIgnoredError($error, $row_first=0, $col_first=0, $row_last=0, $col_last=0) { } // addIgnoredError - + /** * Insert a picture into a cell with given dimensions * @@ -958,6 +1038,16 @@ public function removeCol($column_start, $column_end) { } // removeCol + /** + * Removes all data validations for the sheet (only for xlsx files). + * + * @since libXL 3.8.0.0 + * @return bool + */ + public function removeDataValidations() + { + } // removeDataValidations + /** * Remove rows from row_start to row_end * diff --git a/excel.c b/excel.c index 3ed21f6..f24352e 100644 --- a/excel.c +++ b/excel.c @@ -302,6 +302,9 @@ static void excel_font_object_free_storage(zend_object *object) #define REGISTER_EXCEL_CLASS_CONST_LONG(class_name, const_name, value) \ zend_declare_class_constant_long(excel_ce_ ## class_name, const_name, sizeof(const_name)-1, (long)value); +#define REGISTER_EXCEL_CLASS_CONST_STRING(class_name, const_name, value) \ + zend_declare_class_constant_string(excel_ce_ ## class_name, const_name, sizeof(const_name)-1, (char *)value); + static zend_object *excel_object_new_font_ex(zend_class_entry *class_type, excel_font_object **ptr) { excel_font_object *intern; @@ -1461,6 +1464,24 @@ EXCEL_METHOD(Book, colorUnpack) } /* }}} */ +/* {{{ proto string ExcelBook::getLibXlVersion() + Returns the version of libXL library */ +EXCEL_METHOD(Book, getLibXlVersion) +{ + char libxl_api[25]; + snprintf(libxl_api, sizeof(libxl_api), "%x", LIBXL_VERSION); + RETURN_STRING(libxl_api); +} +/* }}} */ + +/* {{{ proto string ExcelBook::getPhpExcelVersion() + Returns the version of PHP Excel extension */ +EXCEL_METHOD(Book, getPhpExcelVersion) +{ + RETURN_STRING(PHP_EXCEL_VERSION); +} +/* }}} */ + /* {{{ proto int ExcelFont::size([int size]) Get or set the font size */ EXCEL_METHOD(Font, size) @@ -2380,12 +2401,12 @@ zend_bool php_excel_write_cell(SheetHandle sheet, BookHandle book, int row, int case IS_STRING: data_zs = Z_STR_P(data); - if (dtype == PHP_EXCEL_STRING) { - return xlSheetWriteStr(sheet, row, col, (const char*) ZSTR_VAL(data_zs), format); - } if (Z_STRLEN_P(data) > 0 && '\'' == Z_STRVAL_P(data)[0]) { return xlSheetWriteStr(sheet, row, col, (const char*) ZSTR_VAL(data_zs) + 1, format); } + if (dtype == PHP_EXCEL_STRING) { + return xlSheetWriteStr(sheet, row, col, (const char*) ZSTR_VAL(data_zs), format); + } if (Z_STRLEN_P(data) > 0 && '=' == Z_STRVAL_P(data)[0]) { dtype = PHP_EXCEL_FORMULA; } @@ -5232,6 +5253,147 @@ EXCEL_METHOD(FilterColumn, clear) /* }}} */ #endif +#if LIBXL_VERSION >= 0x03080000 +/* {{{ proto long ExcelBook::addPictureAsLink(str filename, bool insert) + Adds a picture to the workbook as link (only for xlsx files) */ +EXCEL_METHOD(Book, addPictureAsLink) +{ + zval *object = getThis(); + BookHandle book; + zend_string *filename; + zend_bool insert = 0; + long result; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|b", &filename, &insert) == FAILURE) { + RETURN_FALSE; + } + + BOOK_FROM_OBJECT(book, object); + + result = xlBookAddPictureAsLink(book, ZSTR_VAL(filename), insert); + + if (-1 == result) { + php_error_docref(NULL, E_WARNING, "Could not add picture as link."); + RETURN_FALSE; + } + + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto bool ExcelBook::moveSheet(int src_index, int dest_index) + Moves a sheet with specified index to a new position. Returns 0 if error occurs. */ +EXCEL_METHOD(Book, moveSheet) +{ + BookHandle book; + zval *object = getThis(); + zend_long src_index, dest_index; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll", &src_index, &dest_index) == FAILURE) { + RETURN_FALSE; + } + + BOOK_FROM_OBJECT(book, object); + + if (!xlBookMoveSheet(book, src_index, dest_index)) { + RETURN_FALSE; + } + + RETURN_TRUE; +} +/* }}} */ + +/* {{{ proto bool Sheet::addDataValidation() + Adds a data validation for the specified range (only for xlsx files). */ +EXCEL_METHOD(Sheet, addDataValidation) +{ + zval *object = getThis(); + SheetHandle sheet; + + zend_long type, op, row_first, row_last, col_first, col_last; + zend_string *val_1, *val_2; + zend_bool allow_blank = 1, hide_dropdown=0, show_inputmessage = 1, show_errormessage = 1; + zend_string *prompt_title = zend_string_init("", sizeof("")-1, 0), *prompt = zend_string_init("", sizeof("")-1, 0); + zend_string *error_title = zend_string_init("", sizeof("")-1, 0), *error = zend_string_init("", sizeof("")-1, 0); + zend_long error_style = 1; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "llllllS|SbbbbSSSSl", &type, &op, &row_first, &row_last, \ + &col_first, &col_last, &val_1, &val_2, &allow_blank, &hide_dropdown, &show_inputmessage, \ + &show_errormessage, &prompt_title, &prompt, &error_title, &error, &error_style) == FAILURE) { + RETURN_FALSE; + } + + if (!val_1 || ZSTR_LEN(val_1) < 1) { + php_error_docref(NULL, E_WARNING, "The first value can not be empty."); + RETURN_FALSE; + } + + if ((op == VALIDATION_OP_BETWEEN || op == VALIDATION_OP_NOTBETWEEN) && ZEND_NUM_ARGS() < 8) { + php_error_docref(NULL, E_WARNING, "The second value can not be null when used with (not) between operator."); + RETURN_FALSE; + } + + SHEET_FROM_OBJECT(sheet, object); + + xlSheetAddDataValidationEx(sheet, type, op, row_first, row_last, col_first, col_last, ZSTR_VAL(val_1), \ + ZSTR_VAL(val_2), allow_blank, hide_dropdown, show_inputmessage, show_errormessage, \ + ZSTR_VAL(prompt_title), ZSTR_VAL(prompt), ZSTR_VAL(error_title), ZSTR_VAL(error), error_style); + + RETURN_TRUE; +} +/* }}} */ + +/* {{{ proto bool Sheet::addDataValidationDouble() + Adds a data validation for the specified range with double or date values for the relational operator + (only for xlsx files). See parameters in the xlSheetAddDataValidation() method. */ +EXCEL_METHOD(Sheet, addDataValidationDouble) +{ + zval *object = getThis(); + SheetHandle sheet; + + zend_long type, op, row_first, row_last, col_first, col_last; + double val_1, val_2; + zend_bool allow_blank = 1, hide_dropdown=0, show_inputmessage = 1, show_errormessage = 1; + zend_string *prompt_title = zend_string_init("", sizeof("")-1, 0), *prompt = zend_string_init("", sizeof("")-1, 0); + zend_string *error_title = zend_string_init("", sizeof("")-1, 0), *error = zend_string_init("", sizeof("")-1, 0); + zend_long error_style = 1; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "lllllld|dbbbbSSSSl", &type, &op, &row_first, &row_last, \ + &col_first, &col_last, &val_1, &val_2, &allow_blank, &hide_dropdown, &show_inputmessage, \ + &show_errormessage, &prompt_title, &prompt, &error_title, &error, &error_style) == FAILURE) { + RETURN_FALSE; + } + + if ((op == VALIDATION_OP_BETWEEN || op == VALIDATION_OP_NOTBETWEEN) && ZEND_NUM_ARGS() < 8) { + php_error_docref(NULL, E_WARNING, "The second value can not be null when used with (not) between operator."); + RETURN_FALSE; + } + + SHEET_FROM_OBJECT(sheet, object); + + xlSheetAddDataValidationDoubleEx(sheet, type, op, row_first, row_last, col_first, col_last, val_1, \ + val_2, allow_blank, hide_dropdown, show_inputmessage, show_errormessage, \ + ZSTR_VAL(prompt_title), ZSTR_VAL(prompt), ZSTR_VAL(error_title), ZSTR_VAL(error), error_style); + + RETURN_TRUE; +} +/* }}} */ + +/* {{{ proto bool Sheet::removeDataValidations() + Removes all data validations for the sheet (only for xlsx files). */ +EXCEL_METHOD(Sheet, removeDataValidations) +{ + zval *object = getThis(); + SheetHandle sheet; + + SHEET_FROM_OBJECT(sheet, object); + xlSheetRemoveDataValidations(sheet); + + RETURN_TRUE; +} +/* }}} */ +#endif + ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_requiresKey, 0, 0, 0) ZEND_END_ARG_INFO() @@ -5413,6 +5575,12 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_sheetType, 0, 0, 1) ZEND_ARG_INFO(0, sheet) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_getLibXlVersion, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_getPhpExcelVersion, 0, 0, 0) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_INFO_EX(arginfo_Font_size, 0, 0, 0) ZEND_ARG_INFO(0, size) ZEND_END_ARG_INFO() @@ -6222,7 +6390,61 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_FilterColumn_clear, 0, 0, 0) ZEND_END_ARG_INFO() +#endif + +#if LIBXL_VERSION >= 0x03080000 +ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_addPictureAsLink, 0, 0, 1) + ZEND_ARG_INFO(0, filename) + ZEND_ARG_INFO(0, insert) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_moveSheet, 0, 0, 2) + ZEND_ARG_INFO(0, src_index) + ZEND_ARG_INFO(0, dest_index) +ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_addDataValidation, 0, 0, 7) + ZEND_ARG_INFO(0, type) + ZEND_ARG_INFO(0, op) + ZEND_ARG_INFO(0, row_first) + ZEND_ARG_INFO(0, row_last) + ZEND_ARG_INFO(0, col_first) + ZEND_ARG_INFO(0, col_last) + ZEND_ARG_INFO(0, val_1) + ZEND_ARG_INFO(0, val_2) + ZEND_ARG_INFO(0, allow_blank) + ZEND_ARG_INFO(0, hide_dropdown) + ZEND_ARG_INFO(0, show_inputmessage) + ZEND_ARG_INFO(0, show_errormessage) + ZEND_ARG_INFO(0, prompt_title) + ZEND_ARG_INFO(0, prompt) + ZEND_ARG_INFO(0, error_title) + ZEND_ARG_INFO(0, error) + ZEND_ARG_INFO(0, error_style) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_addDataValidationDouble, 0, 0, 7) + ZEND_ARG_INFO(0, type) + ZEND_ARG_INFO(0, op) + ZEND_ARG_INFO(0, row_first) + ZEND_ARG_INFO(0, row_last) + ZEND_ARG_INFO(0, col_first) + ZEND_ARG_INFO(0, col_last) + ZEND_ARG_INFO(0, val_1) + ZEND_ARG_INFO(0, val_2) + ZEND_ARG_INFO(0, allow_blank) + ZEND_ARG_INFO(0, hide_dropdown) + ZEND_ARG_INFO(0, show_inputmessage) + ZEND_ARG_INFO(0, show_errormessage) + ZEND_ARG_INFO(0, prompt_title) + ZEND_ARG_INFO(0, prompt) + ZEND_ARG_INFO(0, error_title) + ZEND_ARG_INFO(0, error) + ZEND_ARG_INFO(0, error_style) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_removeDataValidations, 0, 0, 0) +ZEND_END_ARG_INFO() #endif #define EXCEL_ME(class_name, function_name, arg_info, flags) \ @@ -6272,6 +6494,12 @@ zend_function_entry excel_funcs_book[] = { EXCEL_ME(Book, isTemplate, arginfo_Book_isTemplate, 0) EXCEL_ME(Book, setTemplate, arginfo_Book_setTemplate, 0) EXCEL_ME(Book, sheetType, arginfo_Book_sheetType, 0) + EXCEL_ME(Book, getLibXlVersion, arginfo_Book_getLibXlVersion, 0) + EXCEL_ME(Book, getPhpExcelVersion, arginfo_Book_getPhpExcelVersion, 0) +#if LIBXL_VERSION >= 0x03080000 + EXCEL_ME(Book, addPictureAsLink, arginfo_Book_addPictureAsLink, 0) + EXCEL_ME(Book, moveSheet, arginfo_Book_moveSheet, 0) +#endif {NULL, NULL, NULL} }; @@ -6408,6 +6636,11 @@ zend_function_entry excel_funcs_sheet[] = { EXCEL_ME(Sheet, table, arginfo_Sheet_table, 0) EXCEL_ME(Sheet, writeError, arginfo_Sheet_writeError, 0) EXCEL_ME(Sheet, addIgnoredError, arginfo_Sheet_addIgnoredError, 0) +#endif +#if LIBXL_VERSION >= 0x03080000 + EXCEL_ME(Sheet, addDataValidation, arginfo_Sheet_addDataValidation, 0) + EXCEL_ME(Sheet, addDataValidationDouble, arginfo_Sheet_addDataValidationDouble, 0) + EXCEL_ME(Sheet, removeDataValidations, arginfo_Sheet_removeDataValidations, 0) #endif {NULL, NULL, NULL} }; @@ -6678,6 +6911,7 @@ PHP_MINIT_FUNCTION(excel) REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "ERRORTYPE_VALUE", ERRORTYPE_VALUE); REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "ERRORTYPE_DIV_0", ERRORTYPE_DIV_0); REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "ERRORTYPE_NULL", ERRORTYPE_NULL); + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "ERRORTYPE_NOERROR", ERRORTYPE_NOERROR); REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "PAPER_DEFAULT", PAPER_DEFAULT); REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "PAPER_LETTER", PAPER_LETTER); @@ -6722,7 +6956,6 @@ PHP_MINIT_FUNCTION(excel) REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "PAPER_GERMAN_STD_FANFOLD", PAPER_GERMAN_STD_FANFOLD); REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "PAPER_GERMAN_LEGAL_FANFOLD", PAPER_GERMAN_LEGAL_FANFOLD); - REGISTER_EXCEL_CLASS_CONST_LONG(book, "PICTURETYPE_PNG", PICTURETYPE_PNG); REGISTER_EXCEL_CLASS_CONST_LONG(book, "PICTURETYPE_JPEG", PICTURETYPE_JPEG); REGISTER_EXCEL_CLASS_CONST_LONG(book, "PICTURETYPE_WMF", PICTURETYPE_WMF); @@ -6730,6 +6963,7 @@ PHP_MINIT_FUNCTION(excel) REGISTER_EXCEL_CLASS_CONST_LONG(book, "PICTURETYPE_EMF", PICTURETYPE_EMF); REGISTER_EXCEL_CLASS_CONST_LONG(book, "PICTURETYPE_PICT", PICTURETYPE_PICT); REGISTER_EXCEL_CLASS_CONST_LONG(book, "PICTURETYPE_TIFF", PICTURETYPE_TIFF); + REGISTER_EXCEL_CLASS_CONST_LONG(book, "SCOPE_UNDEFINED", SCOPE_UNDEFINED); REGISTER_EXCEL_CLASS_CONST_LONG(book, "SCOPE_WORKBOOK", SCOPE_WORKBOOK); @@ -6739,6 +6973,7 @@ PHP_MINIT_FUNCTION(excel) REGISTER_EXCEL_CLASS_CONST_LONG(book, "SHEETTYPE_SHEET", SHEETTYPE_SHEET); REGISTER_EXCEL_CLASS_CONST_LONG(book, "SHEETTYPE_CHART", SHEETTYPE_CHART); REGISTER_EXCEL_CLASS_CONST_LONG(book, "SHEETTYPE_UNKNOWN", SHEETTYPE_UNKNOWN); + #if LIBXL_VERSION >= 0x03060300 REGISTER_EXCEL_CLASS_CONST_LONG(book, "POSITION_MOVE_AND_SIZE", POSITION_MOVE_AND_SIZE); REGISTER_EXCEL_CLASS_CONST_LONG(book, "POSITION_ONLY_MOVE", POSITION_ONLY_MOVE); @@ -6794,6 +7029,30 @@ PHP_MINIT_FUNCTION(excel) REGISTER_EXCEL_CLASS_CONST_LONG(filtercolumn, "FILTER_NOT_SET", FILTER_NOT_SET); #endif +#if LIBXL_VERSION >= 0x03080000 + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "VALIDATION_TYPE_NONE", VALIDATION_TYPE_NONE); + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "VALIDATION_TYPE_WHOLE", VALIDATION_TYPE_WHOLE); + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "VALIDATION_TYPE_DECIMAL", VALIDATION_TYPE_DECIMAL); + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "VALIDATION_TYPE_LIST", VALIDATION_TYPE_LIST); + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "VALIDATION_TYPE_DATE", VALIDATION_TYPE_DATE); + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "VALIDATION_TYPE_TIME", VALIDATION_TYPE_TIME); + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "VALIDATION_TYPE_TEXTLENGTH", VALIDATION_TYPE_TEXTLENGTH); + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "VALIDATION_TYPE_CUSTOM", VALIDATION_TYPE_CUSTOM); + + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "VALIDATION_OP_BETWEEN", VALIDATION_OP_BETWEEN); + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "VALIDATION_OP_NOTBETWEEN", VALIDATION_OP_NOTBETWEEN); + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "VALIDATION_OP_EQUAL", VALIDATION_OP_EQUAL); + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "VALIDATION_OP_NOTEQUAL", VALIDATION_OP_NOTEQUAL); + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "VALIDATION_OP_LESSTHAN", VALIDATION_OP_LESSTHAN); + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "VALIDATION_OP_LESSTHANOREQUAL", VALIDATION_OP_LESSTHANOREQUAL); + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "VALIDATION_OP_GREATERTHAN", VALIDATION_OP_GREATERTHAN); + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "VALIDATION_OP_GREATERTHANOREQUAL", VALIDATION_OP_GREATERTHANOREQUAL); + + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "VALIDATION_ERRSTYLE_STOP", VALIDATION_ERRSTYLE_STOP); + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "VALIDATION_ERRSTYLE_WARNING", VALIDATION_ERRSTYLE_WARNING); + REGISTER_EXCEL_CLASS_CONST_LONG(sheet, "VALIDATION_ERRSTYLE_INFORMATION", VALIDATION_ERRSTYLE_INFORMATION); +#endif + return SUCCESS; } /* }}} */ diff --git a/tests/002.phpt b/tests/002.phpt index 64e4a16..256ecbd 100644 --- a/tests/002.phpt +++ b/tests/002.phpt @@ -5,23 +5,23 @@ date.timezone=America/Toronto --SKIPIF-- --FILE-- -unpackDate($x->packDate($tm)); if ($out != $tm) { - echo "source: {$tm} <> res: " . $out . " >> diff: ".($out - $tm)." packed: '".$x->packDate($tm)."'\n"; + echo "[1] source: {$tm} <> res: " . $out . " >> diff: ".($out - $tm)." packed: '".$x->packDate($tm)."'\n"; } } echo "OK\n"; - + for ($i = 0; $i < 1000; $i++) { $tm = time(); //rand(10000000, $t); - + $ed = $x->packDateValues( date('Y', $tm), date('m', $tm), @@ -32,7 +32,9 @@ date.timezone=America/Toronto ); $out = $x->unpackDate($ed); if ($out != $tm) { - echo "source: {$tm} <> res: " . $out . " >> diff: ".($out - $tm)." packed: '".$ed."'\n"; + // known to fail because LibXL packs/unpacks with OS based timezone - not with timezone set in PHP - + // to get this test pass change date.timezone=America/Toronto under --INI-- section to your OS timezone + echo "[2] source: {$tm} <> res: " . $out . " >> diff: ".($out - $tm)." packed: '".$ed."'\n"; } } echo "OK\n"; diff --git a/tests/051.phpt b/tests/051.phpt index 882a06a..103cc72 100644 --- a/tests/051.phpt +++ b/tests/051.phpt @@ -12,6 +12,8 @@ date.timezone=America/Toronto $s->write(1, 1, "Test"); + // fails for LibXl < 3.7.0 + // because setProtect() returns null var_dump( $s->protect(), $s->setProtect(true), @@ -22,6 +24,6 @@ date.timezone=America/Toronto ?> --EXPECT-- bool(false) -NULL +bool(true) bool(true) OK diff --git a/tests/092.phpt b/tests/092.phpt new file mode 100644 index 0000000..293d75a --- /dev/null +++ b/tests/092.phpt @@ -0,0 +1,15 @@ +--TEST-- +Book::getLibXlVersion() +--SKIPIF-- + +--FILE-- +getLibXlVersion()) +); + +?> +--EXPECT-- +bool(true) \ No newline at end of file diff --git a/tests/093.phpt b/tests/093.phpt new file mode 100644 index 0000000..6882d74 --- /dev/null +++ b/tests/093.phpt @@ -0,0 +1,15 @@ +--TEST-- +Book::getPhpExcelVersion() +--SKIPIF-- + +--FILE-- +getPhpExcelVersion()) +); + +?> +--EXPECT-- +bool(true) \ No newline at end of file diff --git a/tests/094.phpt b/tests/094.phpt new file mode 100644 index 0000000..8d58a12 --- /dev/null +++ b/tests/094.phpt @@ -0,0 +1,119 @@ +--TEST-- +Sheet::addDataValidation() +--SKIPIF-- + +--FILE-- +addDataValidation( + \ExcelSheet::VALIDATION_TYPE_WHOLE, + \ExcelSheet::VALIDATION_OP_BETWEEN, + 1, + 2, + 1, + 2, + '1' + ) + ); + + var_dump( + $sheet->addDataValidation( + \ExcelSheet::VALIDATION_TYPE_WHOLE, + \ExcelSheet::VALIDATION_OP_BETWEEN, + 1, + 2, + 1, + 2, + '1', + '3' + ) + ); + + var_dump( + $sheet->addDataValidation( + \ExcelSheet::VALIDATION_TYPE_WHOLE, + \ExcelSheet::VALIDATION_OP_BETWEEN, + 1, + 2, + 1, + 2, + '1', + '100', + 1, + 0, + 1, + 1, + 'Prompt_Title', + 'Prompt', + 'Error Title', + 'Error' + ) + ); + + var_dump( + $sheet->addDataValidationDouble( + \ExcelSheet::VALIDATION_TYPE_WHOLE, + \ExcelSheet::VALIDATION_OP_BETWEEN, + 1, + 2, + 1, + 2, + '1' + ) + ); + + var_dump( + $sheet->addDataValidationDouble( + \ExcelSheet::VALIDATION_TYPE_WHOLE, + \ExcelSheet::VALIDATION_OP_BETWEEN, + 1, + 2, + 1, + 2, + 1, + 2, + 1, + 0, + 1, + 3, + 'Prompt_Title', + 'Prompt', + 'Error Title', + 'Error' + ) + ); + + var_dump( + $sheet->addDataValidation( + \ExcelSheet::VALIDATION_TYPE_WHOLE, + \ExcelSheet::VALIDATION_OP_EQUAL, + 1, + 2, + 1, + 2, + '1' + ) + ); + + var_dump( + $sheet->removeDataValidations() + ); + + echo "OK\n"; + +?> +--EXPECTF-- +Warning: ExcelSheet::addDataValidation(): The second value can not be null when used with (not) between operator. in %s on line %d +bool(false) +bool(true) +bool(true) + +Warning: ExcelSheet::addDataValidationDouble(): The second value can not be null when used with (not) between operator. in %s on line %d +bool(false) +bool(true) +bool(true) +bool(true) +OK \ No newline at end of file diff --git a/tests/095.phpt b/tests/095.phpt new file mode 100644 index 0000000..70fcc25 --- /dev/null +++ b/tests/095.phpt @@ -0,0 +1,68 @@ +--TEST-- +Book::moveSheet() +--SKIPIF-- + +--FILE-- +getSheet(0)->name(), + $book->getSheet(1)->name(), + $book->getSheet(2)->name(), + $book->getSheet(3)->name(), + $book->getSheet(4)->name() + ); + + var_dump( + $book->moveSheet(0,2) + ); + + var_dump( + $book->getSheet(0)->name(), + $book->getSheet(1)->name(), + $book->getSheet(2)->name(), + $book->getSheet(3)->name(), + $book->getSheet(4)->name() + ); + + var_dump( + $book->moveSheet(0,3) + ); + + var_dump( + $book->getSheet(0)->name(), + $book->getSheet(1)->name(), + $book->getSheet(2)->name(), + $book->getSheet(3)->name(), + $book->getSheet(4)->name() + ); + + echo "OK\n"; + +?> +--EXPECT-- +string(6) "sheet1" +string(6) "sheet2" +string(6) "sheet3" +string(6) "sheet4" +string(6) "sheet5" +bool(true) +string(6) "sheet2" +string(6) "sheet1" +string(6) "sheet3" +string(6) "sheet4" +string(6) "sheet5" +bool(true) +string(6) "sheet1" +string(6) "sheet3" +string(6) "sheet2" +string(6) "sheet4" +string(6) "sheet5" +OK From e9e9bd7f7b35418c3e8245a5391ff9833345eb0e Mon Sep 17 00:00:00 2001 From: Johannes Mueller Date: Mon, 1 May 2017 17:03:38 +0200 Subject: [PATCH 46/68] Revert "Added ExcelFormat::AS_STRING const" This reverts commit eeb9a813f83a06deca8cb3cf910094b4c40fdbb6. --- excel.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/excel.c b/excel.c index f24352e..2b31a0c 100644 --- a/excel.c +++ b/excel.c @@ -53,7 +53,6 @@ static long xlFormatBorderColor(FormatHandle f) #define PHP_EXCEL_DATE 1 #define PHP_EXCEL_FORMULA 2 #define PHP_EXCEL_NUMERIC_STRING 3 -#define PHP_EXCEL_STRING 4 #define PHP_EXCEL_VERSION "1.0.3dev" @@ -6745,7 +6744,6 @@ PHP_MINIT_FUNCTION(excel) REGISTER_EXCEL_CLASS_CONST_LONG(format, "AS_DATE", PHP_EXCEL_DATE); REGISTER_EXCEL_CLASS_CONST_LONG(format, "AS_FORMULA", PHP_EXCEL_FORMULA); REGISTER_EXCEL_CLASS_CONST_LONG(format, "AS_NUMERIC_STRING", PHP_EXCEL_NUMERIC_STRING); - REGISTER_EXCEL_CLASS_CONST_LONG(format, "AS_STRING", PHP_EXCEL_STRING); REGISTER_EXCEL_CLASS_CONST_LONG(format, "COLOR_BLACK", COLOR_BLACK); REGISTER_EXCEL_CLASS_CONST_LONG(format, "COLOR_WHITE", COLOR_WHITE); From 0f845881ce425d5e3cf4c94029f3825a96209a94 Mon Sep 17 00:00:00 2001 From: Johannes Mueller Date: Mon, 1 May 2017 17:13:49 +0200 Subject: [PATCH 47/68] removed remaining code of PR #183 --- excel.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/excel.c b/excel.c index 2b31a0c..e253792 100644 --- a/excel.c +++ b/excel.c @@ -2400,12 +2400,12 @@ zend_bool php_excel_write_cell(SheetHandle sheet, BookHandle book, int row, int case IS_STRING: data_zs = Z_STR_P(data); - if (Z_STRLEN_P(data) > 0 && '\'' == Z_STRVAL_P(data)[0]) { - return xlSheetWriteStr(sheet, row, col, (const char*) ZSTR_VAL(data_zs) + 1, format); - } if (dtype == PHP_EXCEL_STRING) { return xlSheetWriteStr(sheet, row, col, (const char*) ZSTR_VAL(data_zs), format); } + if (Z_STRLEN_P(data) > 0 && '\'' == Z_STRVAL_P(data)[0]) { + return xlSheetWriteStr(sheet, row, col, (const char*) ZSTR_VAL(data_zs) + 1, format); + } if (Z_STRLEN_P(data) > 0 && '=' == Z_STRVAL_P(data)[0]) { dtype = PHP_EXCEL_FORMULA; } From 82a2e6d9f87eac46d8313e73b2925ca5d6582cce Mon Sep 17 00:00:00 2001 From: Johannes Mueller Date: Mon, 1 May 2017 17:17:36 +0200 Subject: [PATCH 48/68] removed remaining code of PR #183 --- excel.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/excel.c b/excel.c index e253792..ae8e9f3 100644 --- a/excel.c +++ b/excel.c @@ -2400,9 +2400,6 @@ zend_bool php_excel_write_cell(SheetHandle sheet, BookHandle book, int row, int case IS_STRING: data_zs = Z_STR_P(data); - if (dtype == PHP_EXCEL_STRING) { - return xlSheetWriteStr(sheet, row, col, (const char*) ZSTR_VAL(data_zs), format); - } if (Z_STRLEN_P(data) > 0 && '\'' == Z_STRVAL_P(data)[0]) { return xlSheetWriteStr(sheet, row, col, (const char*) ZSTR_VAL(data_zs) + 1, format); } From a5936d98b918d883acdcfb5d7313b1504f566cb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Sun, 11 Jun 2017 15:12:43 +0200 Subject: [PATCH 49/68] fixes issue #176 --- excel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/excel.c b/excel.c index 8593331..247642f 100644 --- a/excel.c +++ b/excel.c @@ -1748,7 +1748,7 @@ EXCEL_METHOD(Format, getFont) RETURN_FALSE; } - ZVAL_OBJ(return_value, excel_object_new_sheet(excel_ce_font)); + ZVAL_OBJ(return_value, excel_object_new_font(excel_ce_font)); fo = Z_EXCEL_FONT_OBJ_P(return_value); fo->font = font; fo->book = obj->book; From 5f3f61915326c93695b7c8402e335b91ede8d582 Mon Sep 17 00:00:00 2001 From: Xavier Perseguers Date: Sun, 15 Oct 2017 11:05:45 +0200 Subject: [PATCH 50/68] Fix order of parameters for \ExcelAutoFilter::setRef() This patch reorders the PHP method parameters to be in line with those from LibXL (see http://www.libxl.com/autoFilter.html). Resolves: #216 --- docs/ExcelAutoFilter.php | 6 +++--- excel.c | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/ExcelAutoFilter.php b/docs/ExcelAutoFilter.php index 913fdea..faa2eba 100644 --- a/docs/ExcelAutoFilter.php +++ b/docs/ExcelAutoFilter.php @@ -27,7 +27,7 @@ public function __construct($sheet) /** * Gets the cell range of AutoFilter with header. * - * @return array with keys "row_first"(int), "col_first"(int), "row_last"(int), "col_last"(int) + * @return array with keys "row_first"(int), "row_last"(int), "col_first"(int), "col_last"(int) */ public function getRef() { @@ -37,12 +37,12 @@ public function getRef() * Sets the cell range of AutoFilter with header. * * @param int $row_first 0-based (optional, default = 0) - * @param int $col_first 0-based (optional, default = 0) * @param int $row_last 0-based (optional, default = 0) + * @param int $col_first 0-based (optional, default = 0) * @param int $col_last 0-based (optional, default = 0) * @return void */ - public function setRef($row_first=0, $col_first=0, $row_last=0, $col_last=0) + public function setRef($row_first=0, $row_last=0, $col_first=0, $col_last=0) { } // setRef diff --git a/excel.c b/excel.c index 8593331..3f3841e 100644 --- a/excel.c +++ b/excel.c @@ -4859,15 +4859,15 @@ EXCEL_METHOD(AutoFilter, setRef) { zval *object = getThis(); AutoFilterHandle autofilter; - zend_long rowFirst=0, colFirst=0, rowLast=0, colLast=0; + zend_long rowFirst=0, rowLast=0, colFirst=0, colLast=0; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "llll", &rowFirst, &colFirst, &rowLast, &colLast) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "llll", &rowFirst, &rowLast, &colFirst, &colLast) == FAILURE) { RETURN_FALSE; } AUTOFILTER_FROM_OBJECT(autofilter, object); - xlAutoFilterSetRef(autofilter, rowFirst, colFirst, rowLast, colLast); + xlAutoFilterSetRef(autofilter, rowFirst, rowLast, colFirst, colLast); } /* }}} */ @@ -4942,18 +4942,18 @@ EXCEL_METHOD(AutoFilter, getSortRange) { zval *object = getThis(); AutoFilterHandle autofilter; - int rowFirst=0, colFirst=0, rowLast=0, colLast=0; + int rowFirst=0, rowLast=0, colFirst=0, colLast=0; AUTOFILTER_FROM_OBJECT(autofilter, object); - if (!xlAutoFilterGetSortRange(autofilter, &rowFirst, &colFirst, &rowLast, &colLast)) { + if (!xlAutoFilterGetSortRange(autofilter, &rowFirst, &rowLast, &colFirst, &colLast)) { RETURN_FALSE; } array_init(return_value); add_assoc_long(return_value, "row_first", rowFirst); - add_assoc_long(return_value, "col_first", colFirst); add_assoc_long(return_value, "row_last", rowLast); + add_assoc_long(return_value, "col_first", colFirst); add_assoc_long(return_value, "col_last", rowLast); } /* }}} */ From 46924402a231099244aec4ab0b190e60fe8593e0 Mon Sep 17 00:00:00 2001 From: Xavier Perseguers Date: Sun, 15 Oct 2017 11:24:09 +0200 Subject: [PATCH 51/68] Streamline PHP documentation Resolves: #219 --- docs/ExcelAutoFilter.php | 4 ++-- docs/ExcelFilterColumn.php | 6 +++--- docs/ExcelFont.php | 2 +- docs/ExcelSheet.php | 10 +++++----- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/ExcelAutoFilter.php b/docs/ExcelAutoFilter.php index faa2eba..91999a6 100644 --- a/docs/ExcelAutoFilter.php +++ b/docs/ExcelAutoFilter.php @@ -20,7 +20,7 @@ class ExcelAutoFilter * @param ExcelSheet $sheet * @return ExcelAutoFilter */ - public function __construct($sheet) + public function __construct(ExcelSheet $sheet) { } // __construct @@ -42,7 +42,7 @@ public function getRef() * @param int $col_last 0-based (optional, default = 0) * @return void */ - public function setRef($row_first=0, $row_last=0, $col_first=0, $col_last=0) + public function setRef($row_first = 0, $row_last = 0, $col_first = 0, $col_last = 0) { } // setRef diff --git a/docs/ExcelFilterColumn.php b/docs/ExcelFilterColumn.php index a8db48a..7514cab 100644 --- a/docs/ExcelFilterColumn.php +++ b/docs/ExcelFilterColumn.php @@ -36,7 +36,7 @@ class ExcelFilterColumn * @param ExcelAutoFilter $autoFilter * @return ExcelFilterColumn */ - public function __construct($autoFilter) + public function __construct(ExcelAutoFilter $autoFilter) { } // __construct @@ -104,7 +104,7 @@ public function getTop10() * @param bool $percent - using percent instead of number items. (optional, default = false) * @return bool */ - public function setTop10($value, $top=true, $percent=false) + public function setTop10($value, $top = true, $percent = false) { } // setTop10 @@ -127,7 +127,7 @@ public function getCustomFilter() * @param bool $andOp - flag indicating whether the two criterias have an "and" relationship. True indicates "and", false indicates "or". (optional, default = false) * @return void */ - public function setCustomFilter($op1, $v1, $op2=-1, $v2=null, $andOp=false) + public function setCustomFilter($op1, $v1, $op2 = -1, $v2 = null, $andOp = false) { } // setCustomFilter diff --git a/docs/ExcelFont.php b/docs/ExcelFont.php index cb4fe92..53f3fae 100644 --- a/docs/ExcelFont.php +++ b/docs/ExcelFont.php @@ -31,7 +31,7 @@ class ExcelFont * @param ExcelBook $book * @return ExcelFont */ - public function __construct($book) + public function __construct(ExcelBook $book) { } // __construct diff --git a/docs/ExcelSheet.php b/docs/ExcelSheet.php index 28b1fce..a9451f9 100644 --- a/docs/ExcelSheet.php +++ b/docs/ExcelSheet.php @@ -140,7 +140,7 @@ public function addHyperlink($hyperlink, $row_first, $row_last, $col_first, $col public function addIgnoredError($error, $row_first=0, $col_first=0, $row_last=0, $col_last=0) { } // addIgnoredError - + /** * Insert a picture into a cell with given dimensions * @@ -1055,7 +1055,7 @@ public function setColWidth($column_start, $column_end, $width, $hidden = false, * @param int $column_end 0-based column number * @return bool */ - public function setAutofitArea($row_start=0, $row_end=-1, $column_start=0, $column_end=-1) + public function setAutofitArea($row_start = 0, $row_end = -1, $column_start = 0, $column_end = -1) { } // setAutofitArea @@ -1357,7 +1357,7 @@ public function printRepeatRows() * @param int ExcelSheet::PROT_ALL (optional, default=ExcelSheet::PROT_DEFAULT) * @return void */ - public function setProtect($value, $password="", $enhancedProtection=ExcelSheet::PROT_DEFAULT) + public function setProtect($value, $password = '', $enhancedProtection = ExcelSheet::PROT_DEFAULT) { } // setProtect @@ -1470,7 +1470,7 @@ public function splitSheet($row, $column) * @param int $index (optional, default = 0) * @return array with keys "name"(string), "row_first"(int), "col_first"(int), "row_last"(int), "col_last"(int), "header_row_count"(int) and "totals_row_count"(int) */ - public function table($index=0) + public function table($index = 0) { } // table @@ -1558,7 +1558,7 @@ public function writeComment($row, $column, $comment, $author, $width, $height) * @param ExcelFormat $format (optional, default = null) * @return bool */ - public function writeError($row=0, $col=0, $error=0, $format=null) + public function writeError($row = 0, $col = 0, $error = 0, $format = null) { } // writeError From 0720fca5107c5e782bf50ef4a2d2ec9c7777c477 Mon Sep 17 00:00:00 2001 From: Jan-E Date: Mon, 31 Dec 2018 04:03:20 +0100 Subject: [PATCH 52/68] Fix #241 for PHP7 --- docs/ExcelSheet.php | 12 +++++++---- excel.c | 49 +++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 53 insertions(+), 8 deletions(-) diff --git a/docs/ExcelSheet.php b/docs/ExcelSheet.php index 41542fc..f9bee2d 100644 --- a/docs/ExcelSheet.php +++ b/docs/ExcelSheet.php @@ -773,9 +773,10 @@ public function horPageBreak($row, $break) * * @param int $column_start 0-based column number * @param int $column_end 0-based column number + * @param bool $update_named_ranges (optional, default=true) * @return bool */ - public function insertCol($column_start, $column_end) + public function insertCol($column_start, $column_end, $update_named_ranges = true) { } // insertCol @@ -784,9 +785,10 @@ public function insertCol($column_start, $column_end) * * @param int $row_start 0-based row number * @param int $row_end 0-based row number + * @param bool $update_named_ranges (optional, default=true) * @return bool */ - public function insertRow($row_start, $row_end) + public function insertRow($row_start, $row_end, $update_named_ranges = true) { } // insertRow @@ -1032,9 +1034,10 @@ public function readRow($row, $column_start = 0, $column_end = -1, $read_formula * * @param int $column_start 0-based column number * @param int $column_end 0-based column number + * @param bool $update_named_ranges (optional, default=true) * @return bool */ - public function removeCol($column_start, $column_end) + public function removeCol($column_start, $column_end, $update_named_ranges = true) { } // removeCol @@ -1053,9 +1056,10 @@ public function removeDataValidations() * * @param int $row_start 0-based row number * @param int $row_end 0-based row number + * @param bool $update_named_ranges (optional, default=true) * @return bool */ - public function removeRow($row_start, $row_end) + public function removeRow($row_start, $row_end, $update_named_ranges = true) { } // removeRow diff --git a/excel.c b/excel.c index 5e2beaf..8530094 100644 --- a/excel.c +++ b/excel.c @@ -2585,6 +2585,19 @@ EXCEL_METHOD(Sheet, writeCol) RETURN_BOOL(xlSheet ## func_name (sheet, r, c)); \ } +#define PHP_EXCEL_SHEET_GET_BOOL_STATE_3831(func_name) \ + { \ + SheetHandle sheet; \ + zval *object = getThis(); \ + zend_long r, c; \ + zend_bool u = 1; \ + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll|b", &r, &c, &u) == FAILURE) { \ + RETURN_FALSE; \ + } \ + SHEET_FROM_OBJECT(sheet, object); \ + RETURN_BOOL(xlSheet ## func_name (sheet, r, c, u)); \ + } + /* {{{ proto bool ExcelSheet::isFormula(int row, int column) Determine if the cell contains a formula */ EXCEL_METHOD(Sheet, isFormula) @@ -2615,35 +2628,51 @@ EXCEL_METHOD(Sheet, isDate) } /* }}} */ -/* {{{ proto bool ExcelSheet::insertRow(int row_first, int row_last) +/* {{{ proto bool ExcelSheet::insertRow(int row_first, int row_last, bool update_named_ranges) Inserts rows from rowFirst to rowLast */ EXCEL_METHOD(Sheet, insertRow) { +#if LIBXL_VERSION >= 0x03080301 + PHP_EXCEL_SHEET_GET_BOOL_STATE_3831(InsertRow) +#else PHP_EXCEL_SHEET_GET_BOOL_STATE(InsertRow) +#endif } /* }}} */ -/* {{{ proto bool ExcelSheet::insertCol(int col_first, int col_last) +/* {{{ proto bool ExcelSheet::insertCol(int col_first, int col_last, bool update_named_ranges) Inserts columns from colFirst to colLast */ EXCEL_METHOD(Sheet, insertCol) { +#if LIBXL_VERSION >= 0x03080301 + PHP_EXCEL_SHEET_GET_BOOL_STATE_3831(InsertCol) +#else PHP_EXCEL_SHEET_GET_BOOL_STATE(InsertCol) +#endif } /* }}} */ -/* {{{ proto bool ExcelSheet::removeRow(int row_first, int row_last) +/* {{{ proto bool ExcelSheet::removeRow(int row_first, int row_last, bool update_named_ranges) Removes rows from rowFirst to rowLast */ EXCEL_METHOD(Sheet, removeRow) { +#if LIBXL_VERSION >= 0x03080301 + PHP_EXCEL_SHEET_GET_BOOL_STATE_3831(RemoveRow) +#else PHP_EXCEL_SHEET_GET_BOOL_STATE(RemoveRow) +#endif } /* }}} */ -/* {{{ proto bool ExcelSheet::removeCol(int col_first, int col_last) +/* {{{ proto bool ExcelSheet::removeCol(int col_first, int col_last, bool update_named_ranges) Removes columns from colFirst to colLast */ EXCEL_METHOD(Sheet, removeCol) { +#if LIBXL_VERSION >= 0x03080301 + PHP_EXCEL_SHEET_GET_BOOL_STATE_3831(RemoveCol) +#else PHP_EXCEL_SHEET_GET_BOOL_STATE(RemoveCol) +#endif } /* }}} */ @@ -5798,21 +5827,33 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_insertRow, 0, 0, 2) ZEND_ARG_INFO(0, row_first) ZEND_ARG_INFO(0, row_last) +#if LIBXL_VERSION >= 0x03080301 + ZEND_ARG_INFO(0, update_named_ranges) +#endif ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_insertCol, 0, 0, 2) ZEND_ARG_INFO(0, col_first) ZEND_ARG_INFO(0, col_last) +#if LIBXL_VERSION >= 0x03080301 + ZEND_ARG_INFO(0, update_named_ranges) +#endif ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_removeRow, 0, 0, 2) ZEND_ARG_INFO(0, row_first) ZEND_ARG_INFO(0, row_last) +#if LIBXL_VERSION >= 0x03080301 + ZEND_ARG_INFO(0, update_named_ranges) +#endif ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_removeCol, 0, 0, 2) ZEND_ARG_INFO(0, col_first) ZEND_ARG_INFO(0, col_last) +#if LIBXL_VERSION >= 0x03080301 + ZEND_ARG_INFO(0, update_named_ranges) +#endif ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_colWidth, 0, 0, 1) From 2961c725b4041a04f36983365f9ea676e32aa665 Mon Sep 17 00:00:00 2001 From: Jan-E Date: Mon, 31 Dec 2018 04:08:31 +0100 Subject: [PATCH 53/68] Fix #234 for PHP7 --- ChangeLog | 3 ++- excel.c | 18 +++++++----------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 27c57f1..442cc74 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ -[2017-??-??] - Version 1.0.3dev +[2018-??-??] - Version 1.0.3dev * Fixed crash when trying to read an empty file + * Fixed bug with writing references (see issue #234) * Added PECL package.xml to allow installation via pecl * Added ExcelSheet::AS_STRING const to use with write operations (see PR 183 by ederuiter) * Added new methods (requires LibXL 3.8.0) diff --git a/excel.c b/excel.c index 8530094..b998482 100644 --- a/excel.c +++ b/excel.c @@ -2366,14 +2366,14 @@ zend_bool php_excel_write_cell(SheetHandle sheet, BookHandle book, int row, int { zend_string *data_zs; + try_again: switch (Z_TYPE_P(data)) { case IS_NULL: if (INI_INT("excel.skip_empty") > 0) { return 1; } if (!format) { - FormatHandle fmt = xlBookAddFormat(book, NULL); - return xlSheetWriteBlank(sheet, row, col, fmt); + return xlSheetWriteBlank(sheet, row, col, NULL); } else { return xlSheetWriteBlank(sheet, row, col, format); } @@ -2433,16 +2433,12 @@ zend_bool php_excel_write_cell(SheetHandle sheet, BookHandle book, int row, int case IS_FALSE: return xlSheetWriteBool(sheet, row, col, 0, format); - case IS_ARRAY: - php_error_docref(NULL, E_WARNING, "Type mismatch: array not supported for atomic write operation in row %d, column %d", row, col); - return 1; - - case IS_OBJECT: - php_error_docref(NULL, E_WARNING, "Type mismatch: object not supported for atomic write operation in row %d, column %d", row, col); - return 1; + case IS_REFERENCE: + ZVAL_DEREF(data); + goto try_again; - case IS_RESOURCE: - php_error_docref(NULL, E_WARNING, "Type mismatch: resource not supported for atomic write operation in row %d, column %d", row, col); + default: + php_error_docref(NULL, E_WARNING, "Type mismatch: %s not supported for atomic write operation in row %d, column %d", Z_TYPE_P(data), row, col); return 1; } From 623489d3f80482e08ccddd0c98ec07092bb7429a Mon Sep 17 00:00:00 2001 From: Jan-E Date: Mon, 31 Dec 2018 04:24:42 +0100 Subject: [PATCH 54/68] added new methods Book::getSheetName() and Book::loadInfo() --- docs/ExcelBook.php | 22 +++++++++++++++- excel.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 1 deletion(-) diff --git a/docs/ExcelBook.php b/docs/ExcelBook.php index a9e0b66..459ee7a 100644 --- a/docs/ExcelBook.php +++ b/docs/ExcelBook.php @@ -87,7 +87,7 @@ public function addFormat(ExcelFormat $format = null) /** * Adds a picture to the workbook as link (only for xlsx files). * Supports BMP, DIB, PNG, JPG and WMF picture formats. Use picture identifier with - * \ExcelSheet::setPictureDim() or \ExcelSheet::setPictureScale() + * \ExcelSheet::setPictureDim() or \ExcelSheet::setPictureScale() * @see \ExcelSheet::setPictureDim() * @see \ExcelSheet::setPictureScale() * @@ -360,6 +360,16 @@ public function loadFile($filename) { } // loadFile + /** + * Load Excel sheet info + * + * @param string $filename + * @return bool + */ + public function loadInfo($filename) + { + } // loadInfo + /** * Moves a sheet with specified index to a new position. Returns false if error occurs. * @@ -508,6 +518,16 @@ public function sheetCount() { } // sheetCount + /** + * Returns the sheet name by index + * + * @param int $index + * @return string + */ + public function getSheetName($index) + { + } // getSheetName + /** * Returns type of sheet with specified index: * 0 - sheet diff --git a/excel.c b/excel.c index 5e2beaf..e3f89de 100644 --- a/excel.c +++ b/excel.c @@ -1481,6 +1481,57 @@ EXCEL_METHOD(Book, getPhpExcelVersion) } /* }}} */ +#if LIBXL_VERSION >= 0x03080300 +/* {{{ proto bool ExcelBook::loadInfo(string filename) + Loads only information about sheets. Afterwards you can call Book::sheetCount() + and Book::getSheetName() methods. Returns false if error occurs. Get error + info with Book::errorMessage(). */ +EXCEL_METHOD(Book, loadInfo) +{ + BookHandle book; + zval *object = getThis(); + zend_string *filename_zs = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &filename_zs) == FAILURE) { + RETURN_FALSE; + } + + EXCEL_NON_EMPTY_STRING(filename_zs) + + BOOK_FROM_OBJECT(book, object); + + RETURN_BOOL(xlBookLoadInfo(book, ZSTR_VAL(filename_zs))); +} +/* }}} */ + +/* {{{ proto string ExcelBook::getSheetName(int index) + Returns a sheet name with specified index. Returns + NULL if error occurs. Get error info with xlBookErrorMessage(). */ +EXCEL_METHOD(Book, getSheetName) +{ + BookHandle book; + zval *object = getThis(); + zend_long index; + char *data; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) { + RETURN_FALSE; + } + + if (index < 1) { + RETURN_FALSE; + } + + BOOK_FROM_OBJECT(book, object); + + if (!(data = (char *)xlBookGetSheetName(book, index))) { + RETURN_FALSE; + } + RETURN_STRING(data); +} +/* }}} */ +#endif + /* {{{ proto int ExcelFont::size([int size]) Get or set the font size */ EXCEL_METHOD(Font, size) @@ -5577,6 +5628,16 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_getPhpExcelVersion, 0, 0, 0) ZEND_END_ARG_INFO() +#if LIBXL_VERSION >= 0x03080300 +ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_loadInfo, 0, 0, 1) + ZEND_ARG_INFO(0, filename) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_Book_getSheetName, 0, 0, 1) + ZEND_ARG_INFO(0, index) +ZEND_END_ARG_INFO() +#endif + ZEND_BEGIN_ARG_INFO_EX(arginfo_Font_size, 0, 0, 0) ZEND_ARG_INFO(0, size) ZEND_END_ARG_INFO() @@ -6495,6 +6556,10 @@ zend_function_entry excel_funcs_book[] = { #if LIBXL_VERSION >= 0x03080000 EXCEL_ME(Book, addPictureAsLink, arginfo_Book_addPictureAsLink, 0) EXCEL_ME(Book, moveSheet, arginfo_Book_moveSheet, 0) +#endif +#if LIBXL_VERSION >= 0x03080300 + EXCEL_ME(Book, loadInfo, arginfo_Book_loadInfo, 0) + EXCEL_ME(Book, getSheetName, arginfo_Book_getSheetName, 0) #endif {NULL, NULL, NULL} }; From 01715d0e8465697ddfa897b8c7594ceef801dc9b Mon Sep 17 00:00:00 2001 From: Jan-E Date: Fri, 13 Nov 2020 23:21:30 +0100 Subject: [PATCH 55/68] Fix https://github.com/iliaal/php_excel/issues/264 Changes for PHP7, add PHP8 support --- excel.c | 10 ++++++---- php_excel.h | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/excel.c b/excel.c index fd6f34d..32cf5df 100644 --- a/excel.c +++ b/excel.c @@ -985,10 +985,12 @@ EXCEL_METHOD(Book, getCustomFormat) } /* }}} */ -static double _php_excel_date_pack(BookHandle book, long ts) +static double _php_excel_date_pack(BookHandle book, long longts) { + time_t ts; struct tm tm; + ts = (time_t) longts; if (!php_localtime_r(&ts, &tm)) { return -1; } @@ -3092,7 +3094,7 @@ EXCEL_METHOD(Sheet, copy) #define PE_RETURN_IS_LONG RETURN_LONG #define PE_RETURN_IS_BOOL RETURN_BOOL #define PE_RETURN_IS_DOUBLE RETURN_DOUBLE -#define PE_RETURN_IS_STRING(data) if (data) { RETURN_STRING((char *)data) } else { RETURN_NULL(); } +#define PE_RETURN_IS_STRING(data) if (data) { RETURN_STRING((char *)data); } else { RETURN_NULL(); } #define PHP_EXCEL_INFO(func_name, type) \ { \ @@ -4732,7 +4734,7 @@ EXCEL_METHOD(Sheet, table) { zval *object = getThis(); SheetHandle sheet; - zend_long index=0, rowFirst, rowLast, colFirst, colLast, headerRowCount, totalsRowCount; + int index=0, rowFirst, rowLast, colFirst, colLast, headerRowCount, totalsRowCount; const char *name; if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) { @@ -4846,7 +4848,7 @@ EXCEL_METHOD(Sheet, addIgnoredError) SHEET_FROM_OBJECT(sheet, object); if (!xlSheetAddIgnoredError(sheet, rowFirst, colFirst, rowLast, colLast, iError)) { - RETURN_FALSE + RETURN_FALSE; } RETURN_TRUE; diff --git a/php_excel.h b/php_excel.h index 654528d..8795010 100644 --- a/php_excel.h +++ b/php_excel.h @@ -41,8 +41,8 @@ ZEND_END_MODULE_GLOBALS(excel) # define PHP_EXCEL_ERROR_HANDLING() \ zend_error_handling error_handling; \ - zend_replace_error_handling(EH_THROW, NULL, &error_handling TSRMLS_CC); -# define PHP_EXCEL_RESTORE_ERRORS() zend_restore_error_handling(&error_handling TSRMLS_CC); + zend_replace_error_handling(EH_THROW, NULL, &error_handling); +# define PHP_EXCEL_RESTORE_ERRORS() zend_restore_error_handling(&error_handling); #ifndef Z_SET_ISREF_P # define Z_SET_ISREF_P(pz) (pz)->is_ref = 1 From da2fb8218aee5b4100329e77ba95e6357adeb858 Mon Sep 17 00:00:00 2001 From: Jan-E Date: Sun, 15 Nov 2020 23:18:12 +0100 Subject: [PATCH 56/68] Fix https://github.com/iliaal/php_excel/issues/265 updateNamedRanges changes since LibXL 3.8.8 --- excel.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 88 insertions(+), 8 deletions(-) diff --git a/excel.c b/excel.c index 32cf5df..d92029a 100644 --- a/excel.c +++ b/excel.c @@ -2681,10 +2681,30 @@ EXCEL_METHOD(Sheet, isDate) Inserts rows from rowFirst to rowLast */ EXCEL_METHOD(Sheet, insertRow) { -#if LIBXL_VERSION >= 0x03080301 - PHP_EXCEL_SHEET_GET_BOOL_STATE_3831(InsertRow) +#if LIBXL_VERSION >= 0x03080800 + SheetHandle sheet; + zval *object = getThis(); + zend_long r, c; + zend_bool u = 1; + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll|b", &r, &c, &u) == FAILURE) { + RETURN_FALSE; + } + SHEET_FROM_OBJECT(sheet, object); + if (u == 1) { + RETURN_BOOL(xlSheetInsertRow (sheet, r, c)); + } else { +#ifdef _UNICODE + RETURN_BOOL(xlSheetInsertRowAndKeepRangesW (sheet, r, c)); +#else + RETURN_BOOL(xlSheetInsertRowAndKeepRangesA (sheet, r, c)); +#endif + } #else +# if LIBXL_VERSION >= 0x03080301 + PHP_EXCEL_SHEET_GET_BOOL_STATE_3831(InsertRow) +# else PHP_EXCEL_SHEET_GET_BOOL_STATE(InsertRow) +# endif #endif } /* }}} */ @@ -2693,10 +2713,30 @@ EXCEL_METHOD(Sheet, insertRow) Inserts columns from colFirst to colLast */ EXCEL_METHOD(Sheet, insertCol) { -#if LIBXL_VERSION >= 0x03080301 - PHP_EXCEL_SHEET_GET_BOOL_STATE_3831(InsertCol) +#if LIBXL_VERSION >= 0x03080800 + SheetHandle sheet; + zval *object = getThis(); + zend_long r, c; + zend_bool u = 1; + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll|b", &r, &c, &u) == FAILURE) { + RETURN_FALSE; + } + SHEET_FROM_OBJECT(sheet, object); + if (u == 1) { + RETURN_BOOL(xlSheetInsertCol (sheet, r, c)); + } else { +#ifdef _UNICODE + RETURN_BOOL(xlSheetInsertColAndKeepRangesW (sheet, r, c)); +#else + RETURN_BOOL(xlSheetInsertColAndKeepRangesA (sheet, r, c)); +#endif + } #else +# if LIBXL_VERSION >= 0x03080301 + PHP_EXCEL_SHEET_GET_BOOL_STATE_3831(InsertCol) +# else PHP_EXCEL_SHEET_GET_BOOL_STATE(InsertCol) +# endif #endif } /* }}} */ @@ -2705,10 +2745,30 @@ EXCEL_METHOD(Sheet, insertCol) Removes rows from rowFirst to rowLast */ EXCEL_METHOD(Sheet, removeRow) { -#if LIBXL_VERSION >= 0x03080301 - PHP_EXCEL_SHEET_GET_BOOL_STATE_3831(RemoveRow) +#if LIBXL_VERSION >= 0x03080800 + SheetHandle sheet; + zval *object = getThis(); + zend_long r, c; + zend_bool u = 1; + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll|b", &r, &c, &u) == FAILURE) { + RETURN_FALSE; + } + SHEET_FROM_OBJECT(sheet, object); + if (u == 1) { + RETURN_BOOL(xlSheetRemoveRow (sheet, r, c)); + } else { +#ifdef _UNICODE + RETURN_BOOL(xlSheetRemoveRowAndKeepRangesW (sheet, r, c)); +#else + RETURN_BOOL(xlSheetRemoveRowAndKeepRangesA (sheet, r, c)); +#endif + } #else +# if LIBXL_VERSION >= 0x03080301 + PHP_EXCEL_SHEET_GET_BOOL_STATE_3831(RemoveRow) +# else PHP_EXCEL_SHEET_GET_BOOL_STATE(RemoveRow) +# endif #endif } /* }}} */ @@ -2717,10 +2777,30 @@ EXCEL_METHOD(Sheet, removeRow) Removes columns from colFirst to colLast */ EXCEL_METHOD(Sheet, removeCol) { -#if LIBXL_VERSION >= 0x03080301 - PHP_EXCEL_SHEET_GET_BOOL_STATE_3831(RemoveCol) +#if LIBXL_VERSION >= 0x03080800 + SheetHandle sheet; + zval *object = getThis(); + zend_long r, c; + zend_bool u = 1; + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll|b", &r, &c, &u) == FAILURE) { + RETURN_FALSE; + } + SHEET_FROM_OBJECT(sheet, object); + if (u == 1) { + RETURN_BOOL(xlSheetRemoveCol (sheet, r, c)); + } else { +#ifdef _UNICODE + RETURN_BOOL(xlSheetRemoveColAndKeepRangesW (sheet, r, c)); +#else + RETURN_BOOL(xlSheetRemoveColAndKeepRangesA (sheet, r, c)); +#endif + } #else +# if LIBXL_VERSION >= 0x03080301 + PHP_EXCEL_SHEET_GET_BOOL_STATE_3831(RemoveCol) +# else PHP_EXCEL_SHEET_GET_BOOL_STATE(RemoveCol) +# endif #endif } /* }}} */ From b697264d9a2d6509e3acf4051c9d0e118f48a9e3 Mon Sep 17 00:00:00 2001 From: Jan-E Date: Wed, 18 Nov 2020 02:00:19 +0100 Subject: [PATCH 57/68] Fix borked tests --- excel.c | 2 ++ tests/002.phpt | 2 +- tests/005.phpt | 2 +- tests/075.phpt | 2 +- tests/076.phpt | 2 +- tests/077.phpt | 2 +- tests/078.phpt | 2 +- tests/079.phpt | 2 +- tests/080.phpt | 2 +- tests/092.phpt | 2 +- tests/093.phpt | 2 +- tests/094.phpt | 2 +- tests/095.phpt | 2 +- 13 files changed, 14 insertions(+), 12 deletions(-) diff --git a/excel.c b/excel.c index d92029a..03f8d04 100644 --- a/excel.c +++ b/excel.c @@ -6909,8 +6909,10 @@ PHP_MINIT_FUNCTION(excel) REGISTER_EXCEL_CLASS(Sheet, sheet, NULL); REGISTER_EXCEL_CLASS(Format, format, excel_format_object_clone); REGISTER_EXCEL_CLASS(Font, font, excel_font_object_clone); +#if LIBXL_VERSION >= 0x03070000 REGISTER_EXCEL_CLASS(AutoFilter, autofilter, NULL); REGISTER_EXCEL_CLASS(FilterColumn, filtercolumn, NULL); +#endif REGISTER_EXCEL_CLASS_CONST_LONG(font, "NORMAL", SCRIPT_NORMAL); REGISTER_EXCEL_CLASS_CONST_LONG(font, "SUBSCRIPT", SCRIPT_SUB); diff --git a/tests/002.phpt b/tests/002.phpt index 256ecbd..2e2095f 100644 --- a/tests/002.phpt +++ b/tests/002.phpt @@ -1,7 +1,7 @@ --TEST-- Excel date pack/unpack tests --INI-- -date.timezone=America/Toronto +date.timezone=Europe/Amsterdam --SKIPIF-- --FILE-- diff --git a/tests/005.phpt b/tests/005.phpt index 9bcac24..3fe8239 100644 --- a/tests/005.phpt +++ b/tests/005.phpt @@ -3,7 +3,7 @@ Date format tests --INI-- date.timezone=America/Toronto --SKIPIF-- - + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- Date: Wed, 18 Nov 2020 02:17:59 +0100 Subject: [PATCH 58/68] Fix https://github.com/iliaal/php_excel/issues/266 Format clone & Font clone - 018/019.phpt --- excel.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/excel.c b/excel.c index 03f8d04..baa4e12 100644 --- a/excel.c +++ b/excel.c @@ -329,13 +329,21 @@ static zend_object *excel_object_new_font(zend_class_entry *class_type) return excel_object_new_font_ex(class_type, NULL); } +#if PHP_MAJOR_VERSION >= 8 +static zend_object *excel_font_object_clone(zend_object *this_object) +#else static zend_object *excel_font_object_clone(zval *this_ptr) +#endif { zend_object *new_ov; FontHandle font; excel_font_object *new_obj = NULL; +#if PHP_MAJOR_VERSION >= 8 + excel_font_object *old_obj = php_excel_font_object_fetch_object(this_object); +#else excel_font_object *old_obj = Z_EXCEL_FONT_OBJ_P(this_ptr); +#endif new_ov = excel_object_new_font_ex(old_obj->std.ce, &new_obj); font = xlBookAddFont(old_obj->book, old_obj->font); @@ -382,13 +390,21 @@ static zend_object *excel_object_new_format(zend_class_entry *class_type) return excel_object_new_format_ex(class_type, NULL); } +#if PHP_MAJOR_VERSION >= 8 +static zend_object *excel_format_object_clone(zend_object *this_object) +#else static zend_object *excel_format_object_clone(zval *this_ptr) +#endif { zend_object *new_ov; FormatHandle format; excel_format_object *new_obj = NULL; +#if PHP_MAJOR_VERSION >= 8 + excel_format_object *old_obj = php_excel_format_object_fetch_object(this_object); +#else excel_format_object *old_obj = Z_EXCEL_FORMAT_OBJ_P(this_ptr); +#endif new_ov = excel_object_new_format_ex(old_obj->std.ce, &new_obj); format = xlBookAddFormat(old_obj->book, old_obj->format); From 59c697784f173b33a0db349a3c37e3d5e919416a Mon Sep 17 00:00:00 2001 From: Darren Odden Date: Wed, 10 May 2023 18:16:49 -0700 Subject: [PATCH 59/68] update ignore --- .idea/workspace.xml | 122 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 .idea/workspace.xml diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..00175cf --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,122 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1683761430105 + + + 1683761728804 + + + 1683761810694 + + + 1683765901708 + + + + + + + + + + + + + \ No newline at end of file From 0c156181b9baea3260e5fc23e77668b1ed5879ba Mon Sep 17 00:00:00 2001 From: Darren Odden Date: Wed, 10 May 2023 19:23:29 -0700 Subject: [PATCH 60/68] git ignore update --- .gitignore | 1 + .idea/workspace.xml | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 66f52a1..6359af8 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ *.la .deps .libs +.idea Makefile Makefile.fragments Makefile.global diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 00175cf..f32acb6 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -43,7 +43,7 @@ "WebServerToolWindowFactoryState": "false", "cf.first.check.clang-format": "false", "cidr.known.project.marker": "true", - "git-widget-placeholder": "main", + "git-widget-placeholder": "update__ignore", "last_opened_file_path": "/Users/do/dev/doPhp/excel", "node.js.detected.package.eslint": "true", "node.js.detected.package.tslint": "true", @@ -61,7 +61,7 @@