您的位置:首页 > 编程语言 > Python开发

python实现读Excel写入.txt

2017-05-14 14:17 543 查看
因为今天要用到把Excel中的数据写入到.txt文件中,所以简单的写了个代码:import numpy as np
import xlrd #打开excel文件
data= xlrd.open_workbook('./sudata/ng.xls')#打开Excel文件读取数据
sh=data.sheet_by_name("Sheet1")##通过工作簿名称获取
print sh.nrows#行数 5820
print sh.ncols#列数 2
n=0
i=0
file=open("ng.txt","w")
for n in range(sh.nrows):
for i in range(sh.ncols):
text=sh.cell_value(n,i).encode('utf-8')
file.write(text)
file.write('\n')
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: