티스토리 뷰

[엑셀 쓰기]


from openpyxl import Workbook
import datetime

wb = Workbook()
ws = wb.active
ws['A1'] = 42
ws.append([1, 2, 3])
ws['A3'] = datetime.datetime.now()
wb.save("sample.xlsx")





[엑셀 읽기]



from openpyxl import Workbook
from openpyxl import load_workbook

wb = load_workbook(filename='sample.xlsx')
name_sheet = 'Sheet'
if name_sheet in wb:
sheet = wb[name_sheet]
multiple_cells = sheet['A1':'C3']
for row in multiple_cells:
for cell in row:
print(cell.value)
else:
print("{} does not exist".format(name_sheet))

댓글