xls.save(file_name)
使用xlwt
代码如下:
# -*- coding: utf-8 -*-
'''
Created on 2012-12-14
@author: walfred
@module: XLRDPkg.write
@description:
'''
import xlwt as ExcelWrite
def writeXLS(file_name):
value = [["name", "jim", "hmm", "lilei"], ["sex", "man", "woman", "man"], ["age", 19, 24, 24], ["country", "USA", "CHN", "CHN"]]
xls = ExcelWrite.Workbook()
sheet = xls.add_sheet("Sheet1")
for i in range(0, 4):
for j in range(0, len(value)):
sheet.write(j, i, value[i][j])
xls.save(file_name)
if __name__ == "__main__":
writeXLS("./test_write.xls");
当然这只是简单的介绍下如何使用xlwt,更多功能个API需要读者自行从下载包中学习,比如设置格式、超链接、公式等。