Openpyxl - SyntaxError: invalid character in identifier

0

With the following script I try to get the data from a range of cells:

wb=openpyxl.load_workbook('testfile.xlsx')
sheet = wb.get_sheet_by_name('Hoja1')
# Imprimir un rango 
multiple_cells = sheet['A1':'C20']
for row in multiple_cells:
    for cell in row:
        print cell.value

When I run it, I get the error:

File "E:/Python/Openpyxl/Practicas_openpyxl.py", line 43
    for cell in row:
    ^
SyntaxError: invalid character in identifier

I can not tell where the fault is.

On the other hand, is it possible to give a variable name to the imported range and convert it into a DataFrame? How could I do it?

    
asked by efueyo 15.12.2017 в 20:39
source

1 answer

0

I work with Anaconda3 and Spyder. I store the files as python files. Regarding the first question, it was solved as follows:

  

select a range

     

seleccion = sheet ['A1': 'B23']   for rows in selection:       for columns in rows:           print (columns.value)

As for the second question, there is a previous answer, a question also mine, which in principle serves me. You can find it in the link:

Pass the data of a list to a spreadsheet, by means of two cells of the sheet - Python

Thanks

    
answered by 15.12.2017 в 22:20