I have an Excel file (.xls) with many lines (1008), and I'm looking for lines that have anything with 2010.
For example, there is a line that contains 01/06/2010, so this line would be deleted, leaving the cell blank.
For this example, all of these would be deleted. I tried at least reading the file, but I got an ugly error:
def Pesquisar():
nomeArquivo = open('D:/file.xls', 'r')
for palavraArquivo in nomeArquivo.readlines():
print palavraArquivo
Result:
ÐÏࡱ
You can't directly read an excel file since it's not a standard text file. You need to use a third party library such as xlrd. Another option would be to export the xls file as a csv file or tab delimited format and then parse them as a text file with python.
Excel files use a special format that doesn't lend itself to plain text parsing.
This discussion might point you in the right direction, as far as libraries for handling .xls formats go: Reading/parsing Excel (xls) files with Python