Skip to content

Commit 238fbdf

Browse files
authored
Merge pull request #237 from viest/dev
Feat: header format
2 parents 1e81a68 + 58b4738 commit 238fbdf

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed

kernel/excel.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ ZEND_END_ARG_INFO()
9090

9191
ZEND_BEGIN_ARG_INFO_EX(xls_header_arginfo, 0, 0, 1)
9292
ZEND_ARG_INFO(0, header)
93+
ZEND_ARG_INFO(0, format_handle)
9394
ZEND_END_ARG_INFO()
9495

9596
ZEND_BEGIN_ARG_INFO_EX(xls_data_arginfo, 0, 0, 1)
@@ -402,10 +403,13 @@ PHP_METHOD(vtiful_xls, constMemory)
402403
PHP_METHOD(vtiful_xls, header)
403404
{
404405
zend_long header_l_key;
405-
zval *header = NULL, *header_value = NULL;
406+
lxw_format *format_handle = NULL;
407+
zval *header = NULL, *header_value = NULL, *zv_format_handle = NULL;;
406408

407-
ZEND_PARSE_PARAMETERS_START(1, 1)
409+
ZEND_PARSE_PARAMETERS_START(1, 2)
408410
Z_PARAM_ARRAY(header)
411+
Z_PARAM_OPTIONAL
412+
Z_PARAM_RESOURCE(zv_format_handle)
409413
ZEND_PARSE_PARAMETERS_END();
410414

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

415419
WORKBOOK_NOT_INITIALIZED(obj);
416420

421+
if (zv_format_handle == NULL) {
422+
format_handle = obj->format_ptr.format;
423+
} else {
424+
format_handle = zval_get_format(zv_format_handle);
425+
}
426+
417427
ZEND_HASH_FOREACH_NUM_KEY_VAL(Z_ARRVAL_P(header), header_l_key, header_value)
418-
type_writer(header_value, 0, header_l_key, &obj->write_ptr, NULL, obj->format_ptr.format);
428+
type_writer(header_value, 0, header_l_key, &obj->write_ptr, NULL, format_handle);
419429
ZEND_HASH_FOREACH_END();
420430

421431
SHEET_LINE_ADD(obj)
@@ -556,7 +566,11 @@ PHP_METHOD(vtiful_xls, insertDate)
556566
type_writer(&_zv_double_time, row, column, &obj->write_ptr, format, obj->format_ptr.format);
557567
}
558568

559-
zend_string_release(format);
569+
// Release default format
570+
if (ZEND_NUM_ARGS() == 3) {
571+
zend_string_release(format);
572+
}
573+
560574
zval_ptr_dtor(&_zv_double_time);
561575
}
562576
/* }}} */

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@
195195
<file md5sum="f9c233fedf10a2bbb2ac5534cf8f20ef" name="tests/format_wrap.phpt" role="test" />
196196
<file md5sum="4d46bc759ff8d41c8c919a0f50c595b0" name="tests/freeze_panes.phpt" role="test" />
197197
<file name="tests/gridlines.phpt" role="test" />
198+
<file name="tests/header_format.phpt" role="test" />
198199
<file md5sum="b4c6f2949c46ab89099e5f971f152a1f" name="tests/image_no_styles.phpt" role="test" />
199200
<file md5sum="fb81df82009c851b96a6124972ccc3d1" name="tests/image_width_height_styles.phpt" role="test" />
200201
<file md5sum="73521b6a1cb84ba3c7730470b836368f" name="tests/insert_date_custom_format.phpt" role="test" />

tests/header_format.phpt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
Check for vtiful presence
3+
--SKIPIF--
4+
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
$config = [
8+
'path' => './tests'
9+
];
10+
11+
$excel = new \Vtiful\Kernel\Excel($config);
12+
13+
$fileObject = $excel->fileName('tutorial.xlsx');
14+
$fileHandle = $fileObject->getHandle();
15+
16+
$format = new \Vtiful\Kernel\Format($fileHandle);
17+
$alignStyle = $format->align(
18+
\Vtiful\Kernel\Format::FORMAT_ALIGN_CENTER,
19+
\Vtiful\Kernel\Format::FORMAT_ALIGN_VERTICAL_CENTER
20+
)->toResource();
21+
22+
$setHeader = $fileObject
23+
->header(['Item', 'Cost'], $alignStyle)
24+
->output();
25+
26+
var_dump($setHeader);
27+
?>
28+
--EXPECT--
29+
string(21) "./tests/tutorial.xlsx"

0 commit comments

Comments
 (0)