Skip to content

Commit d731591

Browse files
authored
Merge pull request #335 from viest/dev
Feat: sheet hide and first
2 parents a6c1562 + d64ee72 commit d731591

File tree

8 files changed

+183
-5
lines changed

8 files changed

+183
-5
lines changed

include/xlswriter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ STATIC void _populate_range(lxw_workbook *self, lxw_series_range *range);
222222
STATIC void _populate_range_dimensions(lxw_workbook *self, lxw_series_range *range);
223223

224224
void comment_show(xls_resource_write_t *res);
225+
void hide_worksheet(xls_resource_write_t *res);
226+
void first_worksheet(xls_resource_write_t *res);
225227
void zoom(xls_resource_write_t *res, zend_long zoom);
226228
void gridlines(xls_resource_write_t *res, zend_long option);
227229
void auto_filter(zend_string *range, xls_resource_write_t *res);

kernel/excel.c

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,12 @@ ZEND_END_ARG_INFO()
272272

273273
ZEND_BEGIN_ARG_INFO_EX(xls_set_printed_landscape_arginfo, 0, 0, 0)
274274
ZEND_END_ARG_INFO()
275+
276+
ZEND_BEGIN_ARG_INFO_EX(xls_hide_sheet_arginfo, 0, 0, 0)
277+
ZEND_END_ARG_INFO()
278+
279+
ZEND_BEGIN_ARG_INFO_EX(xls_first_sheet_arginfo, 0, 0, 0)
280+
ZEND_END_ARG_INFO()
275281
/* }}} */
276282

277283
/** {{{ \Vtiful\Kernel\Excel::__construct(array $config)
@@ -1138,6 +1144,34 @@ PHP_METHOD(vtiful_xls, setPrintedLandscape)
11381144
}
11391145
/* }}} */
11401146

1147+
/** {{{ \Vtiful\Kernel\Excel::setCurrentSheetHide()
1148+
*/
1149+
PHP_METHOD(vtiful_xls, setCurrentSheetHide)
1150+
{
1151+
ZVAL_COPY(return_value, getThis());
1152+
1153+
xls_object* obj = Z_XLS_P(getThis());
1154+
1155+
WORKBOOK_NOT_INITIALIZED(obj);
1156+
1157+
hide_worksheet(&obj->write_ptr);
1158+
}
1159+
/* }}} */
1160+
1161+
/** {{{ \Vtiful\Kernel\Excel::setCurrentSheetIsFirst()
1162+
*/
1163+
PHP_METHOD(vtiful_xls, setCurrentSheetIsFirst)
1164+
{
1165+
ZVAL_COPY(return_value, getThis());
1166+
1167+
xls_object* obj = Z_XLS_P(getThis());
1168+
1169+
WORKBOOK_NOT_INITIALIZED(obj);
1170+
1171+
first_worksheet(&obj->write_ptr);
1172+
}
1173+
/* }}} */
1174+
11411175
#ifdef ENABLE_READER
11421176

