python中excel基本操作实例
来源:互联网 发布:mac谷歌应用商店打不开 编辑:程序博客网 时间:2024/06/03 23:43
#! /usr/bin/env python# -*- coding:utf8 -*-import osimport sysimport xlrdimport xlwt# reload(sys)# sys.setdefaultencoding('utf8')def excelRead(): # excel文件路径 excelPath = 'E:/tmp/t.xlsx' # 判断是否已存在,存在则移出旧文件 if not os.path.exists(excelPath): return # 读取book book= xlrd.open_workbook(excelPath) # 按顺序读取book中的第一个sheet sheet = book.sheet_by_index(0) #nrows = sheet.nrows # 读取sheet第一行第二列的数据 str = sheet.cell(0,1).value print strdef excelWrite(): # excel文件路径 excelPath = 'E:/tmp/t.xlsx' # 判断是否已存在,存在则移出旧文件 if os.path.exists(excelPath): os.remove(excelPath) # 新建book book = xlwt.Workbook() # 新建sheet sheet = book.add_sheet("testTitle") # 往sheet第一行,第一列写数据:ID sheet.row(0).write(0, 'ID') # 往sheet第一行,第二列写数据:姓名 特别注意,中文字符前要加u,标识unicode编码,否则会报错 sheet.row(0).write(1, u'姓名') # 保存book到文件中 book.save(excelPath)def main(): excelWrite() excelRead()if __name__ == '__main__': main()
阅读全文
0 0
- python中excel基本操作实例
- Python处理excel基本操作
- PYTHON操作EXCEL,实例代码
- python操作excel的基本语句
- python基本数字类型操作实例
- python中mysql基本操作
- Python语句中基本的规则与特殊字符简单操作实例
- python中操作excel文件方法总结
- python中对Excel进行读写操作
- python中对Excel进行读写操作
- python中对excel的操作
- 在python中使用xlwt操作excel
- python中使用pyexcel操作excel方法
- python中使用xlrd、xlwt操作excel
- python处理excel表格的一些基本操作(1)
- Excel基本操作
- excel基本操作
- Excel 的基本操作
- JavaEE 获取路径
- YOLO: Real-Time Object Detection
- [ 转]放弃MATLAB!简述winpython为什么比MATLAB更方便
- hibernate--CoreAPI_Session
- R入门-001
- python中excel基本操作实例
- 欢迎使用CSDN-markdown编辑器
- 2014年国人开发的最热门的开源软件TOP 100
- Unity3D
- mongodb的c++接口说明
- JQuery ui 简单应用
- 缓存击穿
- MongoDB MapReduce 性能提升20倍的优化宝典
- 简易解包程序