@@ -365,9 +365,19 @@ protected function writeCell(XLSXWriter_BuffererWriter &$file, $row_number, $col
365
365
} elseif (is_string ($ value ) && $ value {0 }=='= ' ){
366
366
$ file ->write ('<c r=" ' .$ cell_name .'" s=" ' .$ cell_style_idx .'" t="s"><f> ' .self ::xmlspecialchars ($ value ).'</f></c> ' );
367
367
} elseif ($ num_format_type =='n_date ' ) {
368
- $ file ->write ('<c r=" ' .$ cell_name .'" s=" ' .$ cell_style_idx .'" t="n"><v> ' .intval (self ::convert_date_time ($ value )).'</v></c> ' );
368
+ $ dateValue = self ::convert_date_time ($ value );
369
+ if ($ dateValue > 0 || preg_match ("/(\d+):(\d{2}):(\d{2})/ " , $ value )) {
370
+ $ file ->write ('<c r=" ' .$ cell_name .'" s=" ' .$ cell_style_idx .'" t="n"><v> ' .intval ($ dateValue ).'</v></c> ' );
371
+ } else { //not date, treat it as string
372
+ $ file ->write ('<c r=" ' .$ cell_name .'" s=" ' .$ cell_style_idx .'" t="inlineStr"><is><t> ' .self ::xmlspecialchars ($ value ).'</t></is></c> ' );
373
+ }
369
374
} elseif ($ num_format_type =='n_datetime ' ) {
370
- $ file ->write ('<c r=" ' .$ cell_name .'" s=" ' .$ cell_style_idx .'" t="n"><v> ' .self ::convert_date_time ($ value ).'</v></c> ' );
375
+ $ dateValue = self ::convert_date_time ($ value );
376
+ if ($ dateValue > 0 || preg_match ("/(\d+):(\d{2}):(\d{2})/ " , $ value )) {
377
+ $ file ->write ('<c r=" ' .$ cell_name .'" s=" ' .$ cell_style_idx .'" t="n"><v> ' .$ dateValue .'</v></c> ' );
378
+ } else { //not datetime, treat it as string
379
+ $ file ->write ('<c r=" ' .$ cell_name .'" s=" ' .$ cell_style_idx .'" t="inlineStr"><is><t> ' .self ::xmlspecialchars ($ value ).'</t></is></c> ' );
380
+ }
371
381
} elseif ($ num_format_type =='n_numeric ' ) {
372
382
if (!is_string ($ value ) || $ value =='0 ' || ($ value [0 ]!='0 ' && ctype_digit ($ value )) || preg_match ("/^\-?(0|[1-9][0-9]*)?(\.[0-9]+)?$/ " , $ value )){
373
383
$ file ->write ('<c r=" ' .$ cell_name .'" s=" ' .$ cell_style_idx .'" t="n"><v> ' .self ::xmlspecialchars ($ value ).'</v></c> ' );//int,float,currency
0 commit comments