11431177
/** {{{ \Vtiful\Kernel\Excel::openFile()
@@ -1467,13 +1501,16 @@ zend_function_entry xls_methods[] = {
14671501
PHP_ME(vtiful_xls, zoom, xls_sheet_zoom_arginfo, ZEND_ACC_PUBLIC)
14681502
PHP_ME(vtiful_xls, gridline, xls_sheet_gridline_arginfo, ZEND_ACC_PUBLIC)
14691503

1504+
PHP_ME(vtiful_xls, setPrintedPortrait, xls_set_printed_portrait_arginfo, ZEND_ACC_PUBLIC)
1505+
PHP_ME(vtiful_xls, setPrintedLandscape, xls_set_printed_landscape_arginfo, ZEND_ACC_PUBLIC)
1506+
1507+
PHP_ME(vtiful_xls, setCurrentSheetHide, xls_hide_sheet_arginfo, ZEND_ACC_PUBLIC)
1508+
PHP_ME(vtiful_xls, setCurrentSheetIsFirst, xls_first_sheet_arginfo, ZEND_ACC_PUBLIC)
1509+
14701510
PHP_ME(vtiful_xls, columnIndexFromString, xls_index_to_string, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
14711511
PHP_ME(vtiful_xls, stringFromColumnIndex, xls_string_to_index, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
14721512
PHP_ME(vtiful_xls, timestampFromDateDouble, xls_string_to_index, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
14731513

1474-
PHP_ME(vtiful_xls, setPrintedPortrait, xls_set_printed_portrait_arginfo, ZEND_ACC_PUBLIC)
1475-
PHP_ME(vtiful_xls, setPrintedLandscape, xls_set_printed_landscape_arginfo, ZEND_ACC_PUBLIC)
1476-
14771514
#ifdef ENABLE_READER
14781515
PHP_ME(vtiful_xls, openFile, xls_open_file_arginfo, ZEND_ACC_PUBLIC)
14791516
PHP_ME(vtiful_xls, openSheet, xls_open_sheet_arginfo, ZEND_ACC_PUBLIC)

kernel/write.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,22 @@ void printed_direction(xls_resource_write_t *res, unsigned int direction)
363363
worksheet_set_landscape(res->worksheet);
364364
}
365365

366+
/*
367+
* Hide worksheet
368+
*/
369+
void hide_worksheet(xls_resource_write_t *res)
370+
{
371+
worksheet_hide(res->worksheet);
372+
}
373+
374+
/*
375+
* First worksheet
376+
*/
377+
void first_worksheet(xls_resource_write_t *res)
378+
{
379+
worksheet_set_first_sheet(res->worksheet);
380+
}
381+
366382
/*
367383
* Call finalization code and close file.
368384
*/

php_xlswriter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ extern zend_module_entry xlswriter_module_entry;
1919
#define phpext_xlswriter_ptr &xlswriter_module_entry
2020

2121
#define PHP_XLSWRITER_VERSION "1.3.7"
22+
#define PHP_XLSWRITER_AUTHOR "Jiexing.Wang ([email protected])"
2223

2324
#ifdef PHP_WIN32
2425
# define PHP_VTIFUL_API __declspec(dllexport)

tests/first.phpt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
--TEST--
2+
Check for vtiful presence
3+
--SKIPIF--
4+
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
try {
8+
$config = ['path' => './tests'];
9+
$excel = new \Vtiful\Kernel\Excel($config);
10+
11+
$excel->setCurrentSheetHide();
12+
} catch (\Exception $exception) {
13+
var_dump($exception->getCode());
14+
var_dump($exception->getMessage());
15+
}
16+
17+
$config = ['path' => './tests'];
18+
$excel = new \Vtiful\Kernel\Excel($config);
19+
20+
$excel->fileName('first.xlsx', 'sheet1')
21+
->addSheet('sheet2')
22+
->setCurrentSheetIsFirst()
23+
->output();
24+
25+
var_dump($excel);
26+
?>
27+
--CLEAN--
28+
<?php
29+
@unlink(__DIR__ . '/first.xlsx');
30+
?>
31+
--EXPECT--
32+
int(130)
33+
string(51) "Please create a file first, use the filename method"
34+
object(Vtiful\Kernel\Excel)#3 (3) {
35+
["config":"Vtiful\Kernel\Excel":private]=>
36+
array(1) {
37+
["path"]=>
38+
string(7) "./tests"
39+
}
40+
["fileName":"Vtiful\Kernel\Excel":private]=>
41+
string(18) "./tests/first.xlsx"
42+
["read_row_type":"Vtiful\Kernel\Excel":private]=>
43+
NULL
44+
}

