Skip to content

Commit 1bda0f4

Browse files
committed
Merge pull request #111 from johmue/isLicensed
added ExcelSheet::isLicensed() method
2 parents 5a5b314 + a055077 commit 1bda0f4

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed

ChangeLog

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- ExcelSheet::rowHidden()
66
- ExcelSheet::setColHidden()
77
- ExcelSheet::setRowHidden()
8+
- ExcelSheet::isLicensed()
89
* Added new methods (requires LibXL 3.6.0)
910
- ExcelSheet::hyperlinkSize()
1011
- ExcelSheet::hyperlink()

docs/ExcelSheet.php

+9
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,15 @@ public function isHidden()
580580
{
581581
} //isHidden
582582

583+
/**
584+
* Returns whether LibXL runs in trial or licensed mode
585+
*
586+
* @return bool
587+
*/
588+
public function isLicensed()
589+
{
590+
} //isLicensed
591+
583592
/**
584593
* Returns the header margin (in inches)
585594
*

excel.c

+33
Original file line numberDiff line numberDiff line change
@@ -4529,6 +4529,34 @@ EXCEL_METHOD(Sheet, setColHidden)
45294529
}
45304530
/* }}} */
45314531

4532+
/* {{{ proto bool ExcelSheet::isLicensed()
4533+
Get license status */
4534+
EXCEL_METHOD(Sheet, isLicensed)
4535+
{
4536+
char *err;
4537+
zval *object = getThis();
4538+
SheetHandle sheet;
4539+
BookHandle book;
4540+
4541+
SHEET_AND_BOOK_FROM_OBJECT(sheet, book, object);
4542+
4543+
xlSheetCellFormat(sheet, 0, 0);
4544+
err = (char *)xlBookErrorMessage(book);
4545+
if (err) {
4546+
// on Linux
4547+
if (!strcmp(err, "can't get access to format in row 0 in trial version")) {
4548+
RETURN_FALSE;
4549+
}
4550+
// on Win
4551+
if (!strcmp(err, "can't access row 0 in trial version")) {
4552+
RETURN_FALSE;
4553+
}
4554+
}
4555+
4556+
RETURN_TRUE;
4557+
}
4558+
/* }}} */
4559+
45324560
/* {{{ proto long ExcelBook::sheetType(int sheet)
45334561
Returns type of sheet with specified index. */
45344562
EXCEL_METHOD(Book, sheetType)
@@ -5625,6 +5653,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_setRowHidden, 0, 0, 2)
56255653
ZEND_END_ARG_INFO()
56265654
#endif
56275655

5656+
PHP_EXCEL_ARGINFO
5657+
ZEND_BEGIN_ARG_INFO_EX(arginfo_Sheet_isLicensed, 0, 0, 0)
5658+
ZEND_END_ARG_INFO()
5659+
56285660
#define EXCEL_ME(class_name, function_name, arg_info, flags) \
56295661
PHP_ME( Excel ## class_name, function_name, arg_info, flags)
56305662

@@ -5818,6 +5850,7 @@ zend_function_entry excel_funcs_sheet[] = {
58185850
EXCEL_ME(Sheet, setColHidden, arginfo_Sheet_setColHidden, 0)
58195851
EXCEL_ME(Sheet, setRowHidden, arginfo_Sheet_setRowHidden, 0)
58205852
#endif
5853+
EXCEL_ME(Sheet, isLicensed, arginfo_Sheet_isLicensed, 0)
58215854
{NULL, NULL, NULL}
58225855
};
58235856

tests/086.phpt

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
test Sheet::isLicensed()
3+
--SKIPIF--
4+
<?php if (!extension_loaded("excel")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
8+
// requires correct php.ini settings
9+
// excel.license_name="<NAME>" and excel.license_key="<KEY>"
10+
$book = new ExcelBook();
11+
$sheet = $book->addSheet("Sheet1");
12+
var_dump(
13+
$sheet->isLicensed()
14+
);
15+
16+
$book = new ExcelBook('x', 'y');
17+
$sheet = $book->addSheet("Sheet1");
18+
var_dump(
19+
$sheet->isLicensed()
20+
);
21+
22+
?>
23+
--EXPECT--
24+
bool(true)
25+
bool(false)

0 commit comments

Comments
 (0)