Browse Source

Merge pull request #335 from viest/dev

Feat: sheet hide and first
viest 4 years ago
parent
commit
d7315917b3
8 changed files with 183 additions and 5 deletions
  1. 2 0
      include/xlswriter.h
  2. 40 3
      kernel/excel.c
  3. 16 0
      kernel/write.c
  4. 1 0
      php_xlswriter.h
  5. 44 0
      tests/first.phpt
  6. 44 0
      tests/hide.phpt
  7. 12 0
      tests/version.phpt
  8. 24 2
      xlswriter.c

+ 2 - 0
include/xlswriter.h

@@ -222,6 +222,8 @@ STATIC void _populate_range(lxw_workbook *self, lxw_series_range *range);
 STATIC void _populate_range_dimensions(lxw_workbook *self, lxw_series_range *range);
 
 void comment_show(xls_resource_write_t *res);
+void hide_worksheet(xls_resource_write_t *res);
+void first_worksheet(xls_resource_write_t *res);
 void zoom(xls_resource_write_t *res, zend_long zoom);
 void gridlines(xls_resource_write_t *res, zend_long option);
 void auto_filter(zend_string *range, xls_resource_write_t *res);

+ 40 - 3
kernel/excel.c

@@ -272,6 +272,12 @@ ZEND_END_ARG_INFO()
 
 ZEND_BEGIN_ARG_INFO_EX(xls_set_printed_landscape_arginfo, 0, 0, 0)
 ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(xls_hide_sheet_arginfo, 0, 0, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(xls_first_sheet_arginfo, 0, 0, 0)
+ZEND_END_ARG_INFO()
 /* }}} */
 
 /** {{{ \Vtiful\Kernel\Excel::__construct(array $config)
@@ -1138,6 +1144,34 @@ PHP_METHOD(vtiful_xls, setPrintedLandscape)
 }
 /* }}} */
 
+/** {{{ \Vtiful\Kernel\Excel::setCurrentSheetHide()
+ */
+PHP_METHOD(vtiful_xls, setCurrentSheetHide)
+{
+    ZVAL_COPY(return_value, getThis());
+
+    xls_object* obj = Z_XLS_P(getThis());
+
+    WORKBOOK_NOT_INITIALIZED(obj);
+
+    hide_worksheet(&obj->write_ptr);
+}
+/* }}} */
+
+/** {{{ \Vtiful\Kernel\Excel::setCurrentSheetIsFirst()
+ */
+PHP_METHOD(vtiful_xls, setCurrentSheetIsFirst)
+{
+    ZVAL_COPY(return_value, getThis());
+
+    xls_object* obj = Z_XLS_P(getThis());
+
+    WORKBOOK_NOT_INITIALIZED(obj);
+
+    first_worksheet(&obj->write_ptr);
+}
+/* }}} */
+
 #ifdef ENABLE_READER
 
 /** {{{ \Vtiful\Kernel\Excel::openFile()
@@ -1467,13 +1501,16 @@ zend_function_entry xls_methods[] = {
         PHP_ME(vtiful_xls, zoom,          xls_sheet_zoom_arginfo,     ZEND_ACC_PUBLIC)
         PHP_ME(vtiful_xls, gridline,      xls_sheet_gridline_arginfo, ZEND_ACC_PUBLIC)
 
+        PHP_ME(vtiful_xls, setPrintedPortrait,  xls_set_printed_portrait_arginfo,  ZEND_ACC_PUBLIC)
+        PHP_ME(vtiful_xls, setPrintedLandscape, xls_set_printed_landscape_arginfo, ZEND_ACC_PUBLIC)
+
+        PHP_ME(vtiful_xls, setCurrentSheetHide,    xls_hide_sheet_arginfo,  ZEND_ACC_PUBLIC)
+        PHP_ME(vtiful_xls, setCurrentSheetIsFirst, xls_first_sheet_arginfo, ZEND_ACC_PUBLIC)
+
         PHP_ME(vtiful_xls, columnIndexFromString,   xls_index_to_string, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
         PHP_ME(vtiful_xls, stringFromColumnIndex,   xls_string_to_index, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
         PHP_ME(vtiful_xls, timestampFromDateDouble, xls_string_to_index, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
 
-        PHP_ME(vtiful_xls, setPrintedPortrait, xls_set_printed_portrait_arginfo,   ZEND_ACC_PUBLIC)
-        PHP_ME(vtiful_xls, setPrintedLandscape, xls_set_printed_landscape_arginfo, ZEND_ACC_PUBLIC)
-
 #ifdef ENABLE_READER
         PHP_ME(vtiful_xls, openFile,         xls_open_file_arginfo,          ZEND_ACC_PUBLIC)
         PHP_ME(vtiful_xls, openSheet,        xls_open_sheet_arginfo,         ZEND_ACC_PUBLIC)

+ 16 - 0
kernel/write.c

@@ -363,6 +363,22 @@ void printed_direction(xls_resource_write_t *res, unsigned int direction)
     worksheet_set_landscape(res->worksheet);
 }
 
+/*
+ * Hide worksheet
+ */
+void hide_worksheet(xls_resource_write_t *res)
+{
+    worksheet_hide(res->worksheet);
+}
+
+/*
+ * First worksheet
+ */
+void first_worksheet(xls_resource_write_t *res)
+{
+    worksheet_set_first_sheet(res->worksheet);
+}
+
 /*
  * Call finalization code and close file.
  */

+ 1 - 0
php_xlswriter.h

@@ -19,6 +19,7 @@ extern zend_module_entry xlswriter_module_entry;
 #define phpext_xlswriter_ptr &xlswriter_module_entry
 
 #define PHP_XLSWRITER_VERSION "1.3.7"
+#define PHP_XLSWRITER_AUTHOR  "Jiexing.Wang ([email protected])"
 
 #ifdef PHP_WIN32
 #	define PHP_VTIFUL_API __declspec(dllexport)

+ 44 - 0
tests/first.phpt

@@ -0,0 +1,44 @@
+--TEST--
+Check for vtiful presence
+--SKIPIF--
+<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
+--FILE--
+<?php
+try {
+    $config = ['path' => './tests'];
+    $excel  = new \Vtiful\Kernel\Excel($config);
+
+    $excel->setCurrentSheetHide();
+} catch (\Exception $exception) {
+    var_dump($exception->getCode());
+    var_dump($exception->getMessage());
+}
+
+$config = ['path' => './tests'];
+$excel  = new \Vtiful\Kernel\Excel($config);
+
+$excel->fileName('first.xlsx', 'sheet1')
+    ->addSheet('sheet2')
+    ->setCurrentSheetIsFirst()
+    ->output();
+
+var_dump($excel);
+?>
+--CLEAN--
+<?php
+@unlink(__DIR__ . '/first.xlsx');
+?>
+--EXPECT--
+int(130)
+string(51) "Please create a file first, use the filename method"
+object(Vtiful\Kernel\Excel)#3 (3) {
+  ["config":"Vtiful\Kernel\Excel":private]=>
+  array(1) {
+    ["path"]=>
+    string(7) "./tests"
+  }
+  ["fileName":"Vtiful\Kernel\Excel":private]=>
+  string(18) "./tests/first.xlsx"
+  ["read_row_type":"Vtiful\Kernel\Excel":private]=>
+  NULL
+}