tests/hide.phpt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
--TEST--
2+
Check for vtiful presence
3+
--SKIPIF--
4+
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
try {
8+
$config = ['path' => './tests'];
9+
$excel = new \Vtiful\Kernel\Excel($config);
10+
11+
$excel->setCurrentSheetHide();
12+
} catch (\Exception $exception) {
13+
var_dump($exception->getCode());
14+
var_dump($exception->getMessage());
15+
}
16+
17+
$config = ['path' => './tests'];
18+
$excel = new \Vtiful\Kernel\Excel($config);
19+
20+
$excel->fileName('hide.xlsx', 'sheet1')
21+
->addSheet('sheet2')
22+
->setCurrentSheetHide()
23+
->output();
24+
25+
var_dump($excel);
26+
?>
27+
--CLEAN--
28+
<?php
29+
@unlink(__DIR__ . '/hide.xlsx');
30+
?>
31+
--EXPECT--
32+
int(130)
33+
string(51) "Please create a file first, use the filename method"
34+
object(Vtiful\Kernel\Excel)#3 (3) {
35+
["config":"Vtiful\Kernel\Excel":private]=>
36+
array(1) {
37+
["path"]=>
38+
string(7) "./tests"
39+
}
40+
["fileName":"Vtiful\Kernel\Excel":private]=>
41+
string(17) "./tests/hide.xlsx"
42+
["read_row_type":"Vtiful\Kernel\Excel":private]=>
43+
NULL
44+
}

tests/version.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Check for vtiful presence
3+
--SKIPIF--
4+
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
var_dump(is_string(xlswriter_get_version()));
8+
var_dump(is_string(xlswriter_get_author()));
9+
?>
10+
--EXPECT--
11+
bool(true)
12+
bool(true)

xlswriter.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,28 @@
2525

2626
int le_xls_writer;
2727

28+
ZEND_BEGIN_ARG_INFO_EX(xlswriter_get_version_arginfo, 0, 0, 0)
29+
ZEND_END_ARG_INFO()
30+
31+
ZEND_BEGIN_ARG_INFO_EX(xlswriter_get_auther_arginfo, 0, 0, 0)
32+
ZEND_END_ARG_INFO()
33+
34+
/* {{{ xlswriter_get_version
35+
*/
36+
PHP_FUNCTION(xlswriter_get_version)
37+
{
38+
RETURN_STRINGL(PHP_XLSWRITER_VERSION, strlen(PHP_XLSWRITER_VERSION));
39+
}
40+
/* }}} */
41+
42+
/* {{{ xlswriter_get_author
43+
*/
44+
PHP_FUNCTION(xlswriter_get_author)
45+
{
46+
RETURN_STRINGL(PHP_XLSWRITER_AUTHOR, strlen(PHP_XLSWRITER_AUTHOR));
47+
}
48+
/* }}} */
49+
2850
/* {{{ PHP_MINIT_FUNCTION
2951
*/
3052
PHP_MINIT_FUNCTION(xlswriter)
@@ -40,7 +62,6 @@ PHP_MINIT_FUNCTION(xlswriter)
4062
}
4163
/* }}} */
4264

43-
4465
/* {{{ PHP_MSHUTDOWN_FUNCTION
4566
*/
4667
PHP_MSHUTDOWN_FUNCTION(xlswriter)
@@ -68,7 +89,6 @@ PHP_RSHUTDOWN_FUNCTION(xlswriter)
6889
}
6990
/* }}} */
7091

71-
7292
/* {{{ PHP_MINFO_FUNCTION
7393
*/
7494
PHP_MINFO_FUNCTION(xlswriter)
@@ -109,6 +129,8 @@ PHP_MINFO_FUNCTION(xlswriter)
109129
* Every user visible function must have an entry in xlswriter_functions[].
110130
*/
111131
const zend_function_entry xlswriter_functions[] = {
132+
PHP_FE(xlswriter_get_version, xlswriter_get_version_arginfo)
133+
PHP_FE(xlswriter_get_author, xlswriter_get_auther_arginfo)
112134
PHP_FE_END
113135
};
114136
/* }}} */

0 commit comments

Comments
 (0)