txt2xls
#!/bin/env python
# -*- encoding: utf-8 -*-
import datetime
import time
import os
import sys
import openpyxl
def txt2xls(filename,xlsname): #文本转换成xls的函数,filename 表示一个要被转换的txt文本,xlsname 表示转换后的文件名
print ('converting xls ... ')
f = open(filename) #打开txt文本进行读取
x = 0 #在excel开始写的位置(y)
y = 0 #在excel开始写的位置(x)
xls=openpyxl.Workbook()
sheet = xls.active
sheet.title = "sheett1"
# xls.create_sheet('sheet1') #生成excel的方法,声明excel
line = f.readline() #一行一行读取
while line: #循环,读取文本里面的所有内容
items = line.replace("\n","").split('\t')
print (items)
print (x)
x += 1
sheet.append(items) #按行写入
line = f.readline() #一行一行读取
f.close()
xls.save(xlsname+'.xlsx') #保存
if __name__ == "__main__":
filename = sys.argv[1]
xlsname = sys.argv[2]
txt2xls(filename,xlsname)
txt2xls的更多相关文章
- 将txt文本转换为excel格式
将txt文本转换为excel格式,中间使用的列分割为 tab 键 一.使用xlwt模块 注:Excel 2003 一个工作表行数限制65536,列数限制256 需要模块:xlwt 模块安装:xlwt ...
- Python 文本(txt) 转换成 EXCEL(xls)
#!/bin/env python # -*- encoding: utf-8 -*- #------------------------------------------------------- ...
- 使用python批量导入txt导入excel表格(公司电脑设备ip和人员统计)
#!/bin/env python # -*- encoding: utf- -*- import datetime import time import os import sys import x ...
随机推荐
- Bootstrap富文本编辑器-bootstrap-wysiwyg
在进行英语试题的录入中,因为英语试题经常会有类似如下的试题: My friend watches dragon boat races at the Dragon Boat Festival.(对划线部 ...
- Codeforces 982E Billiard exgcd
Billiard 枚举终点, 对于每一个终点一共有四种周期的相遇方式, 枚举一下取最小的时间. #include<bits/stdc++.h> #define LL long long # ...
- AtCoder Grand Contest 017D (AGC017D) Game on Tree 博弈
原文链接https://www.cnblogs.com/zhouzhendong/p/AGC017D.html 题目传送门 - AGC017D 题意 给定一棵 n 个节点的以节点 1 为根的树. 两个 ...
- HDU3488 Tour KM
原文链接http://www.cnblogs.com/zhouzhendong/p/8284304.html 题目传送门 - HDU3488 题意概括 给一个n的点m条边的有向图. 然后让你把这个图分 ...
- JavaScript项目重构到底有多少坑要填要踩
看到代码的那一刻我惊呆了,就一个js文件,接近2000行的代码.这个还好,比这个行数多的我见的多了,这个还吓不到我.有哪些问题,一会再说. 因为从我接手的那一刻算起,几天后就要发新版本,我只要也只能调 ...
- Linux下的Mysql数据库备份+还原
数据库备份: root@debian-mm:/home/debian-mm# mysqldump -u root -p Account > Account.sql Enter password: ...
- python inspect 模块 和 types 模块 判断是否是方法,模块,函数等内置特殊属性
python inspect 模块 和 types 模块 判断是否是方法,模块,函数等内置特殊属性 inspect import inspect def fun(): pass inspect.ism ...
- Square Destroyer-POJ 1084 (IDA*)
Description The left figure below shows a complete 3*3 grid made with 2*(3*4) (=24) matchsticks. The ...
- Java高级面试题解析(一)
最近,在看一些java高级面试题,我发现我在认真研究一个面试题的时候,我自己的收获是很大的,我们在看看面试题的时候,不仅仅要看这个问题本身,还要看这个问题的衍生问题,一个问题有些时候可能是一个问题群( ...
- Django 学习第四天——Django 模板标签
一.模板标签: 作用:标签在渲染的过程中提供任意的逻辑:例如 if for...in... 等 标签语法:由 {% %} 来定义的:例如:{% tag %}xxx{% endtag %} 常用标签: ...