文件"/>
python 读取 xls文件
import sys
import xlrd
#from xlrd import open_workbook
#import pandas as pd
import xlwt
file_path = 'D:\data\\gmy\\文学\\傲慢与偏见.xls'
file = pd.read_html(file_path)#获取.xls工作簿对象
'''
sheet_name = file.sheet_names()#获取所有工作表名称
print(sheet_name)sheet = file.sheet_by_index(1)#根据索引获取工作表对象
print(sheet)
sheet = file.sheet_by_name('Sheet1')#根据名称获取工作表对象
print(sheet)
print('------------')
rows = sheet.nrows#获取工作表行数
cols = sheet.ncols#获取工作表列数
print(rows)
print(cols)row = sheet.row_values(1)#获取工作表某一行的内容
print(row)cell = sheet.cell_value(0,1)#获取工作表某一单元格的内容
print(cell)
print('\n')
'''
def xls_pro(file, pro_file_com):file = xlrd.open_workbook(file)sheet_names = file.sheet_names()with open(pro_file_com, 'w', encoding = 'utf-8') as f1:for sheet_name in sheet_names:sheet = file.sheet_by_name(sheet_name)rows = sheet.nrowsprint(rows)#cols = sheet.ncolsif rows:for i in range(rows):cell0 = str(sheet.cell_value(i, 0))#f1.write(cell0 + '\n')cell1 = str(sheet.cell_value(i, 1))f1.write(cell0 + ' ||| ' + cell1 + '\n')file = 'D:\\data\\gmy\\文学\\傲慢与偏见.xls'
pro_file_com = "D:\\data\\xls_com.txt"
#pro_file_chn = "D:\\data\\xls_chn.txt"pro = xls_pro(file, pro_file_com)
更多推荐
python 读取 xls文件
发布评论