Browse Source

FEAT(format): Add cell black style.

viest 7 years ago
parent
commit
e0efa9db9c
10 changed files with 144 additions and 56 deletions
  1. 5 1
      config.m4
  2. 2 0
      excel_writer.c
  3. 14 0
      kernel/common/resource.c
  4. 1 22
      kernel/excel.c
  5. 0 10
      kernel/excel.h
  6. 6 4
      kernel/exception.c
  7. 68 0
      kernel/format.c
  8. 23 0
      kernel/format.h
  9. 24 14
      kernel/include.h
  10. 1 5
      kernel/write.c

+ 5 - 1
config.m4

@@ -4,6 +4,7 @@ PHP_ARG_ENABLE(excel_writer, whether to enable excel_writer support,
 if test "$PHP_EXCEL_WRITER" != "no"; then
 if test "$PHP_EXCEL_WRITER" != "no"; then
     excel_writer_sources="excel_writer.c \
     excel_writer_sources="excel_writer.c \
     kernel/exception.c \
     kernel/exception.c \
+    kernel/common/resource.c \
     "
     "
 
 
     AC_MSG_CHECKING([Check libxlsxwriter support])
     AC_MSG_CHECKING([Check libxlsxwriter support])
@@ -16,7 +17,10 @@ if test "$PHP_EXCEL_WRITER" != "no"; then
             PHP_CHECK_LIBRARY(xlsxwriter, worksheet_write_string,
             PHP_CHECK_LIBRARY(xlsxwriter, worksheet_write_string,
             [
             [
                 PHP_ADD_LIBRARY_WITH_PATH(xlsxwriter, $i/$PHP_LIBDIR, EXCEL_WRITER_SHARED_LIBADD)
                 PHP_ADD_LIBRARY_WITH_PATH(xlsxwriter, $i/$PHP_LIBDIR, EXCEL_WRITER_SHARED_LIBADD)
-                excel_writer_sources="$excel_writer_sources kernel/excel.c kernel/write.c"
+                excel_writer_sources="$excel_writer_sources \
+                kernel/excel.c \
+                kernel/write.c \
+                kernel/format.c"
             ],[
             ],[
                 AC_MSG_ERROR([Wrong libxlsxwriter version or library not found])
                 AC_MSG_ERROR([Wrong libxlsxwriter version or library not found])
             ],[
             ],[

+ 2 - 0
excel_writer.c

@@ -20,6 +20,7 @@
 #include "ext/standard/info.h"
 #include "ext/standard/info.h"
 
 
 #include "kernel/excel.h"
 #include "kernel/excel.h"
+#include "kernel/format.h"
 #include "kernel/exception.h"
 #include "kernel/exception.h"
 
 
 int le_excel_writer;
 int le_excel_writer;
@@ -30,6 +31,7 @@ PHP_MINIT_FUNCTION(excel_writer)
 {
 {
     VTIFUL_STARTUP_MODULE(exception);
     VTIFUL_STARTUP_MODULE(exception);
 	VTIFUL_STARTUP_MODULE(excel);
 	VTIFUL_STARTUP_MODULE(excel);
+	VTIFUL_STARTUP_MODULE(format);
 
 
     le_excel_writer = zend_register_list_destructors_ex(_php_vtiful_excel_close, NULL, VTIFUL_RESOURCE_NAME, module_number);
     le_excel_writer = zend_register_list_destructors_ex(_php_vtiful_excel_close, NULL, VTIFUL_RESOURCE_NAME, module_number);
 
 

+ 14 - 0
kernel/common/resource.c

@@ -0,0 +1,14 @@
+#include "../include.h"
+
+/* {{{ */
+excel_resource_t * zval_get_resource(zval *handle)
+{
+    excel_resource_t *res;
+
+    if((res = (excel_resource_t *)zend_fetch_resource(Z_RES_P(handle), VTIFUL_RESOURCE_NAME, le_excel_writer)) == NULL) {
+        zend_throw_exception(vtiful_exception_ce, "Excel resources resolution fail", 210);
+    }
+
+    return res;
+}
+/* }}} */

+ 1 - 22
kernel/excel.c

@@ -14,15 +14,7 @@
 #include "config.h"
 #include "config.h"
 #endif
 #endif
 
 
-#include "zend.h"
-#include "zend_API.h"
-#include "zend_exceptions.h"
-
-#include "php.h"
-
-#include "excel.h"
-#include "exception.h"
-#include "write.h"
+#include "include.h"
 
 
 zend_class_entry *vtiful_excel_ce;
 zend_class_entry *vtiful_excel_ce;
 
 
@@ -73,19 +65,6 @@ ZEND_BEGIN_ARG_INFO_EX(excel_merge_cells_arginfo, 0, 0, 2)
 ZEND_END_ARG_INFO()
 ZEND_END_ARG_INFO()
 /* }}} */
 /* }}} */
 
 
-/* {{{ */
-excel_resource_t * zval_get_resource(zval *handle)
-{
-    excel_resource_t *res;
-
-    if((res = (excel_resource_t *)zend_fetch_resource(Z_RES_P(handle), VTIFUL_RESOURCE_NAME, le_excel_writer)) == NULL) {
-        zend_throw_exception(vtiful_exception_ce, "Excel resources resolution fail", 210);
-    }
-
-    return res;
-}
-/* }}} */
-
 /** {{{ \Vtiful\Kernel\Excel::__construct(array $config)
 /** {{{ \Vtiful\Kernel\Excel::__construct(array $config)
  */
  */
 PHP_METHOD(vtiful_excel, __construct)
 PHP_METHOD(vtiful_excel, __construct)

+ 0 - 10
kernel/excel.h

@@ -13,14 +13,6 @@
 #ifndef VTIFUL_EXCEL_H
 #ifndef VTIFUL_EXCEL_H
 #define VTIFUL_EXCEL_H
 #define VTIFUL_EXCEL_H
 
 
-#include "php_excel_writer.h"
-#include "xlsxwriter.h"
-
-typedef struct {
-    lxw_workbook *workbook;
-    lxw_worksheet *worksheet;
-} excel_resource_t;
-
 #define V_EXCEL_HANDLE "handle"
 #define V_EXCEL_HANDLE "handle"
 #define V_EXCEL_FIL "fileName"
 #define V_EXCEL_FIL "fileName"
 #define V_EXCEL_COF "config"
 #define V_EXCEL_COF "config"
@@ -28,8 +20,6 @@ typedef struct {
 
 
 extern zend_class_entry *vtiful_excel_ce;
 extern zend_class_entry *vtiful_excel_ce;
 
 
-excel_resource_t * zval_get_resource(zval *handle);
-
 VTIFUL_STARTUP_FUNCTION(excel);
 VTIFUL_STARTUP_FUNCTION(excel);
 
 
 #endif
 #endif

+ 6 - 4
kernel/exception.c

@@ -10,10 +10,12 @@
   +----------------------------------------------------------------------+
   +----------------------------------------------------------------------+
 */
 */
 
 
-#include <php.h>
-#include "zend_exceptions.h"
-#include "php_excel_writer.h"
-#include "exception.h"
+#include "include.h"
+
+//#include <php.h>
+//#include "zend_exceptions.h"
+//#include "php_excel_writer.h"
+//#include "exception.h"
 
 
 zend_class_entry *vtiful_exception_ce;
 zend_class_entry *vtiful_exception_ce;
 
 

+ 68 - 0
kernel/format.c

@@ -0,0 +1,68 @@
+/*
+  +----------------------------------------------------------------------+
+  | Vtiful Extension                                                     |
+  +----------------------------------------------------------------------+
+  | Copyright (c) 2017-2017 The Viest                                    |
+  +----------------------------------------------------------------------+
+  | http://www.viest.me                                                  |
+  +----------------------------------------------------------------------+
+  | Author: viest <[email protected]>                                 |
+  +----------------------------------------------------------------------+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "include.h"
+
+zend_class_entry *vtiful_format_ce;
+
+/* {{{ ARG_INFO
+ */
+ZEND_BEGIN_ARG_INFO_EX(format_style_arginfo, 0, 0, 1)
+                ZEND_ARG_INFO(0, handle)
+ZEND_END_ARG_INFO()
+/* }}} */
+
+/** {{{ \Vtiful\Kernel\Format::boldStype()
+ */
+PHP_METHOD(vtiful_format, boldStype)
+{
+    zval *handle;
+    lxw_format *bold_format;
+    excel_resource_t *excel_res;
+
+    ZEND_PARSE_PARAMETERS_START(1, 1)
+            Z_PARAM_RESOURCE(handle)
+    ZEND_PARSE_PARAMETERS_END();
+
+    excel_res   = zval_get_resource(handle);
+    bold_format = workbook_add_format(excel_res->workbook);
+
+    format_set_bold(bold_format);
+
+    RETURN_RES(zend_register_resource(bold_format, le_excel_writer));
+}
+/* }}} */
+
+/** {{{ excel_methods
+*/
+zend_function_entry formac_methods[] = {
+        PHP_ME(vtiful_format, boldStype, format_style_arginfo, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+        PHP_FE_END
+};
+/* }}} */
+
+/** {{{ VTIFUL_STARTUP_FUNCTION
+*/
+VTIFUL_STARTUP_FUNCTION(format) {
+    zend_class_entry ce;
+
+    INIT_NS_CLASS_ENTRY(ce, "Vtiful\\Kernel", "Format", formac_methods);
+
+    vtiful_format_ce = zend_register_internal_class(&ce);
+
+    return SUCCESS;
+}
+/* }}} */

+ 23 - 0
kernel/format.h

@@ -0,0 +1,23 @@
+/*
+  +----------------------------------------------------------------------+
+  | Vtiful Extension                                                     |
+  +----------------------------------------------------------------------+
+  | Copyright (c) 2017-2017 The Viest                                    |
+  +----------------------------------------------------------------------+
+  | http://www.viest.me                                                  |
+  +----------------------------------------------------------------------+
+  | Author: viest <[email protected]>                                 |
+  +----------------------------------------------------------------------+
+*/
+
+#ifndef PHP_EXT_EXCEL_EXPORT_FORMAT_H
+#define PHP_EXT_EXCEL_EXPORT_FORMAT_H
+
+#include "php_excel_writer.h"
+#include "xlsxwriter.h"
+
+extern zend_class_entry *vtiful_format_ce;
+
+VTIFUL_STARTUP_FUNCTION(format);
+
+#endif

+ 24 - 14
kernel/write.h → kernel/include.h

@@ -1,17 +1,27 @@
-/*
-  +----------------------------------------------------------------------+
-  | Vtiful Extension                                                     |
-  +----------------------------------------------------------------------+
-  | Copyright (c) 2017-2017 The Viest                                    |
-  +----------------------------------------------------------------------+
-  | http://www.viest.me                                                  |
-  +----------------------------------------------------------------------+
-  | Author: viest <[email protected]>                                 |
-  +----------------------------------------------------------------------+
-*/
-
-#ifndef VTIFUL_EXCEL_WRITE_H
-#define VTIFUL_EXCEL_WRITE_H
+#ifndef PHP_EXT_EXCEL_EXPORT_INCLUDE_H
+#define PHP_EXT_EXCEL_EXPORT_INCLUDE_H
+
+#include <php.h>
+
+#include "zend_exceptions.h"
+#include "zend.h"
+#include "zend_API.h"
+#include "php.h"
+
+#include "xlsxwriter.h"
+#include "xlsxwriter/packager.h"
+
+#include "php_excel_writer.h"
+#include "excel.h"
+#include "exception.h"
+#include "format.h"
+
+typedef struct {
+    lxw_workbook *workbook;
+    lxw_worksheet *worksheet;
+} excel_resource_t;
+
+excel_resource_t * zval_get_resource(zval *handle);
 
 
 STATIC lxw_error _store_defined_name(lxw_workbook *self, const char *name, const char *app_name, const char *formula, int16_t index, uint8_t hidden);
 STATIC lxw_error _store_defined_name(lxw_workbook *self, const char *name, const char *app_name, const char *formula, int16_t index, uint8_t hidden);
 
 

+ 1 - 5
kernel/write.c

@@ -10,11 +10,7 @@
   +----------------------------------------------------------------------+
   +----------------------------------------------------------------------+
 */
 */
 
 
-#include "php.h"
-#include "excel.h"
-#include "write.h"
-#include "xlsxwriter.h"
-#include "xlsxwriter/packager.h"
+#include "include.h"
 
 
 /*
 /*
  * According to the zval type written to the file
  * According to the zval type written to the file