Python练手项目0014
2017-02-16 15:52
429 查看
本项目采用的是https://github.com/Yixiaohan/show-me-the-code中所提供的练习项目,所有代码均为原创,转载请注明,谢谢。
问题描述:纯文本文件 student.txt为学生信息, 里面的内容转换到xls中
# -*- coding: utf-8 -*-
"""
Created on Wed Feb 15 13:45:43 2017
@author: sky
"""
import xlwt
import re
def txt2xls(input_path,output_name):
book = xlwt.Workbook(encoding = 'utf-8', style_compression=0)
sheet = book.add_sheet(output_name,cell_overwrite_ok = True)
line = 0
info = re.compile(r'\"(\d+)\":\[\"(.*?)\",(\d+),(\d+),(\d+)\]')
with open(input_path,"r") as f:
data = f.read()
for x in info.findall(data):
for i in range(len(x)):
sheet.write(line,i,x[i])
line+=1
output_name = output_name + '.xls'
book.save(output_name)
if __name__ == '__main__':
txt2xls('student.txt','3')
xlwt用来生成一个excel文档,具体可以参考http://www.jb51.net/article/60510.htm
详细代码和结果,可以参考https://github.com/g8015108/exercise-for-python
问题描述:纯文本文件 student.txt为学生信息, 里面的内容转换到xls中
# -*- coding: utf-8 -*-
"""
Created on Wed Feb 15 13:45:43 2017
@author: sky
"""
import xlwt
import re
def txt2xls(input_path,output_name):
book = xlwt.Workbook(encoding = 'utf-8', style_compression=0)
sheet = book.add_sheet(output_name,cell_overwrite_ok = True)
line = 0
info = re.compile(r'\"(\d+)\":\[\"(.*?)\",(\d+),(\d+),(\d+)\]')
with open(input_path,"r") as f:
data = f.read()
for x in info.findall(data):
for i in range(len(x)):
sheet.write(line,i,x[i])
line+=1
output_name = output_name + '.xls'
book.save(output_name)
if __name__ == '__main__':
txt2xls('student.txt','3')
xlwt用来生成一个excel文档,具体可以参考http://www.jb51.net/article/60510.htm
详细代码和结果,可以参考https://github.com/g8015108/exercise-for-python
相关文章推荐
- python练手项目(1)——字符图片生成
- Python练手项目0016
- 70个Python练手项目列表(都有完整教程)
- 有哪些适合新手练手的Python项目?
- 【Python】 Flask 缘分匹配练手项目
- Python练手项目0 - 给头像右上角添加数字
- Python练手项目
- Python练手项目0013
- Python学习路径及练手项目合集
- python练手项目
- Python练手项目0006
- python练手项目0005
- Python练手项目0015
- Python练手项目0010
- Python练手项目(2)——200行实现2048小游戏
- Python之路【第二十四篇】:Python学习路径及练手项目合集
- python练手项目0007
- 利用Caffe+Python实现Kaggle上Digit Recognition练手项目
- 10个Python练手项目