Usually for reading from Excel I suggest using xlrd, but xlrd does not support comments. Use the Excel COM object instead:
from win32com.client import Dispatch xl = Dispatch("Excel.Application") xl.Visible = True wb = xl.Workbooks.Open("Book1.xls") sh = wb.Sheets("Sheet1") comment = sh.Cells(1,1).Comment.Text()
But how to parse a comment:
comment = "2008:2#2009:4" d = {} for item in comment.split('#'): key, val = item.split(':') d[key] = val
Often Excel comments are in two lines, with the first line indicating who created the comment. If so, your code will look something like this:
comment = """Steven: 2008:2#2009:4""" _, comment = comment.split('\n') d = {} for item in comment.split('#'): key, val = item.split(':') d[key] = val
source share