Skip to content

Commit

Permalink
Merge pull request #386 from viest/dev
Browse files Browse the repository at this point in the history
Feat: existSheet
  • Loading branch information
viest committed Jul 13, 2021
2 parents b90a197 + b79b791 commit e95a68a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
31 changes: 31 additions & 0 deletions kernel/excel.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ ZEND_BEGIN_ARG_INFO_EX(xls_file_add_sheet, 0, 0, 1)
ZEND_ARG_INFO(0, sheet_name)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(xls_file_exist_sheet, 0, 0, 1)
ZEND_ARG_INFO(0, sheet_name)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(xls_file_checkout_sheet, 0, 0, 1)
ZEND_ARG_INFO(0, sheet_name)
ZEND_END_ARG_INFO()
Expand Down Expand Up @@ -385,6 +389,32 @@ PHP_METHOD(vtiful_xls, addSheet)
}
/* }}} */

/** {{{ \Vtiful\Kernel\Excel::existSheet(string $sheetName)
*/
PHP_METHOD(vtiful_xls, existSheet)
{
char *sheet_name = NULL;
zend_string *zs_sheet_name = NULL;

ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STR(zs_sheet_name)
ZEND_PARSE_PARAMETERS_END();

xls_object *obj = Z_XLS_P(getThis());

WORKBOOK_NOT_INITIALIZED(obj);
SHEET_LINE_INIT(obj)

sheet_name = ZSTR_VAL(zs_sheet_name);

if (workbook_get_worksheet_by_name(obj->write_ptr.workbook, sheet_name)) {
RETURN_TRUE;
}

RETURN_FALSE;
}
/* }}} */

/** {{{ \Vtiful\Kernel\Excel::checkoutSheet(string $sheetName)
*/
PHP_METHOD(vtiful_xls, checkoutSheet)
Expand Down Expand Up @@ -1502,6 +1532,7 @@ zend_function_entry xls_methods[] = {
PHP_ME(vtiful_xls, close, xls_close_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(vtiful_xls, fileName, xls_file_name_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(vtiful_xls, addSheet, xls_file_add_sheet, ZEND_ACC_PUBLIC)
PHP_ME(vtiful_xls, existSheet, xls_file_exist_sheet, ZEND_ACC_PUBLIC)
PHP_ME(vtiful_xls, checkoutSheet, xls_file_checkout_sheet, ZEND_ACC_PUBLIC)
PHP_ME(vtiful_xls, activateSheet, xls_file_activate_sheet, ZEND_ACC_PUBLIC)
PHP_ME(vtiful_xls, constMemory, xls_const_memory_arginfo, ZEND_ACC_PUBLIC)
Expand Down
23 changes: 23 additions & 0 deletions tests/exist_sheet.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = ['path' => './tests'];

$fileObject = new \Vtiful\Kernel\Excel($config);

$fileObject->fileName('tutorial.xlsx')
->addSheet('twoSheet');

var_dump($fileObject->existSheet('twoSheet'));
var_dump($fileObject->existSheet('notFoundSheet'));
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/tutorial.xlsx');
?>
--EXPECT--
bool(true)
bool(false)

0 comments on commit e95a68a

Please sign in to comment.