0

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.

enter image description here

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:

ÐÏࡱ
Ricardo Altamirano
  • 14,650
  • 21
  • 72
  • 105
Filipe Manuel
  • 967
  • 2
  • 14
  • 33
  • What are you using to load your excel file, or are you just using python's open()? .xls files cannot be read directly as strings since they are a binary, proprietary format... – troy.unrau Jul 31 '12 at 18:46

2 Answers2

1

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.

GWW
  • 43,129
  • 11
  • 115
  • 108
0

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

Community
  • 1
  • 1
monknomo
  • 540
  • 8
  • 26