- 浏览: 361614 次
- 性别:
- 来自: 四川
文章分类
- 全部博客 (247)
- 数据库以及sql (11)
- java (48)
- 爬虫学习 (20)
- java编程 (28)
- python编程以及安装和配置 (27)
- oracle数据库 (32)
- mongodb基本操作 (4)
- linux学习 (7)
- easyUI (2)
- nodeJs (8)
- python学习 (16)
- 其他 (13)
- hadoop (1)
- svn (1)
- 汉字 (1)
- windows (2)
- jsp (5)
- fiddler (1)
- ETL (1)
- teamviewer (1)
- maven (4)
- GIT (2)
- datagrip (1)
- ocr (1)
- redis (3)
- mysql (3)
- linux (1)
- 数据服务 (0)
最新评论
# coding=utf-8
'''
Created on 2017年3月2日
@author: chenkai
'''
import xlrd #读取excel
data =xlrd.open_workbook("F:\\test.xlsx")
table=data.sheets()[0]
nrows=table.nrows#行数
ncols=table.ncols#列数
print "行数: ",nrows,"列数: " ,ncols
for i in range(0,nrows):
print "--------------------第",i,"行"
rowValues=table.row_values(i)#某一行数据
for item in rowValues:
print item
'''
编写excel
'''
import xlwt
'''
往EXCEl单元格写内容,每次写一行sheet:页签名称;rowValueList:行内容列表;rowIndex:行索引;
isBold:true:粗字段,false:普通字体
'''
def WriteSheetRow(sheet, rowValueList, rowIndex, isBold):
i = 0
#style = xlwt.easyxf('font: bold 1')
style = xlwt.easyxf('font: bold 0, color red; pattern: pattern solid, fore_colour yellow;')#红色字体
'''
# style2 = xlwt.easyxf('pattern: pattern solid, fore_colour yellow; font: bold on;')
# 设置Excel单元格的背景色为黄色,字体为粗体
'''
for svalue in rowValueList:
strValue = unicode(str(svalue), 'utf-8')
if isBold:
sheet.write(rowIndex, i, strValue, style)
else:
sheet.write(rowIndex, i, strValue,style)
i = i + 1
'''写excel文件'''
def save_Excel(strFile):
excelFile = unicode(strFile, "utf8")
wbk = xlwt.Workbook()
sheet = wbk.add_sheet('sheet1', cell_overwrite_ok=True)
headList = ['标题1', '标题2', '标题3', '标题4', '总计']
rowIndex = 0
WriteSheetRow(sheet, headList, rowIndex, True)
for i in xrange(1, 11):
rowIndex = rowIndex + 1
valueList = []
for j in xrange(1, 5):
valueList.append(j * i)
WriteSheetRow(sheet, valueList, rowIndex, False)
wbk.save(excelFile)
save_Excel("F:\\test2.xls")
'''
style2 = xlwt.easyxf('pattern: pattern solid, fore_colour yellow; font: bold on;')
在设置上Excel单元格的背景色时,fore_colour 支持的颜色是有限的,仅支持一下颜色
aqua 0x31
black 0x08
blue 0x0C
blue_gray 0x36
bright_green 0x0B
brown 0x3C
coral 0x1D
cyan_ega 0x0F
dark_blue 0x12
dark_blue_ega 0x12
dark_green 0x3A
dark_green_ega 0x11
dark_purple 0x1C
dark_red 0x10
dark_red_ega 0x10
dark_teal 0x38
dark_yellow 0x13
gold 0x33
gray_ega 0x17
gray25 0x16
gray40 0x37
gray50 0x17
gray80 0x3F
green 0x11
ice_blue 0x1F
indigo 0x3E
ivory 0x1A
lavender 0x2E
light_blue 0x30
light_green 0x2A
light_orange 0x34
light_turquoise 0x29
light_yellow 0x2B
lime 0x32
magenta_ega 0x0E
ocean_blue 0x1E
olive_ega 0x13
olive_green 0x3B
orange 0x35
pale_blue 0x2C
periwinkle 0x18
pink 0x0E
plum 0x3D
purple_ega 0x14
red 0x0A
rose 0x2D
sea_green 0x39
silver_ega 0x16
sky_blue 0x28
tan 0x2F
teal 0x15
teal_ega 0x15
turquoise 0x0F
violet 0x14
white 0x09
yellow 0x0D
'''
'''
Created on 2017年3月2日
@author: chenkai
'''
import xlrd #读取excel
data =xlrd.open_workbook("F:\\test.xlsx")
table=data.sheets()[0]
nrows=table.nrows#行数
ncols=table.ncols#列数
print "行数: ",nrows,"列数: " ,ncols
for i in range(0,nrows):
print "--------------------第",i,"行"
rowValues=table.row_values(i)#某一行数据
for item in rowValues:
print item
'''
编写excel
'''
import xlwt
'''
往EXCEl单元格写内容,每次写一行sheet:页签名称;rowValueList:行内容列表;rowIndex:行索引;
isBold:true:粗字段,false:普通字体
'''
def WriteSheetRow(sheet, rowValueList, rowIndex, isBold):
i = 0
#style = xlwt.easyxf('font: bold 1')
style = xlwt.easyxf('font: bold 0, color red; pattern: pattern solid, fore_colour yellow;')#红色字体
'''
# style2 = xlwt.easyxf('pattern: pattern solid, fore_colour yellow; font: bold on;')
# 设置Excel单元格的背景色为黄色,字体为粗体
'''
for svalue in rowValueList:
strValue = unicode(str(svalue), 'utf-8')
if isBold:
sheet.write(rowIndex, i, strValue, style)
else:
sheet.write(rowIndex, i, strValue,style)
i = i + 1
'''写excel文件'''
def save_Excel(strFile):
excelFile = unicode(strFile, "utf8")
wbk = xlwt.Workbook()
sheet = wbk.add_sheet('sheet1', cell_overwrite_ok=True)
headList = ['标题1', '标题2', '标题3', '标题4', '总计']
rowIndex = 0
WriteSheetRow(sheet, headList, rowIndex, True)
for i in xrange(1, 11):
rowIndex = rowIndex + 1
valueList = []
for j in xrange(1, 5):
valueList.append(j * i)
WriteSheetRow(sheet, valueList, rowIndex, False)
wbk.save(excelFile)
save_Excel("F:\\test2.xls")
'''
style2 = xlwt.easyxf('pattern: pattern solid, fore_colour yellow; font: bold on;')
在设置上Excel单元格的背景色时,fore_colour 支持的颜色是有限的,仅支持一下颜色
aqua 0x31
black 0x08
blue 0x0C
blue_gray 0x36
bright_green 0x0B
brown 0x3C
coral 0x1D
cyan_ega 0x0F
dark_blue 0x12
dark_blue_ega 0x12
dark_green 0x3A
dark_green_ega 0x11
dark_purple 0x1C
dark_red 0x10
dark_red_ega 0x10
dark_teal 0x38
dark_yellow 0x13
gold 0x33
gray_ega 0x17
gray25 0x16
gray40 0x37
gray50 0x17
gray80 0x3F
green 0x11
ice_blue 0x1F
indigo 0x3E
ivory 0x1A
lavender 0x2E
light_blue 0x30
light_green 0x2A
light_orange 0x34
light_turquoise 0x29
light_yellow 0x2B
lime 0x32
magenta_ega 0x0E
ocean_blue 0x1E
olive_ega 0x13
olive_green 0x3B
orange 0x35
pale_blue 0x2C
periwinkle 0x18
pink 0x0E
plum 0x3D
purple_ega 0x14
red 0x0A
rose 0x2D
sea_green 0x39
silver_ega 0x16
sky_blue 0x28
tan 0x2F
teal 0x15
teal_ega 0x15
turquoise 0x0F
violet 0x14
white 0x09
yellow 0x0D
'''
发表评论
-
python中将unicode(u'\u7684') 转中文字符
2018-08-16 16:16 3962ddd=u'\u7684' ddd=ddd.encode(&q ... -
python中的开放运算
2017-07-06 09:39 975要点: 将整数用浮点数表示:由于Python的整数除法,为了 ... -
Python多线程爬取网站image的src属性实例
2017-05-16 11:18 1685# coding=utf-8 ''' Created on 2 ... -
eclipse创建scrapy项目
2017-05-12 17:23 10251. 您必须创建一个新的Scrapy项目。 进入您打算存储代码 ... -
windows安装scrapy框架步骤
2017-05-12 13:05 572Scrapy简介 Scrapy是一个快速,高效的网页抓取Pyt ... -
python操作mongoDB
2017-05-12 10:04 1016#coding=utf-8 from pymongo impo ... -
windows下安装Scrapy框架(python)
2017-03-22 14:39 7181、下载安装Python2.7.6, ... -
python "\xc5\xc0\xb3\xe6" 转汉字
2017-03-10 10:10 5319print "\xc5\xc0\xb3\xe6&qu ... -
python_GUI应用程序代码
2017-03-03 10:06 635# coding=utf-8 ''' Created on 2 ... -
python标准异常分类
2017-03-01 16:09 410ppython标准异常分类 BaseException ... -
python在linux、windows下执行命令的方法
2017-02-22 16:52 1007windows下: import os cmdres= os. ... -
python中selenium 滚动条下拉 操作
2017-02-22 11:16 6683方法一)使用js脚本直接操作,方法如下: js=" ... -
python+BeautifulSoup+selenium+mysqldb完成数据抓取
2017-02-21 14:28 894# coding=utf-8 ''' Created on 2 ... -
python+selenium浏览器调用(chrome、ie、firefox)
2017-02-20 14:35 1876#coding=utf-8 from selenium im ... -
windows下安装beautifulsoup
2017-02-14 10:57 8111.去beautiful soup官网上去下载最新版本是4.3 ... -
windows下casperjs安装以及配置
2017-02-14 10:20 380下载casperjs,解压后命名为casperjs 添加环境变 ... -
wingdows下安装phantomjs
2017-02-14 10:19 396下载phantomjs后解压,重命名为phantomjs 添加 ... -
python下安装beautifulsoup4-4.3.1
2017-02-07 16:18 5281.去beautiful soup官网上去下载最新版本是4.3 ... -
python中的正则表达式,python
2017-02-07 10:20 611# coding=utf-8 ''' Created on 2 ... -
python时间格式
2017-01-17 10:35 4551. 日期输出格式化 datetime => strin ...
相关推荐
python读写excel
python读写excel文件有很多种方法: 用xlrd和xlwt进行excel读写 用openpyxl进行excel读写 用pandas进行excel读写 本文使用xlrd读取excel文件(xls,sxls格式),使用xlwt向excel写入数据 一、xlrd和xlwt的安装 安装...
python读写excel文件代码,读写mdb代码
Python 读取Excel、文本、CSV等不同类型数据 Python源码Python 读取Excel、文本、CSV等不同类型数据 Python源码Python 读取Excel、文本、CSV等不同类型数据 Python源码Python 读取Excel、文本、CSV等不同类型数据 ...
python 读写 Excel 学习总结
这是一个python读取excel文件例子,里面配有python文件、python文件生成的exe,并有MFC界面调取exe文件
代码用于读Excel中的数据,然后批量写进word,文件的读写有专门的类,对于批量处理excel很有帮助
Python的读取Excel文件,做一定筛选,读取行和列;python写入文档;
python读写Excel_MDB_sqlite的示例代码
这个包里带有python读写excel文档 xrld,xlwt,xlutils等支持包。
python读写Excel的代码实现.rar python读写Excel的代码实现.rar
python读写excel表格,简单脚本实现有备注
包含python读写EXCEL的三个包:xlrd-0.9.2.tar、xlutils-1.7.0(1).tar、xlwt-0.7.5.tar
python读写Excel_MDB_sqlite的示例代码
用Python读取excel文件,并获取更多信息。
python读取excel数据 要在Python中读取Excel数据,您可以使用第三方库如 openpyxl 或 pandas。以上是使用这两个库的示例:示例假设您已经有一个名为 example.xlsx 的 Excel 文件,其中包含了要读取的数据。您可以...
主要介绍了Python读取Excel数据并生成图表过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
python读取excel数据 在Python中,可以使用pandas库来读取Excel文件中的数据。下面是一个简单的例子:见附件 在上面的代码中,我们首先导入了pandas库,并使用pd.read_excel()函数来读取名为example.xlsx的Excel文件...
python读取excel数据,通过调用openpyxl来写入或读取excel某行某列的值,也可以读取整张表的内容。 此为python源码,下载后可按需自行更改调试使用。
用于快速生成sql语句,适用于测试人员批量生成合理测试数据,