Skip to content

Commit 28ee386

Browse files
authored
Merge pull request #63 from viest/dev
FEAT(Sheet): new sheet
2 parents 84b6491 + 548b258 commit 28ee386

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed

kernel/excel.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ ZEND_BEGIN_ARG_INFO_EX(xls_file_name_arginfo, 0, 0, 1)
6363
ZEND_ARG_INFO(0, file_name)
6464
ZEND_END_ARG_INFO()
6565

66+
ZEND_BEGIN_ARG_INFO_EX(xls_file_add_sheet, 0, 0, 1)
67+
ZEND_ARG_INFO(0, sheet_name)
68+
ZEND_END_ARG_INFO()
69+
6670
ZEND_BEGIN_ARG_INFO_EX(xls_header_arginfo, 0, 0, 1)
6771
ZEND_ARG_INFO(0, header)
6872
ZEND_END_ARG_INFO()
@@ -168,6 +172,35 @@ PHP_METHOD(vtiful_xls, fileName)
168172
}
169173
/* }}} */
170174

175+
/** {{{ \Vtiful\Kernel\xls::addSheet(string $sheetName)
176+
*/
177+
PHP_METHOD(vtiful_xls, addSheet)
178+
{
179+
zend_string *zs_sheet_name = NULL;
180+
char *sheet_name = NULL;
181+
182+
ZEND_PARSE_PARAMETERS_START(0, 1)
183+
Z_PARAM_OPTIONAL
184+
Z_PARAM_STR(zs_sheet_name)
185+
ZEND_PARSE_PARAMETERS_END();
186+
187+
ZVAL_COPY(return_value, getThis());
188+
189+
xls_object *obj = Z_XLS_P(getThis());
190+
191+
if(obj->ptr.workbook == NULL) {
192+
zend_throw_exception(vtiful_exception_ce, "Please create a file first, use the filename method", 130);
193+
return;
194+
}
195+
196+
if(zs_sheet_name != NULL) {
197+
sheet_name = ZSTR_VAL(zs_sheet_name);
198+
}
199+
200+
obj->ptr.worksheet = workbook_add_worksheet(obj->ptr.workbook, sheet_name);
201+
}
202+
/* }}} */
203+
171204
/** {{{ \Vtiful\Kernel\xls::constMemory(string $fileName)
172205
*/
173206
PHP_METHOD(vtiful_xls, constMemory)
@@ -448,6 +481,7 @@ PHP_METHOD(vtiful_xls, setRow)
448481
zend_function_entry xls_methods[] = {
449482
PHP_ME(vtiful_xls, __construct, xls_construct_arginfo, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
450483
PHP_ME(vtiful_xls, fileName, xls_file_name_arginfo, ZEND_ACC_PUBLIC)
484+
PHP_ME(vtiful_xls, addSheet, xls_file_add_sheet, ZEND_ACC_PUBLIC)
451485
PHP_ME(vtiful_xls, constMemory, xls_file_name_arginfo, ZEND_ACC_PUBLIC)
452486
PHP_ME(vtiful_xls, header, xls_header_arginfo, ZEND_ACC_PUBLIC)
453487
PHP_ME(vtiful_xls, data, xls_data_arginfo, ZEND_ACC_PUBLIC)

kernel/include.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ typedef struct {
3636

3737
typedef struct _vtiful_xls_object {
3838
xls_resource_t ptr;
39-
zend_object zo;
39+
zend_object zo;
4040
} xls_object;
4141

4242
static inline xls_object *php_vtiful_xls_fetch_object(zend_object *obj) {

tests/017.phpt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
Check for vtiful presence
3+
--SKIPIF--
4+
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
$config = ['path' => './tests'];
8+
$excel = new \Vtiful\Kernel\Excel($config);
9+
10+
$fileObject = $excel->fileName("tutorial01.xlsx");
11+
12+
$fileObject->header(['name', 'age'])
13+
->data([['viest', 21]]);
14+
15+
$fileObject->addSheet('twoSheet')
16+
->header(['name', 'age'])
17+
->data([['vikin', 22]]);
18+
19+
$filePath = $fileObject->output();
20+
21+
var_dump($filePath);
22+
?>
23+
--CLEAN--
24+
<?php
25+
@unlink(__DIR__ . '/tutorial01.xlsx');
26+
?>
27+
--EXPECT--
28+
string(23) "./tests/tutorial01.xlsx"

0 commit comments

Comments
 (0)