Is there any way to read an XLS file and manipulate it in Python?

Asked

Viewed 1,014 times

1

Is there any way to read an XLS file and manipulate it in Python? Does any library allow this?

  • 1

    There are several forms, for example https://blogs.harvard.edu/rprasad/2014/06/16/reading-excel-with-python-xlrd/

1 answer

2


import xlrd

def xlread(arq_xls):
    """
    Gerador que le arquivo .xls
    """

    # Abre o arquivo
    xls = xlrd.open_workbook(arq_xls)
    # Pega a primeira planilha do arquivo
    plan = xls.sheets()[0]

    # Para i de zero ao numero de linhas da planilha
    for i in xrange(plan.nrows):
        # Le os valores nas linhas da planilha
        yield plan.row_values(i)

for linha in xlread('test.xls'):
    print (linha)

Pip install xlrd

  • 2

    I think you should add more details to your answers. I notice that some answers are being published only with code. It would be interesting for example, you explain what the stretch is for plan = xls.sheets()[0].

Browser other questions tagged

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