博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
用python操作excel(读写)
阅读量:3899 次
发布时间:2019-05-23

本文共 1010 字,大约阅读时间需要 3 分钟。

用python操作excel(读写)

import xlrdimport randomfrom xlutils.copy import copyimport xlutils# https://github.com/python-excel/xlrd# https://xlrd.readthedocs.io/en/latest/api.htmldef test1():    file = xlrd.open_workbook(filename=r'1.xlsx')    print(file.sheet_names())    # 获取工作表的名称    table = file.sheets()[0]    # 通过索引顺序获取    table = file.sheet_by_index(sheetx=0)    # 通过索引顺序获取    table = file.sheet_by_name(sheet_name='Sheet1')    # 通过名称获取    print("{0} {1} {2}".format(table.name, table.nrows, table.ncols))    # 打印工作表的名称,表的总行数,表的总列数    print("Cell A18 is {0}".format(table.cell_value(rowx=17, colx=0)))    # 打印单元格的值def test2():    x = random.random()    x = round(number=x, ndigits=1) # 保留一位小数    print(x)def main():    file = xlrd.open_workbook(filename=r'1.xlsx')    table = file.sheets()[0]    wb = copy(wb=file)    for i in range(1, table.nrows):        x = random.uniform(0.1, 0.5) + 29        wb.get_sheet(0).write(i, 2, round(number=x, ndigits=1))    wb.save('2.xlsx')if __name__ == '__main__':    main()

转载地址:http://ahden.baihongyu.com/

你可能感兴趣的文章
Datatables基本初始化——jQuery表格插件
查看>>
Servlet监听器——实现在线登录人数统计小例子
查看>>
Oracle笔记——简单查询语句 Oracle入门
查看>>
基于Hibernate和Struts2的用户管理系统小案例
查看>>
打开.class文件的方法
查看>>
基于windows平台Git+GitHub+Hexo搭建个人博客(一)
查看>>
基于windows平台Git+GitHub+Hexo搭建个人博客(二)
查看>>
Windows平台下SVN安装配置及使用
查看>>
python简便的编辑工具:jupyter notebook
查看>>
使用pip安装的时候出现 ModuleNotFoundError: No module named ‘pip‘
查看>>
Selenium自动化测试(八)之上传文件
查看>>
Selenium UI自动化(Java篇)
查看>>
使用Fiddler模拟弱网进行测试
查看>>
使用POI读取Excel测试用例
查看>>
记一次数据推送的异常解决端口解决
查看>>
linux、mysql、nginx、tomcat 性能参数优化
查看>>
Nginx使用Linux内存加速静态文件访问
查看>>
杀掉nginx进程后丢失nginx.pid,如何重新启动nginx
查看>>
nginx另类复杂的架构
查看>>
Nginx流量复制/AB测试/协程
查看>>