浏览代码

Merge pull request #19 from viest/dev

merge cells
王杰新 7 年之前
父节点
当前提交
d965f12453
共有 3 个文件被更改,包括 42 次插入0 次删除
  1. 33 0
      kernel/excel.c
  2. 8 0
      kernel/write.c
  3. 1 0
      kernel/write.h

+ 33 - 0
kernel/excel.c

@@ -66,6 +66,11 @@ ZEND_END_ARG_INFO()
 ZEND_BEGIN_ARG_INFO_EX(excel_auto_filter_arginfo, 0, 0, 1)
                 ZEND_ARG_INFO(0, range)
 ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(excel_merge_cells_arginfo, 0, 0, 2)
+                ZEND_ARG_INFO(0, range)
+                ZEND_ARG_INFO(0, data)
+ZEND_END_ARG_INFO()
 /* }}} */
 
 /* {{{ */
@@ -354,6 +359,33 @@ PHP_METHOD(vtiful_excel, autoFilter)
 }
 /* }}} */
 
+/** {{{ \Vtiful\Kernel\Excel::mergeCells(string $range, string $data)
+ */
+PHP_METHOD(vtiful_excel, mergeCells)
+{
+    zval rv, res_handle;
+    zval *attr_handle;
+    zend_string *range, *data;
+    excel_resource_t *res;
+
+    ZEND_PARSE_PARAMETERS_START(2, 2)
+            Z_PARAM_STR(range)
+            Z_PARAM_STR(data)
+    ZEND_PARSE_PARAMETERS_END();
+
+    ZVAL_COPY(return_value, getThis());
+
+    attr_handle = zend_read_property(vtiful_excel_ce, return_value, ZEND_STRL(V_EXCEL_HANDLE), 0, &rv TSRMLS_DC);
+    res = zval_get_resource(attr_handle);
+
+    merge_cells(range, data, res);
+
+    ZVAL_RES(&res_handle, zend_register_resource(res, le_excel_writer));
+    zend_update_property(vtiful_excel_ce, return_value, ZEND_STRL(V_EXCEL_HANDLE), &res_handle);
+}
+/* }}} */
+
+
 /** {{{ excel_methods
 */
 zend_function_entry excel_methods[] = {
@@ -367,6 +399,7 @@ zend_function_entry excel_methods[] = {
         PHP_ME(vtiful_excel, insertText,    excel_insert_text_arginfo,    ZEND_ACC_PUBLIC)
         PHP_ME(vtiful_excel, insertImage,   excel_insert_image_arginfo,   ZEND_ACC_PUBLIC)
         PHP_ME(vtiful_excel, insertFormula, excel_insert_formula_arginfo, ZEND_ACC_PUBLIC)
+        PHP_ME(vtiful_excel, mergeCells,    excel_merge_cells_arginfo,    ZEND_ACC_PUBLIC)
         PHP_FE_END
 };
 /* }}} */

+ 8 - 0
kernel/write.c

@@ -72,6 +72,14 @@ void auto_filter(zend_string *range, excel_resource_t *res)
     worksheet_autofilter(res->worksheet, RANGE(ZSTR_VAL(range)));
 }
 
+/*
+ * Merge cells.
+ */
+void merge_cells(zend_string *range, zend_string *value, excel_resource_t *res)
+{
+    worksheet_merge_range(res->worksheet, RANGE(ZSTR_VAL(range)), ZSTR_VAL(value), NULL);
+}
+
 /*
  * Call finalization code and close file.
  */

+ 1 - 0
kernel/write.h

@@ -26,6 +26,7 @@ void type_writer(zval *value, zend_long row, zend_long columns, excel_resource_t
 void image_writer(zval *value, zend_long row, zend_long columns, excel_resource_t *res);
 void formula_writer(zval *value, zend_long row, zend_long columns, excel_resource_t *res);
 void auto_filter(zend_string *range, excel_resource_t *res);
+void merge_cells(zend_string *range, zend_string *value, excel_resource_t *res);
 lxw_error workbook_file(excel_resource_t *self, zval *handle);
 
 #endif