python 将数据写入excel

参考博客:
https://www.cnblogs.com/liuyang92/p/7492336.html
https://www.cnblogs.com/lhj588/archive/2012/01/06/2314181.html
https://www.cnblogs.com/liuyang92/p/7492336.html
https://www.cnblogs.com/jiangzhaowei/p/5857904.html
我自己写的一段代码:

#打开excel文件读取数据
data = xlrd.open_workbook('source_aa.xls',formatting_info=True)

#通过索引顺序获取:但是通过sheet_by_index获取的sheet没有write()方法
table = data.sheet_by_index(0)

#写入的另外一个文件
workbook = xlwt.Workbook(encoding='utf-8')
data_sheet = workbook.add_sheet('demo1')



for rowIndex in range(0,table.nrows):
    for colIndex in range(0,table.ncols):
        if '1' in str(table.cell(rowIndex, 0).value):
            print('.....')
            break
        data_sheet.write(rowIndex, colIndex, table.cell(rowIndex, colIndex).value)


workbook.save('demo7.xls')

猜你喜欢

转载自blog.csdn.net/a2011480169/article/details/78483140