提取EXCEL表格中特定列内容保存至txt文档
2014-05-10 11:05
357 查看
不能用wps文件
引用文档中有中文,开头声明 # coding=gbk
写入文件时有中文,需要加入以下代码
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
完整代码:
# coding=gbk
import sys
import xlrd
import time
reload(sys)
sys.setdefaultencoding('utf-8')
book = xlrd.open_workbook(r'C:\Users\Administrator\Desktop\510\123.xls')
sheet = book.sheet_by_index(0)
countRow = sheet.nrows
start = time.time()
f=open(r'C:\Users\Administrator\Desktop\510\read.txt','w')
for i in range(1,countRow):
listRow = sheet.row(i)
getName = listRow[1].value
getBigindex = listRow[7].value
getSmallindex = listRow[8].value
getID = listRow[0].value
ss='%s %d %d %d\n' % (getName,getBigindex,getSmallindex,getID)
f.write(ss)
f.close()
c =time.time()-start
print '程序运行耗时:%.2f' % c
引用文档中有中文,开头声明 # coding=gbk
写入文件时有中文,需要加入以下代码
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
完整代码:
# coding=gbk
import sys
import xlrd
import time
reload(sys)
sys.setdefaultencoding('utf-8')
book = xlrd.open_workbook(r'C:\Users\Administrator\Desktop\510\123.xls')
sheet = book.sheet_by_index(0)
countRow = sheet.nrows
start = time.time()
f=open(r'C:\Users\Administrator\Desktop\510\read.txt','w')
for i in range(1,countRow):
listRow = sheet.row(i)
getName = listRow[1].value
getBigindex = listRow[7].value
getSmallindex = listRow[8].value
getID = listRow[0].value
ss='%s %d %d %d\n' % (getName,getBigindex,getSmallindex,getID)
f.write(ss)
f.close()
c =time.time()-start
print '程序运行耗时:%.2f' % c
相关文章推荐
- 修改txt文档的内容并保存在新的txt文档中
- JAVA提取Word,Excel,PPT,PDF,TXT等文档文字内容
- C#提取TXT文档指定内容
- JAVA提取Word,Excel,PPT,PDF,TXT等文档文字内容
- 提取xml文档的内容到.txt文件中
- VB.NET提取TXT文档指定内容
- python提取txt文档内容
- 读取特定目录下txt文档内容
- Win10使用写字板编辑文档如何将它保存为TXT格式
- excel保存时出现“请注意,您的文档的部分内容可能包含了文档检查器无法删除的个人信息”
- “Word自动更改后的内容保存到通用文档模板上。是否加载该模板?“的解决办法
- c# 读取txt文件中特定内容后的文字
- 保存网页内容到txt
- python 将print输出的内容保存到txt文件中
- 读取一个txt文档中的内容
- 【python】用openpyxl提取txt中特定文字并存储到Excel中
- 如何将文本框里面的内容保存到txt文件中
- PYTHON实现把PPT文档中的内容导出到TXT文件中
- 得到保存在assets目录下的txt文件的内容
- Java使用PDFBox开发包实现对PDF文档内容编辑与保存