python 将数据保存为excel的xls格式

#引入xlwt模块(提前pip下载好)

import xlwt

#使用workbook方法,创建一个新的工作簿

book = xlwt.Workbook(encoding='utf-8',style_compression=0)

#添加一个sheet,名字为mysheet,参数overwrite就是说可不可以重复写入值,就是当单元格已经非空,你还要写入

sheet = book.add_sheet('mysheet',cell_overwrite_ok=True)

#接着就是给指定的单元格写入数据了

sheet.write(0,0,'myText')

#记住要保存

book.save('/Users/Kingsley/Desktop/test.xls')

猜你喜欢

转载自blog.csdn.net/u010397980/article/details/82217689