On 05/21/2017 09:45 AM, Alexandre Goncalves wrote:
> Sorry, but i can't build code to read.
> |
> #!/home/elaineluisdesouzagoncalves/anaconda3/bin/python3
> #
https://media.readthedocs.org/pdf/openpyxl/latest/openpyxl.pdf
> fromopenpyxl importload_workbook
>
> wb =load_workbook(filename
> ='/home/elaineluisdesouzagoncalves/Documents/dados2.xlsx')
> ws =wb['tab3']
>
> tlin =ws.max_row
> tcol =ws.max_column
>
> dados =list()
> tb =list()
>
> forlinhas inrange(tlin):
> forcolunas inrange(tcol):
> dados.append(ws.cell(row =tlin,column =tcol))
> tb.append(dados)
> dados =[]
> linhas +=1
> print(tb)
> |
> So i can't do code to wirte.
I have never used openpyxl before, so take the below as a rough example:
from openpyxl import Workbook
# Create a file and write to it
file_out = 'read_write_test.xlsx'
wb = Workbook()
ws1 = wb.active
ws1.title = 'Test'
for row_idx in range(1, 10):
for col_idx, val in enumerate(['one', 'two', 'three']):
ws1.cell(column=col_idx + 1, row=row_idx, value=val)
wb.save(file_out)
from openpyxl import load_workbook
# Open existing file and modify it.
file_in_out = 'read_write_test.xlsx'
wb = load_workbook(filename = file_in_out)
ws = wb.get_sheet_by_name('Test')
last_row = ws.max_row
for col_idx, val in enumerate(['one', 'two', 'three']):
ws.cell(column=col_idx + 1, row=last_row + 1, value=val)
wb.save(file_in_out)
--
Adrian Klaver
adrian...@aklaver.com