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 ...
随机推荐
- 伪分布式hbase2.6.5和hbase1.1.2的配置
1.注意hadoop和hbase的版本兼容问题 目前测试用:hadoop 2.6.5 Hbase 1.1.2 2.创建hadoop用户 Sudo useradd –m hadoop –s /bin/ ...
- yii2上传七牛图片(超详细)
前期准备 1.在七牛注册账号https://portal.qiniu.com/signup/choice 2.创建空间https://portal.qiniu.com/bucket(记住存储空间名称和 ...
- Codeforces 982E Billiard 扩展欧几里德
原文链接http://www.cnblogs.com/zhouzhendong/p/9055728.html 题目传送门 - Codeforces 928E 题意 一束与坐标轴平行或者成$45^\ci ...
- hive中,动态添加map和reduce的大小,以增加并行度
map是配置mapred.max.split.size,来定义map处理文件的大小,默认是256000000字段,换算就是256M. 如果想增加map的并行度,那么就是减少map处理文件的大小即可. ...
- 061 SparkStream数据接收原理
1.宏观 2.看英文解释过程 ------------------------------------------------------------------------------------- ...
- 050 Kafka的引入介绍
高吞吐量的分布式订阅消息系统 1.官网 http://kafka.apache.org/ 2.官网的介绍 3.结构 这个是版本1.0之后的版本. In Kafka the communication ...
- Linux下C语言进程通讯编程
代码: #include <stdio.h> #include <stdlib.h> #include <sys/shm.h> /*************基本的函 ...
- python自带线程池
1. 注意: 导包是: from multiprocessing.pool import ThreadPool #线程池不在thrading中 2. 代码: from mutiprocessing.p ...
- JAVA程序的基本结构
java程序(类)其实是一个静态方法库,或者是定义了一个数据类型.所以会遵循7种语法: 1.原始数据类型: ---整型:byte.short.int.long ---浮 ...
- 【Java并发核心九】并发集合框架
1.List接口:ArrayList 和 Vector ArrayList不是线程安全的,Vector是线程安全的,Vector有一个子类,可实现后进先出(LIFO)的对象堆栈(LinkedList ...