因为需要将一个很大的excel按500条拆分为多个excel,手工操作实在太麻烦,就写了个python小脚本,现在是分为了多个sheet页,使用者可根据自己实际情况修改成多个文件的形式
#!/usr/bin/python# -*- coding:utf-8 -*-import xlrdimport xlwtlimit = raw_input('input limit number:')readbook = raw_input('input excel read path:')savebook = raw_input('input excel save path:')if limit == '': limit = 100 # 默认按100条拆分print '拆分数量: ' + limitlimit = int(limit)# '/Users/huqiang/Desktop/shoplist.xls'data = xlrd.open_workbook(readbook)# 获取sheettable = data.sheets()[0]# 行数nrows = table.nrows# 列数ncols = table.ncolssheets = nrows / limit# print str(nrows) + ' ' + str(ncols)# print table.cell(nrows - 1, ncols - 1).valueworkbook = xlwt.Workbook(encoding='ascii')for i in range(0, sheets): worksheet = workbook.add_sheet(str(i)) for row in range(0, limit): row_content = table.row_values(row + (i * 10)) for col in range(0, ncols): worksheet.write(row, col, row_content[col])workbook.save(savebook)