#encoding=utf-8
import xlrd
from xlwt import *
#------------------读数据---------------------------------
fileName="6.xlsx"
bk=xlrd.open_workbook(fileName)
shxrange=range(bk.nsheets)
try:
sh=bk.sheet_by_name("Sheet1")
except:
print ("代码出错")
nrows=sh.nrows #获取行数
#将某列数据保存到txt文件中
fo = open("longxlsc.txt","a+",encoding='utf-8')
for i in range(1,nrows):
fo.write(sh.cell_value(i,5)+'\n')
print("finished!")
fo.close()
#将数据保存到excel文件中
'''book = Workbook(encoding='utf-8')
sheet = book.add_sheet('Sheet1') #创建一个sheet
for i in range(1,nrows):
row_data=sh.row_values(i)
#获取第i行第3列数据
#sh.cell_value(i,3)
#---------写出文件到excel--------
print ("-----正在写入 "+str(i)+" 行")
sheet.write(i,1, label = sh.cell_value(i,0)) #向第1行第1列写入获取到的值
#sheet.write(i,2, label = sh.cell_value(i,5)) #向第1行第2列写入获取到的值
book.save("excel.xls")'''
python 读取excel文件
最新推荐文章于 2022-05-09 10:49:30 发布