python openpyxl实现添加读写操作(主要针对xlsx格式)

from openpyxl import Workbook
from openpyxl.compat import range
from openpyxl.utils import get_column_letter

dest_filename = 'empty_book1.xlsx'

wb = Workbook()
ws1 = wb.active
ws1.title = "range names"
for row in range(1, 40):
   ws1.append(range(600))

ws3 = wb.create_sheet(title="Data")
for row in range(10, 20):
   for col in range(27, 54):
       _ = ws3.cell(column=col, row=row, value="%s" % get_column_letter(col))
print(ws3['AA10'].value)
wb.save(filename = dest_filename)

sheet_ranges = wb['range names']
print(sheet_ranges['D18'].value)

ws3.cell(column=27,row=11,value='aaa')
wb.save(filename = dest_filename)


你可能感兴趣的:(python)