Diferències
Ací es mostren les diferències entre la revisió seleccionada i la versió actual de la pàgina.
| Següent revisió | Revisió prèvia | ||
| info:cursos:python:openpyxl [08/10/2021 00:46] – creat 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:// | ||
| == 2.Python - Working with Sheet | == 2.Python - Working with Sheet | ||
| Línia 21: | Línia 23: | ||
| sheet.max_column | sheet.max_column | ||
| sheet.title=' | sheet.title=' | ||
| - | sheet.save(' | + | wb.save(' |
| </ | </ | ||
| + | |||
| + | <code python> | ||
| + | wb.create_sheet(index=< | ||
| + | |||
| + | std=wd.get_sheet_by_name(' | ||
| + | wb.remove_sheet(std) | ||
| + | |||
| + | wb.save(' | ||
| + | </ | ||
| + | |||
| + | <code python> | ||
| + | sheet=wb.get_sheet_by_name(' | ||
| + | sheet[' | ||
| + | sheet[' | ||
| + | |||
| + | e=sheet[' | ||
| + | e.value | ||
| + | e.row | ||
| + | e.column | ||
| + | e.value=' | ||
| + | |||
| + | e=sheet.cell(row=2, | ||
| + | |||
| + | wb.save(' | ||
| + | </ | ||
| + | |||
| + | == 3.Reading and Writing Rows in Excel | ||
| <code python> | <code python> | ||
| for i in range(1, | for i in range(1, | ||
| Línia 32: | Línia 61: | ||
| e=sheet.cell(row=5, | e=sheet.cell(row=5, | ||
| lista.append(e.value) | lista.append(e.value) | ||
| + | </ | ||
| + | <code python> | ||
| + | for i in range(0, | ||
| + | e=sheet.cell(row=10, | ||
| + | e.value=list[i] | ||
| + | | ||
| + | wb.save(' | ||
| </ | </ | ||
| + | == 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 | ||
| - | == 3.Reading and Writing Rows in Excel | + | # 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 | ||
| + | </ | ||