Browse Source

Feat: read data with type array index

viest 5 years ago
parent
commit
fcca5edb6c
2 changed files with 67 additions and 9 deletions
  1. 11 9
      kernel/read.c
  2. 56 0
      tests/open_xlsx_next_row_with_data_type_date_array_index.phpt

+ 11 - 9
kernel/read.c

@@ -51,9 +51,10 @@ int sheet_read_row(xlsxioreadersheet sheet_t)
 /* {{{ */
 /* {{{ */
 unsigned int load_sheet_current_row_data(xlsxioreadersheet sheet_t, zval *zv_result_t, zval *zv_type_arr_t, unsigned int flag)
 unsigned int load_sheet_current_row_data(xlsxioreadersheet sheet_t, zval *zv_result_t, zval *zv_type_arr_t, unsigned int flag)
 {
 {
-    zend_long _type = READ_TYPE_EMPTY;
+    zend_ulong _type = READ_TYPE_EMPTY, _cell_index = 0;
+    zend_array *_za_type_t = NULL;
     char *_string_value = NULL;
     char *_string_value = NULL;
-    Bucket *_start = NULL, *_end = NULL;
+    zval *_current_type = NULL;
 
 
     if (flag && !sheet_read_row(sheet_t)) {
     if (flag && !sheet_read_row(sheet_t)) {
         return XLSWRITER_FALSE;
         return XLSWRITER_FALSE;
@@ -64,20 +65,21 @@ unsigned int load_sheet_current_row_data(xlsxioreadersheet sheet_t, zval *zv_res
     }
     }
 
 
     if (zv_type_arr_t != NULL && Z_TYPE_P(zv_type_arr_t) == IS_ARRAY) {
     if (zv_type_arr_t != NULL && Z_TYPE_P(zv_type_arr_t) == IS_ARRAY) {
-        _start = zv_type_arr_t->value.arr->arData;
-        _end   = _start + zv_type_arr_t->value.arr->nNumUsed;
+        _za_type_t = Z_ARR_P(zv_type_arr_t);
     }
     }
 
 
     while ((_string_value = xlsxioread_sheet_next_cell(sheet_t)) != NULL)
     while ((_string_value = xlsxioread_sheet_next_cell(sheet_t)) != NULL)
     {
     {
-        if (_start != _end) {
-            zval *_zv_type = &_start->val;
+        _type = READ_TYPE_EMPTY;
 
 
-            if (Z_TYPE_P(_zv_type) == IS_LONG) {
-                _type = Z_LVAL_P(_zv_type);
+        if (_za_type_t != NULL) {
+            if ((_current_type = zend_hash_index_find(_za_type_t, _cell_index)) != NULL) {
+                if (Z_TYPE_P(_current_type) == IS_LONG) {
+                    _type = Z_LVAL_P(_current_type);
+                }
             }
             }
 
 
-            _start++;
+            _cell_index++;
         }
         }
 
 
         if (_type & READ_TYPE_DATETIME) {
         if (_type & READ_TYPE_DATETIME) {

+ 56 - 0
tests/open_xlsx_next_row_with_data_type_date_array_index.phpt

@@ -0,0 +1,56 @@
+--TEST--
+Check for vtiful presence
+--SKIPIF--
+<?php
+require __DIR__ . '/include/skipif.inc';
+skip_disable_reader();
+?>
+--FILE--
+<?php
+$config   = ['path' => './tests'];
+$excel    = new \Vtiful\Kernel\Excel($config);
+$filePath = $excel->fileName('tutorial.xlsx')
+    ->header(['', 'Cost'])
+    ->data([
+        [],
+        ['viest', ''],
+    ])
+    ->insertDate(2, 4, 1568818881)
+    ->output();
+
+$data = $excel->openFile('tutorial.xlsx')
+    ->openSheet('Sheet1');
+
+while ($data = $excel->nextRow([4 => \Vtiful\Kernel\Excel::TYPE_TIMESTAMP])) {
+    var_dump($data);
+}
+?>
+--CLEAN--
+<?php
+@unlink(__DIR__ . '/tutorial.xlsx');
+?>
+--EXPECT--
+array(2) {
+  [0]=>
+  string(0) ""
+  [1]=>
+  string(4) "Cost"
+}
+array(2) {
+  [0]=>
+  string(0) ""
+  [1]=>
+  string(0) ""
+}
+array(5) {
+  [0]=>
+  string(5) "viest"
+  [1]=>
+  string(0) ""
+  [2]=>
+  string(0) ""
+  [3]=>
+  string(0) ""
+  [4]=>
+  float(1568818881)
+}