Skip to content

Commit

Permalink
Merge pull request #237 from viest/dev
Browse files Browse the repository at this point in the history
Feat: header format
  • Loading branch information
viest authored Mar 19, 2020
2 parents 1e81a68 + 58b4738 commit 238fbdf
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
22 changes: 18 additions & 4 deletions kernel/excel.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(xls_header_arginfo, 0, 0, 1)
ZEND_ARG_INFO(0, header)
ZEND_ARG_INFO(0, format_handle)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(xls_data_arginfo, 0, 0, 1)
Expand Down Expand Up @@ -402,10 +403,13 @@ PHP_METHOD(vtiful_xls, constMemory)
PHP_METHOD(vtiful_xls, header)
{
zend_long header_l_key;
zval *header = NULL, *header_value = NULL;
lxw_format *format_handle = NULL;
zval *header = NULL, *header_value = NULL, *zv_format_handle = NULL;;

ZEND_PARSE_PARAMETERS_START(1, 1)
ZEND_PARSE_PARAMETERS_START(1, 2)
Z_PARAM_ARRAY(header)
Z_PARAM_OPTIONAL
Z_PARAM_RESOURCE(zv_format_handle)
ZEND_PARSE_PARAMETERS_END();

ZVAL_COPY(return_value, getThis());
Expand All @@ -414,8 +418,14 @@ PHP_METHOD(vtiful_xls, header)

WORKBOOK_NOT_INITIALIZED(obj);

if (zv_format_handle == NULL) {
format_handle = obj->format_ptr.format;
} else {
format_handle = zval_get_format(zv_format_handle);
}

ZEND_HASH_FOREACH_NUM_KEY_VAL(Z_ARRVAL_P(header), header_l_key, header_value)
type_writer(header_value, 0, header_l_key, &obj->write_ptr, NULL, obj->format_ptr.format);
type_writer(header_value, 0, header_l_key, &obj->write_ptr, NULL, format_handle);
ZEND_HASH_FOREACH_END();

SHEET_LINE_ADD(obj)
Expand Down Expand Up @@ -556,7 +566,11 @@ PHP_METHOD(vtiful_xls, insertDate)
type_writer(&_zv_double_time, row, column, &obj->write_ptr, format, obj->format_ptr.format);
}

zend_string_release(format);
// Release default format
if (ZEND_NUM_ARGS() == 3) {
zend_string_release(format);
}

zval_ptr_dtor(&_zv_double_time);
}
/* }}} */
Expand Down
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@
<file md5sum="f9c233fedf10a2bbb2ac5534cf8f20ef" name="tests/format_wrap.phpt" role="test" />
<file md5sum="4d46bc759ff8d41c8c919a0f50c595b0" name="tests/freeze_panes.phpt" role="test" />
<file name="tests/gridlines.phpt" role="test" />
<file name="tests/header_format.phpt" role="test" />
<file md5sum="b4c6f2949c46ab89099e5f971f152a1f" name="tests/image_no_styles.phpt" role="test" />
<file md5sum="fb81df82009c851b96a6124972ccc3d1" name="tests/image_width_height_styles.phpt" role="test" />
<file md5sum="73521b6a1cb84ba3c7730470b836368f" name="tests/insert_date_custom_format.phpt" role="test" />
Expand Down
29 changes: 29 additions & 0 deletions tests/header_format.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = [
'path' => './tests'
];

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

$fileObject = $excel->fileName('tutorial.xlsx');
$fileHandle = $fileObject->getHandle();

$format = new \Vtiful\Kernel\Format($fileHandle);
$alignStyle = $format->align(
\Vtiful\Kernel\Format::FORMAT_ALIGN_CENTER,
\Vtiful\Kernel\Format::FORMAT_ALIGN_VERTICAL_CENTER
)->toResource();

$setHeader = $fileObject
->header(['Item', 'Cost'], $alignStyle)
->output();

var_dump($setHeader);
?>
--EXPECT--
string(21) "./tests/tutorial.xlsx"

0 comments on commit 238fbdf

Please sign in to comment.