[python] 如何用python操作Excel
直接上代码:
1 from openpyxl import Workbook 2 from openpyxl.cell import get_column_letter 3 4 wb = Workbook() 5 dest_filename = r'empty_book.xlsx' #file name 6 ws = wb.worksheets[0] #the first sheet 7 ws.title = "range names" #first sheet name 8 for col_idx in xrange(1, 40): 9 col = get_column_letter(col_idx) #change the number into characters 10 for row in xrange(1, 600): 11 ws.cell('%s%s'%(col, row)).value = '%s%s' % (col, row) # write the content in excel 12 13 wb.save(filename = dest_filename)
安装好第三方库之后,直接开始用就行。This is an example about how to write content in an excel.