Skip to content

Instantly share code, notes, and snippets.



Created Feb 18, 2015
What would you like to do?
Simple script to convert an Excel file to MediaWiki format
import sys
import xlrd
if __name__ == '__main__':
if not len(sys.argv) > 1:
sys.exit("Usage: xl2wiki infile.xls [outfile]")
# Read it in and build up a string in the mediawiki format
book = xlrd.open_workbook(sys.argv[1])
s = u""
# Loop over all sheets
for sheet in book.sheets():
s += u"=={}==\n".format(
s += u'{| class="wikitable"\n'
for row_index in xrange(sheet.nrows):
s += u"|-\n"
for col_index in xrange(sheet.ncols):
s += u"| {}\n".format(sheet.cell(row_index, col_index).value)
s += u'|}\n'
# Save it or print it
if len(sys.argv) == 3:
with open(sys.argv[2], 'w') as f:
print s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment