Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setTabColor Method to Set Worksheet Tab Colors #542

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions kernel/excel.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ ZEND_BEGIN_ARG_INFO_EX(xls_file_name_arginfo, 0, 0, 1)
ZEND_ARG_INFO(0, sheet_name)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(xls_set_tab_color_arginfo, 0, 0, 1)
ZEND_ARG_INFO(0, color)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(xls_const_memory_arginfo, 0, 0, 1)
ZEND_ARG_INFO(0, file_name)
ZEND_ARG_INFO(0, sheet_name)
Expand Down Expand Up @@ -1771,6 +1775,26 @@ PHP_METHOD(vtiful_xls, nextCellCallback)
}
/* }}} */

/** {{{ \Vtiful\Kernel\Excel::setTabColor(int $color)
*/
PHP_METHOD(vtiful_xls, setTabColor)
{
zend_long color;

ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_LONG(color)
ZEND_PARSE_PARAMETERS_END();

ZVAL_COPY(return_value, getThis());

xls_object *obj = Z_XLS_P(getThis());

WORKBOOK_NOT_INITIALIZED(obj);

worksheet_set_tab_color(obj->write_ptr.worksheet, (lxw_color_t)color);
}
/* }}} */

#endif

/** {{{ xls_methods
Expand All @@ -1779,6 +1803,7 @@ zend_function_entry xls_methods[] = {
PHP_ME(vtiful_xls, __construct, xls_construct_arginfo, ZEND_ACC_PUBLIC)
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, setTabColor, xls_set_tab_color_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)
Expand Down Expand Up @@ -1921,6 +1946,23 @@ VTIFUL_STARTUP_FUNCTION(excel) {
REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, V_XLS_CONST_READ_TYPE_STRING, READ_TYPE_STRING);
REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, V_XLS_CONST_READ_TYPE_DATETIME, READ_TYPE_DATETIME);

REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "COLOR_BLACK", LXW_COLOR_BLACK);
REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "COLOR_BLUE", LXW_COLOR_BLUE);
REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "COLOR_BROWN", LXW_COLOR_BROWN);
REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "COLOR_CYAN", LXW_COLOR_CYAN);
REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "COLOR_GRAY", LXW_COLOR_GRAY);
REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "COLOR_GREEN", LXW_COLOR_GREEN);
REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "COLOR_LIME", LXW_COLOR_LIME);
REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "COLOR_MAGENTA", LXW_COLOR_MAGENTA);
REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "COLOR_NAVY", LXW_COLOR_NAVY);
REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "COLOR_ORANGE", LXW_COLOR_ORANGE);
REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "COLOR_PINK", LXW_COLOR_PINK);
REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "COLOR_PURPLE", LXW_COLOR_PURPLE);
REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "COLOR_RED", LXW_COLOR_RED);
REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "COLOR_SILVER", LXW_COLOR_SILVER);
REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "COLOR_WHITE", LXW_COLOR_WHITE);
REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "COLOR_YELLOW", LXW_COLOR_YELLOW);

return SUCCESS;
}
/* }}} */
Expand Down
26 changes: 26 additions & 0 deletions tests/set_tab_color.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--TEST--
Test setTabColor method
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);

$filePath = $excel->fileName("set_tab_color_test.xlsx", 'Sheet1')
->setTabColor(\Vtiful\Kernel\Excel::COLOR_RED)
->data([
['Name', 'Age'],
['Alice', 30],
['Bob', 25],
])
->output();

var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/set_tab_color_test.xlsx');
?>
--EXPECT--
string(31) "./tests/set_tab_color_test.xlsx"