+ 44 - 0
tests/hide.phpt

@@ -0,0 +1,44 @@
+--TEST--
+Check for vtiful presence
+--SKIPIF--
+<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
+--FILE--
+<?php
+try {
+    $config = ['path' => './tests'];
+    $excel  = new \Vtiful\Kernel\Excel($config);
+
+    $excel->setCurrentSheetHide();
+} catch (\Exception $exception) {
+    var_dump($exception->getCode());
+    var_dump($exception->getMessage());
+}
+
+$config = ['path' => './tests'];
+$excel  = new \Vtiful\Kernel\Excel($config);
+
+$excel->fileName('hide.xlsx', 'sheet1')
+    ->addSheet('sheet2')
+    ->setCurrentSheetHide()
+    ->output();
+
+var_dump($excel);
+?>
+--CLEAN--
+<?php
+@unlink(__DIR__ . '/hide.xlsx');
+?>
+--EXPECT--
+int(130)
+string(51) "Please create a file first, use the filename method"
+object(Vtiful\Kernel\Excel)#3 (3) {
+  ["config":"Vtiful\Kernel\Excel":private]=>
+  array(1) {
+    ["path"]=>
+    string(7) "./tests"
+  }
+  ["fileName":"Vtiful\Kernel\Excel":private]=>
+  string(17) "./tests/hide.xlsx"
+  ["read_row_type":"Vtiful\Kernel\Excel":private]=>
+  NULL
+}

+ 12 - 0
tests/version.phpt

@@ -0,0 +1,12 @@
+--TEST--
+Check for vtiful presence
+--SKIPIF--
+<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
+--FILE--
+<?php
+var_dump(is_string(xlswriter_get_version()));
+var_dump(is_string(xlswriter_get_author()));
+?>
+--EXPECT--
+bool(true)
+bool(true)

+ 24 - 2
xlswriter.c

@@ -25,6 +25,28 @@
 
 int le_xls_writer;
 
+ZEND_BEGIN_ARG_INFO_EX(xlswriter_get_version_arginfo, 0, 0, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(xlswriter_get_auther_arginfo, 0, 0, 0)
+ZEND_END_ARG_INFO()
+
+/* {{{ xlswriter_get_version
+ */
+PHP_FUNCTION(xlswriter_get_version)
+{
+    RETURN_STRINGL(PHP_XLSWRITER_VERSION, strlen(PHP_XLSWRITER_VERSION));
+}
+/* }}} */
+
+/* {{{ xlswriter_get_author
+ */
+PHP_FUNCTION(xlswriter_get_author)
+{
+    RETURN_STRINGL(PHP_XLSWRITER_AUTHOR, strlen(PHP_XLSWRITER_AUTHOR));
+}
+/* }}} */
+
 /* {{{ PHP_MINIT_FUNCTION
  */
 PHP_MINIT_FUNCTION(xlswriter)
@@ -40,7 +62,6 @@ PHP_MINIT_FUNCTION(xlswriter)
 }
 /* }}} */
 
-
 /* {{{ PHP_MSHUTDOWN_FUNCTION
  */
 PHP_MSHUTDOWN_FUNCTION(xlswriter)
@@ -68,7 +89,6 @@ PHP_RSHUTDOWN_FUNCTION(xlswriter)
 }
 /* }}} */
 
-
 /* {{{ PHP_MINFO_FUNCTION
  */
 PHP_MINFO_FUNCTION(xlswriter)
@@ -109,6 +129,8 @@ PHP_MINFO_FUNCTION(xlswriter)
  * Every user visible function must have an entry in xlswriter_functions[].
  */
 const zend_function_entry xlswriter_functions[] = {
+    PHP_FE(xlswriter_get_version, xlswriter_get_version_arginfo)
+    PHP_FE(xlswriter_get_author,  xlswriter_get_auther_arginfo)
 	PHP_FE_END
 };
 /* }}} */