@@ -99,6 +99,14 @@ ZEND_BEGIN_ARG_INFO_EX(xls_insert_text_arginfo, 0, 0, 5)
9999 ZEND_ARG_INFO (0 , format_handle )
100100ZEND_END_ARG_INFO ()
101101
102+ ZEND_BEGIN_ARG_INFO_EX (xls_insert_date_arginfo , 0 , 0 , 5 )
103+ ZEND_ARG_INFO (0 , row )
104+ ZEND_ARG_INFO (0 , column )
105+ ZEND_ARG_INFO (0 , timestamp )
106+ ZEND_ARG_INFO (0 , format )
107+ ZEND_ARG_INFO (0 , format_handle )
108+ ZEND_END_ARG_INFO ()
109+
102110ZEND_BEGIN_ARG_INFO_EX (xls_insert_url_arginfo , 0 , 0 , 4 )
103111 ZEND_ARG_INFO (0 , row )
104112 ZEND_ARG_INFO (0 , column )
@@ -235,13 +243,9 @@ PHP_METHOD(vtiful_xls, addSheet)
235243
236244 xls_object * obj = Z_XLS_P (getThis ());
237245
246+ WORKBOOK_NOT_INITIALIZED (obj );
238247 SHEET_LINE_INIT (obj )
239248
240- if (obj -> write_ptr .workbook == NULL) {
241- zend_throw_exception (vtiful_exception_ce , "Please create a file first, use the filename method" , 130 );
242- return ;
243- }
244-
245249 if (zs_sheet_name != NULL) {
246250 sheet_name = ZSTR_VAL (zs_sheet_name );
247251 }
@@ -266,10 +270,7 @@ PHP_METHOD(vtiful_xls, checkoutSheet)
266270
267271 xls_object * obj = Z_XLS_P (getThis ());
268272
269- if (obj -> write_ptr .workbook == NULL ) {
270- zend_throw_exception (vtiful_exception_ce , "Please create a file first, use the filename method" , 130 );
271- return ;
272- }
273+ WORKBOOK_NOT_INITIALIZED (obj );
273274
274275 if ((sheet_t = workbook_get_worksheet_by_name (obj -> write_ptr .workbook , ZSTR_VAL (zs_sheet_name ))) == NULL ) {
275276 zend_throw_exception (vtiful_exception_ce , "Sheet not fund" , 140 );
@@ -339,6 +340,8 @@ PHP_METHOD(vtiful_xls, header)
339340
340341 xls_object * obj = Z_XLS_P (getThis ());
341342
343+ WORKBOOK_NOT_INITIALIZED (obj );
344+
342345 ZEND_HASH_FOREACH_NUM_KEY_VAL (Z_ARRVAL_P (header ), header_l_key , header_value )
343346 type_writer (header_value , 0 , header_l_key , & obj -> write_ptr , NULL , NULL );
344347 zval_ptr_dtor (header_value );
@@ -360,6 +363,8 @@ PHP_METHOD(vtiful_xls, data)
360363
361364 xls_object * obj = Z_XLS_P (getThis ());
362365
366+ WORKBOOK_NOT_INITIALIZED (obj );
367+
363368 ZEND_HASH_FOREACH_VAL (Z_ARRVAL_P (data ), data_r_value )
364369 if (Z_TYPE_P (data_r_value ) == IS_ARRAY ) {
365370 SHEET_LINE_ADD (obj )
@@ -383,6 +388,8 @@ PHP_METHOD(vtiful_xls, output)
383388
384389 xls_object * obj = Z_XLS_P (getThis ());
385390
391+ WORKBOOK_NOT_INITIALIZED (obj );
392+
386393 workbook_file (& obj -> write_ptr );
387394
388395 ZVAL_COPY (return_value , file_path );
@@ -420,14 +427,63 @@ PHP_METHOD(vtiful_xls, insertText)
420427
421428 xls_object * obj = Z_XLS_P (getThis ());
422429
430+ WORKBOOK_NOT_INITIALIZED (obj );
431+
423432 SHEET_LINE_SET (obj , row );
424433
425434 if (format_handle ) {
426435 type_writer (data , row , column , & obj -> write_ptr , format , zval_get_format (format_handle ));
427436 } else {
428437 type_writer (data , row , column , & obj -> write_ptr , format , NULL );
429438 }
439+ }
440+ /* }}} */
441+
442+ /** {{{ \Vtiful\Kernel\xls::insertDate(int $row, int $column, int $timestamp[, string $format, resource $formatHandle])
443+ */
444+ PHP_METHOD (vtiful_xls , insertDate )
445+ {
446+ zval * data = NULL , * format_handle = NULL ;
447+ zend_long row , column ;
448+ zend_string * format = NULL ;
449+
450+ ZEND_PARSE_PARAMETERS_START (3 , 5 )
451+ Z_PARAM_LONG (row )
452+ Z_PARAM_LONG (column )
453+ Z_PARAM_ZVAL (data )
454+ Z_PARAM_OPTIONAL
455+ Z_PARAM_STR (format )
456+ Z_PARAM_RESOURCE (format_handle )
457+ ZEND_PARSE_PARAMETERS_END ();
458+
459+ ZVAL_COPY (return_value , getThis ());
460+
461+ xls_object * obj = Z_XLS_P (getThis ());
462+
463+ WORKBOOK_NOT_INITIALIZED (obj );
464+ SHEET_LINE_SET (obj , row );
465+
466+ if (Z_TYPE_P (data ) != IS_LONG ) {
467+ zend_throw_exception (vtiful_exception_ce , "timestamp is long" , 160 );
468+ return ;
469+ }
470+
471+ // Default datetime format
472+ if (format == NULL ) {
473+ format = zend_string_init (ZEND_STRL ("yyyy-mm-dd hh:mm:ss" ), 0 );
474+ }
475+
476+ zval _zv_double_time ;
477+ ZVAL_DOUBLE (& _zv_double_time , ((double )data -> value .lval / 86400 + 25569 ));
478+
479+ if (format_handle ) {
480+ type_writer (& _zv_double_time , row , column , & obj -> write_ptr , format , zval_get_format (format_handle ));
481+ } else {
482+ type_writer (& _zv_double_time , row , column , & obj -> write_ptr , format , NULL );
483+ }
430484
485+ zend_string_release (format );
486+ zval_ptr_dtor (& _zv_double_time );
431487}
432488/* }}} */
433489
@@ -448,6 +504,8 @@ PHP_METHOD(vtiful_xls, insertChart)
448504
449505 xls_object * obj = Z_XLS_P (getThis ());
450506
507+ WORKBOOK_NOT_INITIALIZED (obj );
508+
451509 chart_writer (row , column , zval_get_chart (chart_resource ), & obj -> write_ptr );
452510}
453511/* }}} */
@@ -474,6 +532,8 @@ PHP_METHOD(vtiful_xls, insertUrl)
474532
475533 xls_object * obj = Z_XLS_P (getThis ());
476534
535+ WORKBOOK_NOT_INITIALIZED (obj );
536+
477537 if (argc == 4 ) {
478538 url_writer (row , column , & obj -> write_ptr , url , zval_get_format (format_handle ));
479539 }
@@ -505,6 +565,8 @@ PHP_METHOD(vtiful_xls, insertImage)
505565
506566 xls_object * obj = Z_XLS_P (getThis ());
507567
568+ WORKBOOK_NOT_INITIALIZED (obj );
569+
508570 image_writer (image , row , column , width , height , & obj -> write_ptr );
509571}
510572/* }}} */
@@ -526,6 +588,8 @@ PHP_METHOD(vtiful_xls, insertFormula)
526588
527589 xls_object * obj = Z_XLS_P (getThis ());
528590
591+ WORKBOOK_NOT_INITIALIZED (obj );
592+
529593 formula_writer (formula , row , column , & obj -> write_ptr );
530594}
531595/* }}} */
@@ -544,6 +608,8 @@ PHP_METHOD(vtiful_xls, autoFilter)
544608
545609 xls_object * obj = Z_XLS_P (getThis ());
546610
611+ WORKBOOK_NOT_INITIALIZED (obj );
612+
547613 auto_filter (range , & obj -> write_ptr );
548614}
549615/* }}} */
@@ -563,6 +629,8 @@ PHP_METHOD(vtiful_xls, mergeCells)
563629
564630 xls_object * obj = Z_XLS_P (getThis ());
565631
632+ WORKBOOK_NOT_INITIALIZED (obj );
633+
566634 merge_cells (range , data , & obj -> write_ptr );
567635}
568636/* }}} */
@@ -588,6 +656,8 @@ PHP_METHOD(vtiful_xls, setColumn)
588656
589657 xls_object * obj = Z_XLS_P (getThis ());
590658
659+ WORKBOOK_NOT_INITIALIZED (obj );
660+
591661 if (argc == 3 ) {
592662 set_column (range , width , & obj -> write_ptr , zval_get_format (format_handle ));
593663 }
@@ -619,6 +689,8 @@ PHP_METHOD(vtiful_xls, setRow)
619689
620690 xls_object * obj = Z_XLS_P (getThis ());
621691
692+ WORKBOOK_NOT_INITIALIZED (obj );
693+
622694 if (argc == 3 ) {
623695 set_row (range , height , & obj -> write_ptr , zval_get_format (format_handle ));
624696 }
@@ -693,13 +765,20 @@ PHP_METHOD(vtiful_xls, getSheetData)
693765 */
694766PHP_METHOD (vtiful_xls , nextRow )
695767{
696- xls_object * obj = Z_XLS_P (getThis ());
768+ zval * zv_type = NULL ;
769+
770+ ZEND_PARSE_PARAMETERS_START (0 , 1 )
771+ Z_PARAM_OPTIONAL
772+ Z_PARAM_ARRAY (zv_type )
773+ ZEND_PARSE_PARAMETERS_END ();
774+
775+ xls_object * obj = Z_XLS_P (getThis ());
697776
698777 if (!obj -> read_ptr .sheet_t ) {
699778 RETURN_FALSE ;
700779 }
701780
702- load_sheet_current_row_data (obj -> read_ptr .sheet_t , return_value , READ_ROW );
781+ load_sheet_current_row_data (obj -> read_ptr .sheet_t , return_value , zv_type , READ_ROW );
703782}
704783/* }}} */
705784
@@ -719,6 +798,7 @@ zend_function_entry xls_methods[] = {
719798 PHP_ME (vtiful_xls , getHandle , NULL , ZEND_ACC_PUBLIC )
720799 PHP_ME (vtiful_xls , autoFilter , xls_auto_filter_arginfo , ZEND_ACC_PUBLIC )
721800 PHP_ME (vtiful_xls , insertText , xls_insert_text_arginfo , ZEND_ACC_PUBLIC )
801+ PHP_ME (vtiful_xls , insertDate , xls_insert_date_arginfo , ZEND_ACC_PUBLIC )
722802 PHP_ME (vtiful_xls , insertChart , xls_insert_chart_arginfo , ZEND_ACC_PUBLIC )
723803 PHP_ME (vtiful_xls , insertUrl , xls_insert_url_arginfo , ZEND_ACC_PUBLIC )
724804 PHP_ME (vtiful_xls , insertImage , xls_insert_image_arginfo , ZEND_ACC_PUBLIC )
@@ -754,6 +834,11 @@ VTIFUL_STARTUP_FUNCTION(excel) {
754834 REGISTER_CLASS_PROPERTY_NULL (vtiful_xls_ce , V_XLS_COF , ZEND_ACC_PRIVATE );
755835 REGISTER_CLASS_PROPERTY_NULL (vtiful_xls_ce , V_XLS_FIL , ZEND_ACC_PRIVATE );
756836
837+ REGISTER_CLASS_CONST_LONG (vtiful_xls_ce , V_XLS_CONST_READ_TYPE_INT , READ_TYPE_INT );
838+ REGISTER_CLASS_CONST_LONG (vtiful_xls_ce , V_XLS_CONST_READ_TYPE_DOUBLE , READ_TYPE_DOUBLE );
839+ REGISTER_CLASS_CONST_LONG (vtiful_xls_ce , V_XLS_CONST_READ_TYPE_STRING , READ_TYPE_STRING );
840+ REGISTER_CLASS_CONST_LONG (vtiful_xls_ce , V_XLS_CONST_READ_TYPE_DATETIME , READ_TYPE_DATETIME );
841+
757842 return SUCCESS ;
758843}
759844/* }}} */
0 commit comments