@@ -42,7 +42,7 @@ xlsxioreadersheet sheet_open(xlsxioreader file_t, const zend_string *zs_sheet_na
4242/* }}} */
4343
4444/* {{{ */
45- int is_number (char * value )
45+ int is_number (const char * value )
4646{
4747 if (strspn (value , ".0123456789" ) == strlen (value )) {
4848 return XLSWRITER_TRUE ;
@@ -52,6 +52,71 @@ int is_number(char *value)
5252}
5353/* }}} */
5454
55+ /* {{{ */
56+ void data_to_custom_type (const char * string_value , zend_ulong type , zval * zv_result_t )
57+ {
58+ if (type & READ_TYPE_DATETIME ) {
59+ if (!is_number (string_value )) {
60+ goto STRING ;
61+ }
62+
63+ double value = strtod (string_value , NULL );
64+
65+ if (value != 0 ) {
66+ value = (value - 25569 ) * 86400 ;
67+ }
68+
69+ if (Z_TYPE_P (zv_result_t ) == IS_ARRAY ) {
70+ add_next_index_long (zv_result_t , (zend_long )(value + 0.5 ));
71+ } else {
72+ ZVAL_LONG (zv_result_t , (zend_long )(value + 0.5 ));
73+ }
74+
75+ return ;
76+ }
77+
78+ if (type & READ_TYPE_DOUBLE ) {
79+ if (!is_number (string_value )) {
80+ goto STRING ;
81+ }
82+
83+ if (Z_TYPE_P (zv_result_t ) == IS_ARRAY ) {
84+ add_next_index_double (zv_result_t , strtod (string_value , NULL ));
85+ } else {
86+ ZVAL_DOUBLE (zv_result_t , strtod (string_value , NULL ));
87+ }
88+
89+ return ;
90+ }
91+
92+ if (type & READ_TYPE_INT ) {
93+ if (!is_number (string_value )) {
94+ goto STRING ;
95+ }
96+
97+ zend_long _long_value ;
98+
99+ sscanf (string_value , "%" PRIi64 , & _long_value );
100+
101+ if (Z_TYPE_P (zv_result_t ) == IS_ARRAY ) {
102+ add_next_index_long (zv_result_t , _long_value );
103+ } else {
104+ ZVAL_LONG (zv_result_t , _long_value );
105+ }
106+
107+ return ;
108+ }
109+
110+ STRING :
111+
112+ if (Z_TYPE_P (zv_result_t ) == IS_ARRAY ) {
113+ add_next_index_stringl (zv_result_t , string_value , strlen (string_value ));
114+ } else {
115+ ZVAL_STRINGL (zv_result_t , string_value , strlen (string_value ));
116+ }
117+ }
118+ /* }}} */
119+
55120/* {{{ */
56121int sheet_read_row (xlsxioreadersheet sheet_t )
57122{
@@ -62,7 +127,7 @@ int sheet_read_row(xlsxioreadersheet sheet_t)
62127/* {{{ */
63128unsigned int load_sheet_current_row_data (xlsxioreadersheet sheet_t , zval * zv_result_t , zval * zv_type_arr_t , unsigned int flag )
64129{
65- zend_ulong _type = READ_TYPE_EMPTY , _cell_index = 0 ;
130+ zend_ulong _type , _cell_index = 0 ;
66131 zend_array * _za_type_t = NULL ;
67132 char * _string_value = NULL ;
68133 zval * _current_type = NULL ;
@@ -93,45 +158,7 @@ unsigned int load_sheet_current_row_data(xlsxioreadersheet sheet_t, zval *zv_res
93158 _cell_index ++ ;
94159 }
95160
96- if (_type & READ_TYPE_DATETIME ) {
97- if (!is_number (_string_value )) {
98- goto STRING ;
99- }
100-
101- double value = strtod (_string_value , NULL );
102-
103- if (value != 0 ) {
104- value = (value - 25569 ) * 86400 ;
105- }
106-
107- add_next_index_long (zv_result_t , (zend_long )(value + 0.5 ));
108- continue ;
109- }
110-
111- if (_type & READ_TYPE_DOUBLE ) {
112- if (!is_number (_string_value )) {
113- goto STRING ;
114- }
115-
116- add_next_index_double (zv_result_t , strtod (_string_value , NULL ));
117- continue ;
118- }
119-
120- if (_type & READ_TYPE_INT ) {
121- if (!is_number (_string_value )) {
122- goto STRING ;
123- }
124-
125- zend_long _long_value ;
126-
127- sscanf (_string_value , "%" PRIi64 , & _long_value );
128- add_next_index_long (zv_result_t , _long_value );
129- continue ;
130- }
131-
132- STRING :
133-
134- add_next_index_stringl (zv_result_t , _string_value , strlen (_string_value ));
161+ data_to_custom_type (_string_value , _type , zv_result_t );
135162 }
136163
137164 return XLSWRITER_TRUE ;
@@ -153,8 +180,8 @@ int sheet_row_callback (size_t row, size_t max_col, void* callback_data)
153180 _callback_data -> fci -> params = args ;
154181 _callback_data -> fci -> param_count = 3 ;
155182
156- ZVAL_LONG (& args [0 ], row );
157- ZVAL_LONG (& args [1 ], max_col );
183+ ZVAL_LONG (& args [0 ], ( row - 1 ) );
184+ ZVAL_LONG (& args [1 ], ( max_col - 1 ) );
158185 ZVAL_STRING (& args [2 ], "XLSX_ROW_END" );
159186
160187 zend_call_function (_callback_data -> fci , _callback_data -> fci_cache );
@@ -185,9 +212,25 @@ int sheet_cell_callback (size_t row, size_t col, const char *value, void *callba
185212 _callback_data -> fci -> params = args ;
186213 _callback_data -> fci -> param_count = 3 ;
187214
188- ZVAL_LONG (& args [0 ], row );
189- ZVAL_LONG (& args [1 ], col );
190- ZVAL_STRING (& args [2 ], value );
215+ ZVAL_LONG (& args [0 ], (row - 1 ));
216+ ZVAL_LONG (& args [1 ], (col - 1 ));
217+
218+ if (Z_TYPE_P (_callback_data -> zv_type_t ) != IS_ARRAY ) {
219+ ZVAL_STRING (& args [2 ], value );
220+ }
221+
222+ if (Z_TYPE_P (_callback_data -> zv_type_t ) == IS_ARRAY ) {
223+ zval * _current_type = NULL ;
224+ zend_ulong _type = READ_TYPE_EMPTY ;
225+
226+ if ((_current_type = zend_hash_index_find (Z_ARR_P (_callback_data -> zv_type_t ), (col - 1 ))) != NULL ) {
227+ if (Z_TYPE_P (_current_type ) == IS_LONG ) {
228+ _type = Z_LVAL_P (_current_type );
229+ }
230+ }
231+
232+ data_to_custom_type (value , _type , & args [2 ]);
233+ }
191234
192235 zend_call_function (_callback_data -> fci , _callback_data -> fci_cache );
193236
0 commit comments