python实现读Excel写入.txt的方法

2018-10-15 18:09

阅读:633

因为今天要用到把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)

以上这篇python实现读Excel写入.txt的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。


评论


亲,登录后才可以留言!