-
-
Save Jazzis18/1cea8444fede2cd11c893845804cd280 to your computer and use it in GitHub Desktop.
convert from xls to xlsx using xlrd and openpyxlfound at http://stackoverflow.com/questions/9918646/how-to-convert-xls-to-xlsx
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 xlrd | |
from openpyxl.workbook import Workbook | |
from openpyxl.reader.excel import load_workbook, InvalidFileException | |
def open_xls_as_xlsx(filename): | |
# first open using xlrd | |
book = xlrd.open_workbook(filename) | |
index = 0 | |
nrows, ncols = 0, 0 | |
while nrows * ncols == 0: | |
sheet = book.sheet_by_index(index) | |
nrows = sheet.nrows | |
ncols = sheet.ncols | |
index += 1 | |
# prepare a xlsx sheet | |
book1 = Workbook() | |
sheet1 = book1.get_active_sheet() | |
for row in xrange(0, nrows): | |
for col in xrange(0, ncols): | |
sheet1.cell(row=row+1, column=col+1).value = sheet.cell_value(row, col) | |
return book1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that in the current version of the openpyxl row or column index must start with 1.