简体   繁体   English

如何检查Excel文件是2007还是2010 Office

[英]how to check whether excel file is of 2007 or 2010 office

i am using following code to differentiate excel file of 2003 and 2007 office. 我正在使用以下代码来区分2003和2007办公室的excel文件。

if (Extension == ".xls" || Extension == ".xlsx")
 {
 }

but now i also need to identify 2010 excel file. 但现在我还需要识别2010 Excel文件。 please suggest some solution. 请提出一些解决方案。

You're probably aware that .xlsx files (like all Office Open XML files) are actually .zip files that contain a set of inner files that describe the content. 您可能知道,.xlsx文件(如所有Office Open XML文件)实际上是.zip文件,其中包含一组描述内容的内部文件。 So here's where you go to find the version number of the program that saved the file: 因此,您可以在这里找到保存文件的程序的版本号:

Rename the .xlsx extension to .zip (when you're doing this programatically, you can skip that step, but it's helpful for demonstration). 将.xlsx扩展名重命名为.zip(以编程方式执行此操作时,可以跳过该步骤,但这对演示很有帮助)。 Open up the zipped structure contained in the file. 打开文件中包含的压缩结构。

You'll find a docProps directory inside, which contains a file called app.xml (open it). 您将在其中找到一个docProps目录,其中包含一个名为app.xml的文件(将其打开)。 You'll find something that looks like this: 您会发现以下内容:

<Properties>
  <Application>Microsoft Excel</Application>
  <DocSecurity>0</DocSecurity>
  <ScaleCrop>false</ScaleCrop>
  <HeadingPairs>
    <vt:vector size="2" baseType="variant">
      <vt:variant>
        <vt:lpstr>Worksheets</vt:lpstr>
      </vt:variant>
      <vt:variant>
        <vt:i4>3</vt:i4>
      </vt:variant>
    </vt:vector>
  </HeadingPairs>
  <TitlesOfParts>
    <vt:vector size="3" baseType="lpstr">
      <vt:lpstr>Sheet1</vt:lpstr>
      <vt:lpstr>Sheet2</vt:lpstr>
      <vt:lpstr>Sheet3</vt:lpstr>
    </vt:vector>
  </TitlesOfParts>
  <LinksUpToDate>false</LinksUpToDate>
  <SharedDoc>false</SharedDoc>
  <HyperlinksChanged>false</HyperlinksChanged>
  <AppVersion>14.0300</AppVersion>
</Properties>

See the <Application> tag? 请参阅<Application>标签? That tells you that it was saved in Excel (as opposed to, say Open Office). 这告诉你它已保存在Excel中(而不是Open Office)。 See the <AppVersion> tag? 看到<AppVersion>标签? That one has the version number you're looking for. 那个有您正在寻找的版本号。 Excel 2007 is version 12, and Excel 2010 is 14 (because using version number 13 would have jinxed the whole operation). Excel 2007是版本12,Excel 2010是14(因为使用版本号13将对整个操作进行jinxed)。 Excel 2013 is expected to be version 15. Excel 2013预期为版本15。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM