Skip to content

Commit fcca5ed

Browse files
committed
Feat: read data with type array index
1 parent fe5d9a6 commit fcca5ed

File tree

2 files changed

+67
-9
lines changed

2 files changed

+67
-9
lines changed

kernel/read.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@ int sheet_read_row(xlsxioreadersheet sheet_t)
5151
/* {{{ */
5252
unsigned int load_sheet_current_row_data(xlsxioreadersheet sheet_t, zval *zv_result_t, zval *zv_type_arr_t, unsigned int flag)
5353
{
54-
zend_long _type = READ_TYPE_EMPTY;
54+
zend_ulong _type = READ_TYPE_EMPTY, _cell_index = 0;
55+
zend_array *_za_type_t = NULL;
5556
char *_string_value = NULL;
56-
Bucket *_start = NULL, *_end = NULL;
57+
zval *_current_type = NULL;
5758

5859
if (flag && !sheet_read_row(sheet_t)) {
5960
return XLSWRITER_FALSE;
@@ -64,20 +65,21 @@ unsigned int load_sheet_current_row_data(xlsxioreadersheet sheet_t, zval *zv_res
6465
}
6566

6667
if (zv_type_arr_t != NULL && Z_TYPE_P(zv_type_arr_t) == IS_ARRAY) {
67-
_start = zv_type_arr_t->value.arr->arData;
68-
_end = _start + zv_type_arr_t->value.arr->nNumUsed;
68+
_za_type_t = Z_ARR_P(zv_type_arr_t);
6969
}
7070

7171
while ((_string_value = xlsxioread_sheet_next_cell(sheet_t)) != NULL)
7272
{
73-
if (_start != _end) {
74-
zval *_zv_type = &_start->val;
73+
_type = READ_TYPE_EMPTY;
7574

76-
if (Z_TYPE_P(_zv_type) == IS_LONG) {
77-
_type = Z_LVAL_P(_zv_type);
75+
if (_za_type_t != NULL) {
76+
if ((_current_type = zend_hash_index_find(_za_type_t, _cell_index)) != NULL) {
77+
if (Z_TYPE_P(_current_type) == IS_LONG) {
78+
_type = Z_LVAL_P(_current_type);
79+
}
7880
}
7981

80-
_start++;
82+
_cell_index++;
8183
}
8284

8385
if (_type & READ_TYPE_DATETIME) {
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
--TEST--
2+
Check for vtiful presence
3+
--SKIPIF--
4+
<?php
5+
require __DIR__ . '/include/skipif.inc';
6+
skip_disable_reader();
7+
?>
8+
--FILE--
9+
<?php
10+
$config = ['path' => './tests'];
11+
$excel = new \Vtiful\Kernel\Excel($config);
12+
$filePath = $excel->fileName('tutorial.xlsx')
13+
->header(['', 'Cost'])
14+
->data([
15+
[],
16+
['viest', ''],
17+
])
18+
->insertDate(2, 4, 1568818881)
19+
->output();
20+
21+
$data = $excel->openFile('tutorial.xlsx')
22+
->openSheet('Sheet1');
23+
24+
while ($data = $excel->nextRow([4 => \Vtiful\Kernel\Excel::TYPE_TIMESTAMP])) {
25+
var_dump($data);
26+
}
27+
?>
28+
--CLEAN--
29+
<?php
30+
@unlink(__DIR__ . '/tutorial.xlsx');
31+
?>
32+
--EXPECT--
33+
array(2) {
34+
[0]=>
35+
string(0) ""
36+
[1]=>
37+
string(4) "Cost"
38+
}
39+
array(2) {
40+
[0]=>
41+
string(0) ""
42+
[1]=>
43+
string(0) ""
44+
}
45+
array(5) {
46+
[0]=>
47+
string(5) "viest"
48+
[1]=>
49+
string(0) ""
50+
[2]=>
51+
string(0) ""
52+
[3]=>
53+
string(0) ""
54+
[4]=>
55+
float(1568818881)
56+
}

0 commit comments

Comments
 (0)