1.打印excel的一列为列表表示

server.xls:

# encoding : utf-8

import xlrd

xlsfile = u'C:\Python27\server.xls'

data = xlrd.open_workbook(xlsfile)

table = data.sheet_by_name(u'sheet2')

ncols = table.ncols

print ncols

#for i in range(ncols):

#print table.col_values(0)

a = table.col_values(1)

print a

打印结果:

14

[u'S_18.21', 0.8, 0.98, 0.92, 0.705, 1.0]

2.打印txt文档的一列为列表表示

ex.txt:

0.76

0.76

0.76

0.76#encoding:utf8

import xlrd

import xlwt

class openexcel():

def wexcel(self,infile,outefile):

rfile=open(infile,'r')

buf=rfile.read().split('\n')

print buf

rfile.close()

#w=xlwt.Workbook()

#sheet=w.add_sheet('sheet1')

#for i in range(len(buf)):

#print buf[i]

#sheet.write(i+1,1,buf[i].decode('utf8'))

#w.save(outefile)

if __name__ == '__main__':

t=openexcel()

t.wexcel('ex.txt','server.xls')

打印结果:

['0.76', '0.76', '0.76', '0.76']

3.前面两例的综合,2的打印结果替换1的打印结果相应数据#encoding:utf8

import xlrd

import xlwt

class openexcel():

def wexcel(self,infile,outefile):

rfile=open(infile,'r')

buf=rfile.read().split('\n')

return buf

rfile.close()

xlsfile = u'C:\Python27\server.xls'

data = xlrd.open_workbook(xlsfile)

table = data.sheet_by_name(u'sheet2')

excel_data = table.col_values(1)

if __name__ == '__main__':

t=openexcel()

txt_data = t.wexcel('ex.txt','server.xls')

excel_data[1:] = txt_data

print excel_data

打印结果:

[u'S_18.21', '0.76', '0.76', '0.76', '0.76'] #红色为替换部分

4.多个txt文件写入一个excel:

ex0.txt:

Server

/

/backup

/project

memory

swap

ex1.txt:

0.71

0.71

0.71

0.71

0.71

ex2.txt:

S_18.22

0.72

0.72

0.72

0.72#encoding:utf8

import xlrd

import xlwt

class openexcel():

def wexcel(self,l1,l2,l3,l4,outefile):

rfile1=open(l1,'r')

rfile2=open(l2,'r')

rfile3=open(l3,'r')

rfile4=open(l4,'r')

buf1=rfile1.read().split('\n')

buf2=rfile2.read().split('\n')

buf3=rfile3.read().split('\n')

buf4=rfile4.read().split('\n')

print buf1,buf2,buf3,buf4

rfile1.close()

rfile2.close()

w=xlwt.Workbook()

sheet=w.add_sheet(u'sheet2')

for i in range(len(buf1)):

#print buf1[i]

sheet.write(i,0,buf1[i].decode('utf-8'))

for i in range(len(buf2)):

sheet.write(i,1,buf2[i].decode('utf-8'))

for i in range(len(buf3)):

sheet.write(i,2,buf3[i])

for i in range(len(buf4)):

sheet.write(i,3,buf4[i].decode('utf-8'))

w.save(outefile)

if __name__ == '__main__':

t=openexcel()

t.wexcel(u'ex0.txt','ex1.txt','ex2.txt','ex3.txt','server.xls')

server.xls输出结果:

