xlrd opens files in xls format?

Asked

Viewed 2,078 times

1

excuse my ignorance on the subject, but I’m developing a Python script that reads Excel files to get certain information on these, and for that I’m using xlrd, I was wondering if xlrd is able to read xls files as well, which is a user format by older Excel, someone could help me on that?

1 answer

2


Good morning, all right?

As it says in the presentation of this page below, it is possible yes. I believe that there is no difference at least of the basic part between . xls and . xlsx with xlrd

XLRD Download

It would look like this:

import xlrd #importando a biblioteca

workbook = xlrd.open_workbook('teste.xls') # Escolhe o arquivo a ser lido.

worksheet = workbook.sheet_by_index(0) #Escolha a aba a ser lida. 

for i in range(worksheet.nrows): #itere sobre os itens da aba 
    print(worksheet.row(i))

In my case, with this input spreadsheet :

inserir a descrição da imagem aqui

I have the following output, containing the type of the value.

inserir a descrição da imagem aqui

For more information some links.

Reading xls with python

Github library page

Reading data from a spreadsheet and sending a warning email XLRD + SMTPLIB

Hug.

  • Thanks friend, clear and direct example that I was passed by you, however I have another doubt, in case it has as I know through some function the number of "Sheets" present in the document? Thank you for your attention!

  • Hey, no problem at all. I already used the Workbook.sheet_names() function, it lists the sheet names, if you store in a variable, Voce can use the Len(namesake) function and check how many items there are in it. Hug

  • Thanks for the clarification!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.