Convert date from excel in number format to date format python [duplicate]

from datetime import datetime excel_date = 42139 dt = datetime.fromordinal(datetime(1900, 1, 1).toordinal() + excel_date – 2) tt = dt.timetuple() print(dt) print(tt) As mentioned by J.F. Sebastian, this answer only works for any date after 1900/03/01 EDIT: (in answer to @R.K) If your excel_date is a float number, use this code: from datetime import datetime def … Read more

Converting a Python Float to a String without losing precision

I’m the author of xlrd. There is so much confusion in other answers and comments to rebut in comments so I’m doing it in an answer. @katriealex: “””precision being lost in the guts of xlrd””” — entirely unfounded and untrue. xlrd reproduces exactly the 64-bit float that’s stored in the XLS file. @katriealex: “””It may … Read more

Using Python, write an Excel file with columns copied from another Excel file [closed]

Here are some options to choose from: xlwt (writing xls files) xlrd (reading xls/xlsx files) openpyxl (reading/writing xlsx files) xlsxwriter (writing xlsx files) If you need to copy only data (without formatting information), you can just use any combination of these tools for reading/writing. If you have an xls file, you should go with xlrd+xlwt … Read more

Python xlwt – accessing existing cell content, auto-adjust column width

I just implemented a wrapper class that tracks the widths of items as you enter them. It seems to work pretty well. import arial10 class FitSheetWrapper(object): “””Try to fit columns to max size of any entry. To use, wrap this around a worksheet returned from the workbook’s add_sheet method, like follows: sheet = FitSheetWrapper(book.add_sheet(sheet_name)) The … Read more

Identifying Excel Sheet cell color code using XLRD package

Here is one way to handle this: import xlrd book = xlrd.open_workbook(“sample.xls”, formatting_info=True) sheets = book.sheet_names() print “sheets are:”, sheets for index, sh in enumerate(sheets): sheet = book.sheet_by_index(index) print “Sheet:”, sheet.name rows, cols = sheet.nrows, sheet.ncols print “Number of rows: %s Number of cols: %s” % (rows, cols) for row in range(rows): for col in … Read more

error: could not create ‘/Library/Python/2.7/site-packages/xlrd’: Permission denied

Try python setup.py install –user You shouldn’t use sudo as suggested above for two reasons: You’re allowing arbitrary untrusted code off the internet to be run as root Passing the –user flag to python setup.py install will install the package to a user-owned directory. Your normal non-root user won’t be able to access the files … Read more

Preserving styles using python’s xlrd,xlwt, and xlutils.copy

There are two parts to this. First, you must enable the reading of formatting info when opening the source workbook. The copy operation will then copy the formatting over. import xlrd import xlutils.copy inBook = xlrd.open_workbook(‘input.xls’, formatting_info=True) outBook = xlutils.copy.copy(inBook) Secondly, you must deal with the fact that changing a cell value resets the formatting … Read more