Skip to content

Instantly share code, notes, and snippets.

Created Apr 15, 2020
What would you like to do?
Get Office version that last saved the file
import re
import sys
versions = {
0x00: 'Excel 97',
0x01: 'Excel 2000',
0x02: 'Excel 2002',
0x03: 'Office Excel 2003',
0x04: 'Office Excel 2007',
0x06: 'Excel 2010',
0x07: 'Excel 2013',
0x08: 'Excel 2016 (or higher)'
if(len(sys.argv) != 2):
print " Usage: %s <file>" % sys.argv[0]
with open(sys.argv[1], 'rb') as f:
content =
if(content[0:4] != '\xD0\xCF\x11\xE0'):
print "File is not an MS-XLS (CDF) file"
m ='\xCD\x07[\x00-\xff]{3}\x00\x06([\x00-\xff])\x00\x00', content)
if m is None:
print "No version info found"
v = ord(
print "Version: %s" % versions.get(v, 'Unknown (0x%02x)' % v)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment