问题
I have a spreadsheet that when i open in excel the cells in question show formatting as date mm-dd-yyyy.
When I run this through php excel reader (xlsx file) it does not recognize that it is a date.
I opened the file in ms open xml sdk and it shows in the styles for numFmts
numFmtId="102" formatCode="mm-dd-yyyy"
numFmtId="104" formatCode="mm-dd-yyyy"
numFmtId="106" formatCode="mm-dd-yyyy"
numFmtId="108" formatCode="mm-dd-yyyy"
numFmtId="110" formatCode="mm-dd-yyyy"
numFmtId="112" formatCode="mm-dd-yyyy"
numFmtId="114" formatCode="mm-dd-yyyy"
numFmtId="116" formatCode="mm-dd-yyyy"
numFmtId="118" formatCode="mm-dd-yyyy"
It would only convert to date after I added
self::$_builtInFormats[102] = 'mm-dd-yyyy';
self::$_builtInFormats[104] = 'mm-dd-yyyy';
self::$_builtInFormats[106] = 'mm-dd-yyyy';
self::$_builtInFormats[108] = 'mm-dd-yyyy';
self::$_builtInFormats[110] = 'mm-dd-yyyy';
self::$_builtInFormats[112] = 'mm-dd-yyyy';
self::$_builtInFormats[114] = 'mm-dd-yyyy';
self::$_builtInFormats[116] = 'mm-dd-yyyy';
self::$_builtInFormats[118] = 'mm-dd-yyyy';
to NumberFormat.php.
Is this supposed to be the case
回答1:
MS Excel uses format codes 0 to 163 for "built-in" formats, but there are a lot of unused entries in this set, and nothing is officially defined for format codes 102 to 118. The codes listed as built-in in the PHPExcel PHPExcel_Style_NumberFormat
class are all the main built-ins, only ignoring a few special localised formats for Chinese/Korean/Thai/Japanese localised.
However, this restriction doesn't prevent a lot of naughty homebrew xlsx writers from using "reserved" id values that aren't actually defined in the ISO specification.
Typically, these values should be defined in the /xl/styles.xml
file in a block looking like:
<numFmts count="2">
<numFmt formatCode="mm-dd-yyyy" numFmtId="102"/>
<numFmt formatCode="mm-dd-yyyy" numFmtId="104"/>
...
</numFmts>
While the latest production release of PHPExcel adheres to the ISO standard, and ignores any values below 164 unless they are explicitly defined in the formal specification (ie uses only values in the built-in list), a change has been made in the 1.8 branch to "tolerate" this misuse of the standard, and the code will read user-defined number format values below 164 unless they over-ride a value defined in the standard.
来源:https://stackoverflow.com/questions/34623488/phpexcel-number-formats-for-dates