diff --git a/xlsxwriter.class.php b/xlsxwriter.class.php
index cc8c15112..76868cf00 100644
--- a/xlsxwriter.class.php
+++ b/xlsxwriter.class.php
@@ -365,9 +365,19 @@ protected function writeCell(XLSXWriter_BuffererWriter &$file, $row_number, $col
} elseif (is_string($value) && $value{0}=='='){
$file->write(''.self::xmlspecialchars($value).'');
} elseif ($num_format_type=='n_date') {
- $file->write(''.intval(self::convert_date_time($value)).'');
+ $dateValue = self::convert_date_time($value);
+ if ($dateValue > 0 || preg_match("/(\d+):(\d{2}):(\d{2})/", $value)) {
+ $file->write(''.intval($dateValue).'');
+ } else { //not date, treat it as string
+ $file->write(''.self::xmlspecialchars($value).'');
+ }
} elseif ($num_format_type=='n_datetime') {
- $file->write(''.self::convert_date_time($value).'');
+ $dateValue = self::convert_date_time($value);
+ if ($dateValue > 0 || preg_match("/(\d+):(\d{2}):(\d{2})/", $value)) {
+ $file->write(''.$dateValue.'');
+ } else { //not datetime, treat it as string
+ $file->write(''.self::xmlspecialchars($value).'');
+ }
} elseif ($num_format_type=='n_numeric') {
if (!is_string($value) || $value=='0' || ($value[0]!='0' && ctype_digit($value)) || preg_match("/^\-?(0|[1-9][0-9]*)?(\.[0-9]+)?$/", $value)){
$file->write(''.self::xmlspecialchars($value).'');//int,float,currency