Skip to content

Commit b730495

Browse files
committed
added warnings on read/write errors, fixed missing php_stream_close(), updated README, updated changelog
1 parent 1bda0f4 commit b730495

File tree

4 files changed

+85
-63
lines changed

4 files changed

+85
-63
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,4 @@ tests/*/*/*.diff
6464
tests/*/*/*.php
6565
tests/*/*/*.exp
6666
tmp-php.ini
67+
libxl/*

ChangeLog

+7-3
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@
1818
* Added data type argument for ExcelSheet::writeCol() (see issue #29)
1919
* Fixed bug in ExcelSheet::read() (see issue #86)
2020
* Fixed bug in ExcelBook::setDefaultFont() (see issue #66)
21-
* Added autofit handling for ExcelBook::setColWidth()
21+
* Added autofit support for ExcelBook::setColWidth()
2222
* Added implicit formula recognition on ExcelSheet::write() operations (prefix formula with '=')
2323
* Added multibyte support for license name and license key (see issue #60 and README)
2424
* Added default date format when writing dates
2525
* Added ExcelSheet::__construct(ExcelBook $book, $name) for customized ExcelSheets
26-
* Updated documentation
27-
* Fixed typo -> changed excel.ini_skip_empty to excel.skip_emtpy
26+
* Added warnings on read/write errors
27+
* Removed final keyword for ExcelFormat::__construct(ExcelBook $book)
28+
* Removed invalid PAPER_* constants in ExcelSheet
29+
* Removed invalid COLOR_* constants in ExcelFormat
30+
* Updated documentation and README
31+
* Changed php.ini variable name: excel.ini_skip_empty --> excel.skip_emtpy
2832

2933
[2014-06-03] - Version 1.0
3034
* Fixed issue #63 writing for NULL values using writeRow()

README.markdown

+65-59
Original file line numberDiff line numberDiff line change
@@ -20,79 +20,85 @@ Please see the ```docs/``` and the ```tests/``` directory.
2020

2121
### Linux
2222

23-
// change into php source files directory
24-
cd php-5.x.x
25-
26-
// clone repository into php extension dir
27-
git clone https://github.com/iliaal/php_excel.git ext/excel
28-
29-
// rebuild configure
30-
./buildconf --force
31-
32-
// replace <PATH> with the file path to the extracted libxl files
33-
// on a 32-bit platform use
34-
./configure --with-excel --with-libxl-incdir=<PATH>/libxl-3.6.0.1/include_c --with-libxl-libdir=<PATH>/libxl-3.6.0.1/lib
35-
36-
// on a 64-bit platform use
37-
./configure --with-excel --with-libxl-incdir=<PATH>/libxl-3.6.0.1/include_c --with-libxl-libdir=<PATH>/libxl-3.6.0.1/lib64
23+
``` shell
24+
# change into php source files directory
25+
cd php-5.x.x
3826

27+
# clone repository into php extension dir
28+
git clone https://github.com/iliaal/php_excel.git ext/excel
29+
30+
# rebuild configure
31+
./buildconf --force
32+
33+
# replace <PATH> with the file path to the extracted libxl files
34+
# on a 32-bit platform use
35+
./configure --with-excel --with-libxl-incdir=<PATH>/libxl-3.6.0.1/include_c --with-libxl-libdir=<PATH>/libxl-3.6.0.1/lib
36+
37+
# on a 64-bit platform use
38+
./configure --with-excel --with-libxl-incdir=<PATH>/libxl-3.6.0.1/include_c --with-libxl-libdir=<PATH>/libxl-3.6.0.1/lib64
39+
```
40+
3941
### Windows
4042

4143
Pre-build packages for Windows can be downloaded [here](http://windows.php.net/downloads/pecl/snaps/excel).
4244

4345
## Getting started
4446

45-
<?php
46-
47-
// init excel work book as xlsx
48-
$useXlsxFormat = true;
49-
$xlBook = new \ExcelBook('<YOUR_LICENSE_NAME>', '<YOUR_LICENSE_KEY>', $useXlsxFormat);
50-
$xlBook->setLocale('UTF-8');
51-
52-
// add sheet to work book
53-
$xlSheet1 = $xlBook->addSheet('Sheet1');
54-
55-
// create a small sample data set
56-
$dataset = [
57-
[1, 1500, 'John', 'Doe'],
58-
[2, 750, 'Jane', 'Doe']
59-
];
60-
61-
// write data set to sheet
62-
$row = 1;
63-
foreach($dataset as $item){
64-
$xlSheet1->writeRow($row, $item);
65-
$row++;
66-
}
67-
68-
// write sum formula under data set
69-
$col = 1;
70-
$xlSheet1->write($row, $col, '=SUM(B1:B3)');
71-
72-
// add second sheet to work book
73-
$xlSheet2 = $xlBook->addSheet('Sheet2');
74-
75-
// add a date with specific date format to second sheet
76-
$row = 1; $col = 0;
77-
$date = new \DateTime('2014-08-02');
78-
$dateFormat = new \ExcelFormat($xlBook);
79-
$dateFormat->numberFormat(\ExcelFormat::NUMFORMAT_DATE);
80-
$xlSheet2->write($row, $col, $date->getTimestamp(), $dateFormat, \ExcelFormat::AS_DATE);
81-
82-
// save workbook
83-
$xlBook->save('test.xlsx');
47+
``` php
48+
<?php
49+
50+
// init excel work book as xlsx
51+
$useXlsxFormat = true;
52+
$xlBook = new \ExcelBook('<YOUR_LICENSE_NAME>', '<YOUR_LICENSE_KEY>', $useXlsxFormat);
53+
$xlBook->setLocale('UTF-8');
54+
55+
// add sheet to work book
56+
$xlSheet1 = $xlBook->addSheet('Sheet1');
57+
58+
// create a small sample data set
59+
$dataset = [
60+
[1, 1500, 'John', 'Doe'],
61+
[2, 750, 'Jane', 'Doe']
62+
];
63+
64+
// write data set to sheet
65+
$row = 1;
66+
foreach($dataset as $item){
67+
$xlSheet1->writeRow($row, $item);
68+
$row++;
69+
}
70+
71+
// write sum formula under data set
72+
$col = 1;
73+
$xlSheet1->write($row, $col, '=SUM(B1:B3)');
74+
75+
// add second sheet to work book
76+
$xlSheet2 = $xlBook->addSheet('Sheet2');
77+
78+
// add a date with specific date format to second sheet
79+
$row = 1; $col = 0;
80+
$date = new \DateTime('2014-08-02');
81+
$dateFormat = new \ExcelFormat($xlBook);
82+
$dateFormat->numberFormat(\ExcelFormat::NUMFORMAT_DATE);
83+
$xlSheet2->write($row, $col, $date->getTimestamp(), $dateFormat, \ExcelFormat::AS_DATE);
84+
85+
// save workbook
86+
$xlBook->save('test.xlsx');
87+
```
8488

8589
## optional php.ini settings
8690

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

91-
; optional settings for excel extension
92-
[excel]
93-
excel.license_name="<YOUR_LICENSE_NAME>"
94-
excel.license_key="<YOUR_LICENSE_KEY>"
95-
excel.skip_empty=0
95+
``` ini
96+
; optional settings for excel extension
97+
[excel]
98+
excel.license_name="<YOUR_LICENSE_NAME>"
99+
excel.license_key="<YOUR_LICENSE_KEY>"
100+
excel.skip_empty=0
101+
```
96102

97103
## Known Issues
98104

excel.c

+12-1
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@ EXCEL_METHOD(Book, save)
479479
}
480480

481481
if ((numbytes = php_stream_write(stream, contents, len)) != len) {
482+
php_stream_close(stream);
482483
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Only %d of %d bytes written, possibly out of free disk space", numbytes, len);
483484
RETURN_FALSE;
484485
}
@@ -2251,6 +2252,7 @@ EXCEL_METHOD(Sheet, readRow)
22512252
if (!php_excel_read_cell(row, lc, value, sheet, book, &format, read_formula)) {
22522253
zval_ptr_dtor(&value);
22532254
zval_dtor(return_value);
2255+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to read cell in row %ld, column %d with error '%s'", row, lc, xlBookErrorMessage(book));
22542256
RETURN_FALSE;
22552257
} else {
22562258
add_next_index_zval(return_value, value);
@@ -2311,6 +2313,7 @@ EXCEL_METHOD(Sheet, readCol)
23112313
if (!php_excel_read_cell(lc, col, value, sheet, book, &format, read_formula)) {
23122314
zval_ptr_dtor(&value);
23132315
zval_dtor(return_value);
2316+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to read cell in row %d, column %ld with error '%s'", lc, col, xlBookErrorMessage(book));
23142317
RETURN_FALSE;
23152318
} else {
23162319
add_next_index_zval(return_value, value);
@@ -2345,6 +2348,7 @@ EXCEL_METHOD(Sheet, read)
23452348
}
23462349

23472350
if (!php_excel_read_cell(row, col, return_value, sheet, book, &format, read_formula)) {
2351+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to read cell in row %ld, column %ld with error '%s'", row, col, xlBookErrorMessage(book));
23482352
RETURN_FALSE;
23492353
}
23502354

@@ -2447,7 +2451,12 @@ EXCEL_METHOD(Sheet, write)
24472451
FORMAT_FROM_OBJECT(format, oformat);
24482452
}
24492453

2450-
RETURN_BOOL(php_excel_write_cell(sheet, book, row, col, data, oformat ? format : 0, dtype TSRMLS_CC));
2454+
if (!php_excel_write_cell(sheet, book, row, col, data, oformat ? format : 0, dtype TSRMLS_CC)) {
2455+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to write cell in row %ld, column %ld with error '%s'", row, col, xlBookErrorMessage(book));
2456+
RETURN_FALSE;
2457+
}
2458+
2459+
RETURN_TRUE;
24512460
}
24522461
/* }}} */
24532462

@@ -2492,6 +2501,7 @@ EXCEL_METHOD(Sheet, writeRow)
24922501
zend_hash_move_forward_ex(Z_ARRVAL_P(data), &pos)) {
24932502

24942503
if (!php_excel_write_cell(sheet, book, row, i++, *element, oformat ? format : 0, -1 TSRMLS_CC)) {
2504+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to write cell in row %ld, column %ld with error '%s'", row, i-1, xlBookErrorMessage(book));
24952505
RETURN_FALSE;
24962506
}
24972507
}
@@ -2542,6 +2552,7 @@ EXCEL_METHOD(Sheet, writeCol)
25422552
zend_hash_move_forward_ex(Z_ARRVAL_P(data), &pos)) {
25432553

25442554
if (!php_excel_write_cell(sheet, book, i++, col, *element, oformat ? format : 0, dtype TSRMLS_CC)) {
2555+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to write cell in row %ld, column %ld with error '%s'", i-1, col, xlBookErrorMessage(book));
25452556
RETURN_FALSE;
25462557
}
25472558
}

0 commit comments

Comments
 (0)