![[python] 如何用python操作Excel [python] 如何用python操作Excel](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
直接上代码:
from openpyxl import Workbook
from openpyxl.cell import get_column_letter wb = Workbook()
dest_filename = r'empty_book.xlsx' #file name
ws = wb.worksheets[0] #the first sheet
ws.title = "range names" #first sheet name
for col_idx in xrange(1, 40):
col = get_column_letter(col_idx) #change the number into characters
for row in xrange(1, 600):
ws.cell('%s%s'%(col, row)).value = '%s%s' % (col, row) # write the content in excel wb.save(filename = dest_filename)
安装好第三方库之后,直接开始用就行。This is an example about how to write content in an excel.