瀏覽代碼

Feat: header format

viest 5 年之前
父節點
當前提交
9b75ab853b
共有 3 個文件被更改,包括 43 次插入3 次删除
  1. 13 3
      kernel/excel.c
  2. 1 0
      package.xml
  3. 29 0
      tests/header_format.phpt

+ 13 - 3
kernel/excel.c

@@ -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)
@@ -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());
@@ -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)

+ 1 - 0
package.xml

@@ -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" />

+ 29 - 0
tests/header_format.phpt

@@ -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--
+./tests/tutorial.xlsx