python 2.7.5代码:
# coding=utf-8
import sys
import xlrd data=xlrd.open_workbook('D:\\menu.xls') table = data.sheet_by_name(u'肉食类') nrows_num = table.nrows ncols_num = table.ncols res=[] for nrows in range(nrows_num):
for ncols in range(ncols_num): cell_value = table.cell(nrows,ncols).value if cell_value=='':
cell_value='__'
res.append(cell_value)
elif isinstance(cell_value,unicode):
cell_value=cell_value.encode('gb2312')
res.append(cell_value)
elif isinstance(cell_value,float):
cell_value = str(cell_value)
cell_value = cell_value.decode('utf-8').encode('gb2312')
res.append(cell_value)
elif isinstance(cell_value,int):
cell_value = str(cell_value)
cell_value = cell_value.decode('utf-8').encode('gb2312')
res.append(cell_value)
res.append('|') res = ','.join(res)
res = res.split('|') for i in range(len(res)-1):
print '第',i+1,'行数据:',res[i].strip(',')
测试结果: