@@ -884,8 +884,9 @@ private function formatValue($value, $format_index)
884884 $ seconds = (int ) round ($ time * 86400 , 0 );
885885 }
886886
887+ $ original_value = $ value ;
887888 $ value = clone self ::$ base_date ;
888- if ($ days < 0 ) {
889+ if ($ original_value < 0 ) {
889890 // Negative value, subtract interval
890891 $ days = abs ($ days ) + 1 ;
891892 $ seconds = abs ($ seconds );
@@ -1207,10 +1208,23 @@ private function initStyles(ZipArchive $zip)
12071208 if (!$ current_scope_is_cell_xfs || $ styles_reader ->isClosingTag ()) {
12081209 break ;
12091210 }
1210- if ($ styles_reader ->getAttributeNsId ('applyNumberFormat ' )) {
1211+
1212+ // Determine if number formatting is set for this cell.
1213+ $ num_fmt_id = null ;
1214+ if ($ styles_reader ->getAttributeNsId ('numFmtId ' )) {
1215+ $ applyNumberFormat = $ styles_reader ->getAttributeNsId ('applyNumberFormat ' );
1216+ if ($ applyNumberFormat === null || $ applyNumberFormat === '1 ' || $ applyNumberFormat === 'true ' ) {
1217+ /* Number formatting is enabled either implicitly ('applyNumberFormat' not given)
1218+ * or explicitly ('applyNumberFormat' is a true value). */
1219+ $ num_fmt_id = (int ) $ styles_reader ->getAttributeNsId ('numFmtId ' );
1220+ }
1221+ }
1222+
1223+ // Determine and store correct formatting style.
1224+ if ($ num_fmt_id !== null ) {
12111225 // Number formatting has been enabled for this format.
12121226 // If format ID >= 164, it is a custom format and should be read from styleSheet\numFmts
1213- $ this ->styles [] = ( int ) $ styles_reader -> getAttributeNsId ( ' numFmtId ' ) ;
1227+ $ this ->styles [] = $ num_fmt_id ;
12141228 } else if ($ styles_reader ->getAttributeNsId ('quotePrefix ' )) {
12151229 // "quotePrefix" automatically preceeds the cell content with a ' symbol. This enforces a text format.
12161230 $ this ->styles [] = false ; // false = "Do not format anything".
0 commit comments