Created
April 15, 2020 10:23
-
-
Save rxwx/0e186f4102a108f4b0bcdaedcecb8106 to your computer and use it in GitHub Desktop.
Get Office version that last saved the file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | |
sys.exit(1) | |
with open(sys.argv[1], 'rb') as f: | |
content = f.read() | |
if(content[0:4] != '\xD0\xCF\x11\xE0'): | |
print "File is not an MS-XLS (CDF) file" | |
sys.exit(1) | |
m = re.search(b'\xCD\x07[\x00-\xff]{3}\x00\x06([\x00-\xff])\x00\x00', content) | |
if m is None: | |
print "No version info found" | |
sys.exit(1) | |
v = ord(m.group(1)) | |
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