一.使用win32读取excel内容

# -*- coding: utf-8 -*-
from win32com import client as wc
def open_excel():
excel = wc.Dispatch('EXCEL.Application') #使用excel程序
excel.Visible = 0 #不打开excel界面
my_excel = excel.Workbooks.Open(u'新建表格.xls') #指定表格路径 my_sheet = my_excel.Sheets('Sheet1') #打开表格中的sheet1,根据实际情况而定 for i in range(my_sheet.UsedRange.Rows.Count): #遍历sheet1中的表格列数
for j in range(my_sheet.UsedRange.Columns.Count): #遍历sheet1中的表格行数
print my_sheet.Cells(i + 1, j + 1).Value #读取相应的坐标表格值,并打印
my_excel.Close() #关闭表格
excel.Quit()
open_excel()

二.使用xlrd读取excel内容(比第一种方法快很多)

# -*- coding: utf-8 -*-
from xlrd import open_workbook def open_excel2(): #快很多
wb = open_workbook(u'新建表格.xls') #指定路径
for s in wb.sheets(): #遍历sheet表
for row in range(s.nrows): #遍历列
for col in range(s.ncols): #遍历行
print s.cell(row,col).value #打印值 open_excel()

三.使用xlwt写入表格

# -*- coding: utf-8 -*-
from xlwt import * lists = ['a','b','c']
n = 0 #第一列 def add_excel(n):
filename = u'新建列表.xls'
file = Workbook(encoding='utf-8') #指定file以utf-8的格式打开
sheet1 = file.add_sheet('sheet1') #写入sheet1
for m in range(len(lists)):
sheet1.write(m,n,lists[m]) #指定坐标(m,n)写入内容
file.save(filename) #保存excel文件 add_excel(n)

打开和写入excel文件的更多相关文章

  1. python pandas写入excel文件

    pandas读取.写入csv数据非常方便,但是有时希望通过excel画个简单的图表看一下数据质量.变化趋势并保存,这时候csv格式的数据就略显不便,因此尝试直接将数据写入excel文件. pandas ...

  2. java写入excel文件poi

    java写入excel文件 java写入excel文件poi,支持xlsx与xls,没有文件自动创建 package com.utils; import java.io.File; import ja ...

  3. 从网络上获取图片,并写入excel文件

    package com.weChat.utils; import com.manage.utils.DateUtil;import com.manage.utils.MD5Util;import or ...

  4. Delphi数据库数据用文件流方式快速写入Excel文件

    在开发数据库应用程序中,经常要将类型相同的数据导出来,放到Excel文件中,利用Excel强大的编辑功能,对数据作进一步的加工处理.这有许多的方法,我们可以使用OLE技术,在Delphi中创建一个自动 ...

  5. Python:将爬取的网页数据写入Excel文件中

    Python:将爬取的网页数据写入Excel文件中 通过网络爬虫爬取信息后,我们一般是将内容存入txt文件或者数据库中,也可以写入Excel文件中,这里介绍关于使用Excel文件保存爬取到的网页数据的 ...

  6. Python中使用第三方库xlrd来写入Excel文件示例

    Python中使用第三方库xlrd来写入Excel文件示例 这一篇文章就来介绍下,如何来写Excel,写Excel我们需要使用第三方库xlwt,和xlrd一样,xlrd表示read xls,xlwt表 ...

  7. Window 系统 Excel 同时打开两个Excel 文件

    问题 我们在使用 Excel 的时候,经常需要打开多个 Excel 文件,但是默认的话我们是只打开一个窗口的.这样不便于我们操作两个 Excel . 解决办法 下载这个补丁进行安装,下载链接 http ...

  8. 如何在C#中打开和读取EXCEL文件

    这篇文章向您展示如何在C#Windows Forms Application中使用ExcelDataReader,ExcelDataReader.DataSet打开和读取Excel文件.创建一个新的W ...

  9. python模块:xlsxwriter和xlrd相结合读取、写入excel文件

    python模块简单说明: xlsxwriter:负责写入数据 xlrd:负责读取数据 xlsxwriter 官方文档:http://xlsxwriter.readthedocs.org 本实例是刚写 ...

随机推荐

  1. Spring AOP 理论

    一.AOP AOP 产生的背景 “存在即合理”,任何一种理论或技术的产生,必然有它的原因.了解它产生的背景.为了解决的问题有助于我们更好地把握AOP的概念. 软件开发一直在寻求一种高效开发.护展.维护 ...

  2. c++-pimer-plus-6th-chapter03

    Chapter Review Having more than one integer type lets you choose the type that is best suited to a p ...

  3. 4.2 面向对象分析(二) CRC方法标识概念类

    CRC  又称为CRC索引卡片:CRC card  每张卡片代表一个类 Each card represents one class  每张卡片上写出这个类承担的职责.与其合作交互的其他类名   ...

  4. S-Nim HDU - 1536

    #include<iostream> #include<cstdio> #include<cstring> #include<vector> using ...

  5. python基础之小数据池,is和==区别 编码问题

    主要内容 小数据池,is和==区别 编码问题 小数据池 一种缓存机制,也称为驻留机制,是为了能更快提高一些字符串和整数的处理速度is 和 == 的区别 == 主要指对变量值是否相等的判断,只要数值相同 ...

  6. Bulb Switcher (leetcode java)

    问题描述: There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off ...

  7. win php安装 oracle11 g

    1.下载plsql和oracle11g plsql安装比较简单,就是普通的安装.oracle11 g不用安装, 下面我讲解一下win 64位的系统配置oracle: (1).首先我使用的是warpse ...

  8. poj-2689-素数区间筛

    Prime Distance Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22420 Accepted: 5954 Descr ...

  9. python中eval()和json.dumps的使用

    在python中通过requests.get(url)获取json数据,此时可能需要eval进行解析. # -*- coding: utf-8 -*- import requests r = requ ...

  10. Linux下Tomcat项目启动报错

    Linux下Tomcat项目启动报错 org.springframework.beans.factory.CannotLoadBeanClassException: Error loading cla ...