Browse Source

Feat: sheet hide and first

viest 4 years ago
parent
commit
c1d43186b8
5 changed files with 146 additions and 3 deletions
  1. 2 0
      include/xlswriter.h
  2. 40 3
      kernel/excel.c
  3. 16 0
      kernel/write.c
  4. 44 0
      tests/first.phpt
  5. 44 0
      tests/hide.phpt

+ 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.
  */

+ 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
+}