python处理excel案例_python操作excel例子相关推荐

  1. python数字求和程序_python操作excel求和

    这里介绍如何用python来自动完成我们的excel工作. 本文的目的是展示一些常见的Excel任务,以及如何在python pandas中执行类似的任务.例子微不足道,但重要的是通过这个例子来循序渐 ...

  2. python让工作自动化_python操作excel让工作自动化

    某局某领导给了3只excel文件,一只里面有4个sheet需要处理,一个sheet有250+列,算下来总共有3000+列需要手动反复插入.删除列.拷贝.求和,所以给了4天的时间要完成. 我不愿意做大量 ...

  3. python表格处理工具_python 操作excel表格的方法

    说明:由于公司oa暂缺,人事妹子在做考勤的时候,需要通过几个excel表格去交叉比对员工是否有旷工或迟到,工作量大而且容易出错. 这时候it屌丝的机会来啦,花了一天时间给妹子撸了一个自动化脚本. 1. ...

  4. python设置excel自动换行_python操作excel

    python操作Excel openpyxl模块 0.介绍 openpyxl是一个Python库,用于读取/写入Excel 2010 xlsx / xlsm / xltx / xltm文件. 它的诞生 ...

  5. python实现excel函数_python操作excel

    长期以来都想用python对Excel进行一些列的操作,但由于某种神秘的力量控制着我,一直未果,今天有幸用requests模块和BeautifulSoup模块进行爬虫练习,拿到了一大批数据,照我以前, ...

  6. python设置excel自动换行_python操作excel的方法(xlsxwriter包的使用)

    本文介绍python操作excel的方法(xlsxwriter包的使用),具体内容如下 xlsxwriter包的安装 pip install xlsxwriter Workbook类 创建一个exce ...

  7. python添加excel模块_python操作Excel模块openpyxl

    1. 安装 pip install openpyxl 想要在文件中插入图片文件,需要安装pillow,安装文件:PIL-fork-1.1.7.win-amd64-py2.7.exe · font(字体 ...

  8. python操作excel命令_python操作Excel读写(使用xlrd和xlrt)[转帖]

    xlrd http://pypi.python.org/pypi/xlrd 简单使用 导入 import xlrd 打开excel data = xlrd.open_workbook('demo.xl ...

  9. python控制excel选择区域_python操作excel常用的方法

    读操作模块安装 pip install xlrd 写操作模块安装 pip install xlwt xlrd读操作 1.打开excel xl = xlrd.open_workbook('test.xl ...

最新文章

  1. 昇思MindSpore1.6发布 AI开发者体验再升级
  2. 【简明教程】windows下xgboost安装到python
  3. Linux打印指定的行范围
  4. c++矩阵作为函数输入变量_C++实现矩阵乘法
  5. Centos7.0上搭建LAMP平台安装discuz后无法访问
  6. 05-类--+-号使用
  7. ApacheCN 数据科学译文集 2020.8
  8. 汇编语言学习--转移指令的原理
  9. Shell脚本查询进程存活信息
  10. oracle instant client 配置,oracle instantclient配置
  11. linux下golang protoc安装详细教程
  12. win10内存满载测试软件,windows10系统使用自带内存检测工具检测内存好坏的方法...
  13. 打包一个包含手表端应用的手机端APK应用—Ticwear
  14. win10自带磁盘测速工具
  15. oracle 查找序列号,Oracle 查找丢失数据序列号
  16. uml具有多种视图_UML语言中五大视图
  17. 26.空寂无求,禅意悠远
  18. [英语]在英语学习的过程中学到的学习方法
  19. 股神巴菲特忠告中国股民:学会这几点,你离短线炒股的成功就不远了!
  20. 倍福TwinCAT(贝福Beckhoff)常见问题(FAQ)-人机界面快速入门 TC3

热门文章

  1. 本机电脑与 Android 设备如何进行文件传输?
  2. 缩进一个字符_解析Word——Word段落格式中的几种缩进(中)
  3. 笔记本网络计算机和设备不可见,xp电脑不显示无线网络的七种原因和解决方法...
  4. 每日程序C语言2-判断某日期是这一年的第几天
  5. plesk 打不开php,Laravel在Plesk背后,遇到PHP版本困难
  6. 4.由键盘任意输入10个数据,分别统计其中的正数个数、正数之和、负数个数、负数之和。
  7. Jmeter_简单的关联设置
  8. Java类之File记录
  9. 创建calico网络报错client response is invalid json
  10. wenbao与acm技巧(必备知识)