本文介绍了什么表示Office Open XML单元格包含日期/时间值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在使用 Office Open XML SDK ,并且对于读取Date / Time值感到困惑。我的一个电子表格有这个标记(由Excel 2010生成) < x:row r =2spans = 1:22xmlns:x =http://schemas.openxmlformats.org/spreadsheetml/2006/main> < x:c r =A2t =s> < x:v> 56< / x:v> < / x:c> < x:c r =B2t =s> < x:v> 64< / x:v> < / x:c> 。 。 。 < x:c r =J2s =9> < x:v> 17145< / x:v> < / x:c> Cell J2中有一个日期序列值,一个样式属性 s = 9。然而,Office Open XML规范说,9对应于一个跟随的超链接。这是从ECMA-376,第二版,第1部分 - 基础和标记语言参考.pdf 的第4,999页的屏幕截图。 包含的presetCellStyles.xml文件规范也是指 builtinId 9作为跟随的超链接。 followHyperlink builtinId =9> 规范中的所有样式都只是视觉格式化样式,而不是数字样式。定义数字样式在哪里,以及如何区分样式引用 s =9指示单元格格式(视觉)样式与数字样式? 显然,我在错误的地方找到与数字格式的单元格匹配的样式。找到这些信息的地方在哪里?解决方案 s属性引用了styles.xml中的一个样式xf条目。样式xf依次引用数字格式掩码。要识别包含日期的单元格,您需要执行样式xf - >数字格式查找,然后识别该数字格式掩码是日期/时间数字格式掩码(而不是例如百分比或记帐号格式掩码)。 style.xml文件具有以下元素: xf numFmtId =14... applyNumberFormat =1/> < xf numFmtId =1... applyNumberFormat =1/> 这些是xf条目,依次为您提供引用数字格式掩码的numFmtId。 / p> 您应该在style.xml顶部附近找到numFmts部分,作为styleSheet元素的一部分 <?xml version =1.0encoding =UTF-8standalone =yes?> < styleSheet xmlns =http://schemas.openxmlformats.org/spreadsheetml/2006/main> < numFmts count =3> < numFmt numFmtId =164formatCode =[$ - 414] mmmm\ yyyy; @/> < numFmt numFmtId =165formatCode =0.000/> < numFmt numFmtId =166formatCode =#,## 0.000/> < / numFmts> 数字格式id可能在这里,或者它可能是内置格式之一。数字格式代码(numFmtId)小于164是内置。 我的列表不完整: 0 ='常规'; 1 ='0'; 2 ='0.00'; 3 ='#,## 0'; 4 ='#,## 0.00'; 9 ='0%'; 10 ='0.00%'; 11 ='0.00E + 00'; 12 ='#?/?'; 13 ='#?? / ??'; 14 ='mm-dd-yy'; 15 ='d-mmm-yy'; 16 ='d-mmm'; 17 ='mmm-yy'; 18 ='h:mm AM / PM'; 19 ='h:mm:ss AM / PM'; 20 ='h:mm'; 21 ='h:mm:ss'; 22 ='m / d / yy h:mm'; 37 ='#,## 0;(#,## 0)'; 38 ='#,## 0; [Red](#,## 0)'; 39 ='#,## 0.00;(#,## 0.00)'; 40 ='#,## 0.00; [Red](#,## 0.00)'; 44 ='_($*#,## 0.00 _); _($* \(#,## 0.00\); _($* - ?? _); _(@_)'; 45 ='mm:ss'; 46 ='[h]:mm:ss'; 47 ='mmss .0'; 48 ='## 0.0E + 0'; 49 ='@'; 27 ='[$ -404] e / m / d '; 30 ='m / d / yy'; 36 ='[$ -404] e / m / d'; 50 ='[$ -404] e / / d'; 57 ='[$ -404] e / m / d'; 59 ='t0'; 60 ='t0.00'; 61 ='t#,## 0'; 62 ='t#,## 0.00'; 67 ='t0%'; 68 ='t0.00 %'; 69 ='t#?/?'; 70 ='t#?? / ??'; 缺少的值主要与东亚变体格式相关。 I'm reading an .xlsx file using the Office Open XML SDK and am confused about reading Date/Time values. One of my spreadsheets has this markup (generated by Excel 2010)<x:row r="2" spans="1:22" xmlns:x="http://schemas.openxmlformats.org/spreadsheetml/2006/main"> <x:c r="A2" t="s"> <x:v>56</x:v> </x:c> <x:c r="B2" t="s"> <x:v>64</x:v> </x:c> . . . <x:c r="J2" s="9"> <x:v>17145</x:v> </x:c>Cell J2 has a date serial value in it and a style attribute s="9". However, the Office Open XML Specification says that 9 corresponds to a followed hyperlink. This is a screen shot from page 4,999 of ECMA-376, Second Edition, Part 1 - Fundamentals And Markup Language Reference.pdf.The presetCellStyles.xml file included with the spec also refers to builtinId 9 as a followed hyperlink.<followedHyperlink builtinId="9">All of the styles in the spec are simply visual formatting styles, not number styles. Where are the number styles defined and how does one differentiate a style reference s="9" from indicating a cell formatting (visual) style vs a number style?Obviously I'm looking in the wrong place to match styles on cells with their number formats. Where's the right place to find this information? 解决方案 The s attribute references a style xf entry in styles.xml. The style xf in turn references a number format mask. To identify a cell that contains a date, you need to perform the style xf -> numberformat lookup, then identify whether that numberformat mask is a date/time numberformat mask (rather than, for example, a percentage or an accounting numberformat mask).The style.xml file has elements like:<xf numFmtId="14" ... applyNumberFormat="1" /><xf numFmtId="1" ... applyNumberFormat="1" />These are the xf entries, which in turn give you a numFmtId that references the number format mask.You should find the numFmts section somewhere near the top of style.xml, as part of the styleSheet element<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"> <numFmts count="3"> <numFmt numFmtId="164" formatCode="[$-414]mmmm\ yyyy;@" /> <numFmt numFmtId="165" formatCode="0.000" /> <numFmt numFmtId="166" formatCode="#,##0.000" /> </numFmts>The number format id may be here, or it may be one of the built-in formats. Number format codes (numFmtId) less than 164 are "built-in".The list that I have is incomplete:0 = 'General';1 = '0';2 = '0.00';3 = '#,##0';4 = '#,##0.00';9 = '0%';10 = '0.00%';11 = '0.00E+00';12 = '# ?/?';13 = '# ??/??';14 = 'mm-dd-yy';15 = 'd-mmm-yy';16 = 'd-mmm';17 = 'mmm-yy';18 = 'h:mm AM/PM';19 = 'h:mm:ss AM/PM';20 = 'h:mm';21 = 'h:mm:ss';22 = 'm/d/yy h:mm';37 = '#,##0 ;(#,##0)';38 = '#,##0 ;[Red](#,##0)';39 = '#,##0.00;(#,##0.00)';40 = '#,##0.00;[Red](#,##0.00)';44 = '_("$"* #,##0.00_);_("$"* \(#,##0.00\);_("$"* "-"??_);_(@_)';45 = 'mm:ss';46 = '[h]:mm:ss';47 = 'mmss.0';48 = '##0.0E+0';49 = '@';27 = '[$-404]e/m/d';30 = 'm/d/yy';36 = '[$-404]e/m/d';50 = '[$-404]e/m/d';57 = '[$-404]e/m/d';59 = 't0';60 = 't0.00';61 = 't#,##0';62 = 't#,##0.00';67 = 't0%';68 = 't0.00%';69 = 't# ?/?';70 = 't# ??/??';The missing values are mainly related to east asian variant formats. 这篇关于什么表示Office Open XML单元格包含日期/时间值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-02 10:06