Diferències
Ací es mostren les diferències entre la revisió seleccionada i la versió actual de la pàgina.
| Ambdós costats versió prèvia Revisió prèvia Següent revisió | Revisió prèvia | ||
| info:cursos:python:openpyxl [08/10/2021 02:06] – mate | info:cursos:python:openpyxl [10/06/2022 02:28] (actual) – [Curso python + openpyxl (excel)] mate | ||
|---|---|---|---|
| Línia 1: | Línia 1: | ||
| = Curso python + openpyxl (excel) | = Curso python + openpyxl (excel) | ||
| + | {{tag> | ||
| * udemy | * udemy | ||
| * [[https:// | * [[https:// | ||
| Línia 70: | Línia 71: | ||
| == 4.Reading and Writing Column and later Grid in a Sheet | == 4.Reading and Writing Column and later Grid in a Sheet | ||
| + | <code python> | ||
| + | for i in range(1, | ||
| + | e=sheet.cell(row=j, | ||
| + | print(e.value) | ||
| + | | ||
| + | lista = [] | ||
| + | for i in range(1,5): | ||
| + | e=sheet.cell(row=i, | ||
| + | lista.append(e.value) | ||
| + | | ||
| + | wb2=openpyxl.load_workbook(' | ||
| + | sheet2=wb2.get_sheet_by_name(' | ||
| + | for i in range(0, | ||
| + | e=sheet2.cell(row=10+i, | ||
| + | e.value=listb[i] | ||
| + | | ||
| + | wb2.save(' | ||
| + | </ | ||
| + | <code python> | ||
| + | ### define 2D list | ||
| + | rows=6 | ||
| + | columns=4 | ||
| + | lista=[] | ||
| + | for i in range(1, | ||
| + | lista.append([]) # add list into a list | ||
| + | |||
| + | # read data | ||
| + | for r in range(1, | ||
| + | for c in range(1, | ||
| + | e=sheet.cell(row=r, | ||
| + | lista[r-1].append(e.value) | ||
| + | |||
| + | # write data | ||
| + | for r in range(1, | ||
| + | for c in range(1, | ||
| + | j=sheet2.cell(row=r, | ||
| + | j.value=lista[r-1][c-1] | ||
| + | | ||
| + | # save | ||
| + | </ | ||