Python修改Excel數(shù)據(jù)的實例代碼
在前面的文章中介紹了如何用Python讀寫Excel數(shù)據(jù),今天再介紹一下如何用Python修改Excel數(shù)據(jù)。需要用到xlutils模塊。下載地址為https://pypi.python.org/pypi/xlutils。下載后執(zhí)行python setup.py install命令進行安裝即可。
具體使用代碼如下:
#-*-coding:utf-8-*-
from xlutils.copy import copy # http://pypi.python.org/pypi/xlutils
from xlrd import open_workbook # http://pypi.python.org/pypi/xlrd
from xlwt import easyxf # http://pypi.python.org/pypi/xlwt
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保存之前數(shù)據(jù)的格式
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,寫入配置文件中,下載惡意可執(zhí)行程序。"
#r_sheet.nrows為總行數(shù)
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")
- python讀取excel數(shù)據(jù)繪制簡單曲線圖的完整步驟記錄
- Python matplotlib讀取excel數(shù)據(jù)并用for循環(huán)畫多個子圖subplot操作
- Python導(dǎo)入數(shù)值型Excel數(shù)據(jù)并生成矩陣操作
- 使用python將excel數(shù)據(jù)導(dǎo)入數(shù)據(jù)庫過程詳解
- 用Python將Excel數(shù)據(jù)導(dǎo)入到SQL Server的例子
- python讀取并定位excel數(shù)據(jù)坐標系詳解
- Python利用pandas處理Excel數(shù)據(jù)的應(yīng)用詳解
- python寫入已存在的excel數(shù)據(jù)實例
- 配置python連接oracle讀取excel數(shù)據(jù)寫入數(shù)據(jù)庫的操作流程
相關(guān)文章
Python連接Postgres/Mysql/Mongo數(shù)據(jù)庫基本操作大全
在后端應(yīng)用開發(fā)中,經(jīng)常會用到Postgres/Mysql/Mongo這三種數(shù)據(jù)庫的基本操作,今天小編就給大家詳細介紹Python連接Postgres/Mysql/Mongo數(shù)據(jù)庫基本操作,感興趣的朋友一起看看吧2021-06-06pytorch實現(xiàn)seq2seq時對loss進行mask的方式
今天小編就為大家分享一篇pytorch實現(xiàn)seq2seq時對loss進行mask的方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-02-02基于Python實現(xiàn)簡單學(xué)生管理系統(tǒng)
這篇文章主要為大家詳細介紹了基于Python實現(xiàn)簡單學(xué)生管理系統(tǒng),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2020-07-07基于Python實現(xiàn)一個簡單的學(xué)生管理系統(tǒng)
這篇文章主要為大家詳細介紹了如何利用python實現(xiàn)簡單的學(xué)生信息管理系統(tǒng),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-12-12python使用 request 發(fā)送表單數(shù)據(jù)操作示例
這篇文章主要介紹了python使用 request 發(fā)送表單數(shù)據(jù)操作,結(jié)合實例形式分析了Python基于requests模塊的表單數(shù)據(jù)發(fā)送操作相關(guān)實現(xiàn)技巧,需要的朋友可以參考下2019-09-09