瀏覽代碼

FEAT(set_row): Set row format

viest 7 年之前
父節點
當前提交
b3e2bc0ca5
共有 3 個文件被更改,包括 53 次插入1 次删除
  1. 37 0
      kernel/excel.c
  2. 4 0
      kernel/include.h
  3. 12 1
      kernel/write.c

+ 37 - 0
kernel/excel.c

@@ -69,6 +69,12 @@ ZEND_BEGIN_ARG_INFO_EX(excel_set_column_arginfo, 0, 0, 3)
                 ZEND_ARG_INFO(0, range)
                 ZEND_ARG_INFO(0, width)
 ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(excel_set_row_arginfo, 0, 0, 3)
+                ZEND_ARG_INFO(0, format_handle)
+                ZEND_ARG_INFO(0, range)
+                ZEND_ARG_INFO(0, height)
+ZEND_END_ARG_INFO()
 /* }}} */
 
 /** {{{ \Vtiful\Kernel\Excel::__construct(array $config)
@@ -370,6 +376,36 @@ PHP_METHOD(vtiful_excel, setColumn)
 }
 /* }}} */
 
+/** {{{ \Vtiful\Kernel\Excel::setRow(resource $format, string $range [, int $heitght])
+ */
+PHP_METHOD(vtiful_excel, setRow)
+{
+    zval *format_handle, res_handle;
+    zend_string *range;
+
+    double height = 0;
+    int    argc  = ZEND_NUM_ARGS();
+
+    ZEND_PARSE_PARAMETERS_START(2, 3)
+            Z_PARAM_RESOURCE(format_handle)
+            Z_PARAM_STR(range)
+            Z_PARAM_OPTIONAL
+            Z_PARAM_DOUBLE(height)
+    ZEND_PARSE_PARAMETERS_END();
+
+    ZVAL_COPY(return_value, getThis());
+
+    if (argc == 2) {
+        height = 18;
+    }
+
+    set_row(range, height, excel_res, zval_get_format(format_handle));
+
+    ZVAL_RES(&res_handle, zend_register_resource(excel_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[] = {
@@ -385,6 +421,7 @@ zend_function_entry excel_methods[] = {
         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_ME(vtiful_excel, setColumn,     excel_set_column_arginfo,     ZEND_ACC_PUBLIC)
+        PHP_ME(vtiful_excel, setRow,        excel_set_row_arginfo,        ZEND_ACC_PUBLIC)
         PHP_FE_END
 };
 /* }}} */

+ 4 - 0
kernel/include.h

@@ -20,6 +20,9 @@
 #define REGISTER_CLASS_CONST_LONG(class_name, const_name, value) \
     zend_declare_class_constant_long(class_name, const_name, sizeof(const_name)-1, (zend_long)value);
 
+#define ROW(range) \
+    lxw_name_to_row(range)
+
 typedef struct {
     lxw_workbook *workbook;
     lxw_worksheet *worksheet;
@@ -46,6 +49,7 @@ void formula_writer(zval *value, zend_long row, zend_long columns, excel_resourc
 void auto_filter(zend_string *range, excel_resource_t *res);
 void merge_cells(zend_string *range, zend_string *value, excel_resource_t *res);
 void set_column(zend_string *range, double width, excel_resource_t *res, lxw_format *format);
+void set_row(zend_string *range, double height, excel_resource_t *res, lxw_format *format);
 lxw_error workbook_file(excel_resource_t *self, zval *handle);
 
 #endif

+ 12 - 1
kernel/write.c

@@ -76,9 +76,20 @@ 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);
 }
 
+/*
+ * Set column format
+ */
 void set_column(zend_string *range, double width, excel_resource_t *res, lxw_format *format)
 {
-    worksheet_set_column(res->worksheet, COLS(ZSTR_VAL(range)), (double)width, format);
+    worksheet_set_column(res->worksheet, COLS(ZSTR_VAL(range)), width, format);
+}
+
+/*
+ * Set row format
+ */
+void set_row(zend_string *range, double height, excel_resource_t *res, lxw_format *format)
+{
+    worksheet_set_row(res->worksheet, ROW(ZSTR_VAL(range)), height, format);
 }
 
 /*