一、文件读取
import xlwt
import xlrd
class File( object ):
#读取文件的路径,sheet页,以及列的索引--比如第一列就是0,第二列就是1
def read_excel( self, read_file_path, sheet, num ):
wd = xlrd.open_workbook( read_file_path )
sheet = wd.sheet_by_name( sheet )
check_list = []
for a in range( sheet.nrows ):
#循环读取每一行
cells = sheet.row_values(a)
#获取每一行的指定列的数据
data = cells[ num ]
#如果内容为空,就用none填充
if data == '':
check_list.append( 'none' )
else:
check_list.append( data )
self.new = list( filter(None, check_list) )
#返回每一行,指定列的list
return self.new
二、文件写入
def write_excel( self, excel_path = 'test.xls' ):
workbook = xlwt