赞
踩
因为今天要用到把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')
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。