• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > Python修改Excel数据的实例代码

Python修改Excel数据的实例代码

作者: 字体:[增加 减小] 来源:互联网

通过本文主要向大家介绍了python数据分析实例,python数据挖掘实例,python数据处理实例,python脚本编写实例,python项目实例等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

在前面的文章中介绍了如何用Python读写Excel数据,今天再介绍一下如何用Python修改Excel数据。需要用到xlutils模块。下载地址为https://pypi.python.org/pypi/xlutils。下载后执行python setup.py install命令进行安装即可。
具体使用代码如下:

import sys
reload(sys)
sys.setdefaultencoding('utf-8')

# 0 based (subtract 1 from excel row number)
START_ROW = 404

ismal_index = 2
#url所在列
url_index = 12
#domain所在列
domain_index = 11
#malinfo所在列
malinfo_index = 9

file_path = "C:\\Users\\***\\Desktop\\20130514.xls"
#formatting_info=True保存之前数据的格式
rb = open_workbook(file_path,formatting_info=True)
r_sheet = rb.sheet_by_index(0) # read only copy to introspect the file
wb = copy(rb) # a writable copy (I can't read values out of this, only write to it)
w_sheet = wb.get_sheet(0) # the sheet to write to within the writable copy

malurl = '''http://xbox.ooqqxx.com/res/ext.jar
            http://xbox.ooqqxx.com/res/stat.jar
            http://xbox.ooqqxx.com/pages/v.html
            http://xbox.ooqqxx.com/pages/extv.html
            http://xbox.ooqqxx.com/pages/r.html'''
domain_info = "http://xbox.ooqqxx.com"
malinfo = u"获取恶意URL,写入配置文件中,下载恶意可执行程序。"

#r_sheet.nrows为总行数
for row_index in range(START_ROW, r_sheet.nrows):
    #xlsvalue = r_sheet.cell(row_index, col_age_november).value
    w_sheet.write(row_index, ismal_index, u'是')
    w_sheet.write(row_index, url_index, malurl)
    w_sheet.write(row_index, domain_index, domain_info)
    w_sheet.write(row_index, malinfo_index, malinfo)
#wb.save(file_path + '.out' + os.path.splitext(file_path)[-1])
wb.save("C:\\Users\\***\\Desktop\\2013.xls")
</div>

</div>

您可能想查找下面的文章:

  • Python正则简单实例分析
  • Python类属性与实例属性用法分析
  • python元组操作实例解析
  • Python修改Excel数据的实例代码

相关文章

  • 利用Python开发微信支付的注意事项
  • Python多线程实例教程
  • python单例模式实例分析
  • Python ORM框架SQLAlchemy学习笔记之安装和简单查询实例
  • 浅谈python中的实例方法、类方法和静态方法
  • Windows上使用virtualenv搭建Python+Flask开发环境
  • Python多线程编程(一):threading模块综述
  • Python模块学习 datetime介绍
  • Python实现给qq邮箱发送邮件的方法
  • Python socket编程实例详解

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • 浅析Python中元祖、列表和字典的区别
    • Python实现统计单词出现的个数
    • Python开发WebService系列教程之REST,web.py,eurasia,Django
    • Python使用函数默认值实现函数静态变量的方法
    • Python中实现字符串类型与字典类型相互转换的方法
    • 利用Python的装饰器解决Bottle框架中用户验证问题
    • Python使用multiprocessing实现一个最简单的分布式作业调度系统
    • Python实现将数据库一键导出为Excel表格的实例
    • Python实现的Kmeans++算法实例
    • TensorFlow——Checkpoint为模型添加检查点的实例

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有