国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python修改Excel數(shù)據(jù)的實(shí)例代碼

2019-11-25 18:38:26
字體:
供稿:網(wǎng)友

在前面的文章中介紹了如何用Python讀寫Excel數(shù)據(jù),今天再介紹一下如何用Python修改Excel數(shù)據(jù)。需要用到xlutils模塊。下載地址為https://pypi.python.org/pypi/xlutils。下載后執(zhí)行python setup.py install命令進(jìn)行安裝即可。
具體使用代碼如下:

復(fù)制代碼 代碼如下:

#-*-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")


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 靖西县| 齐河县| 扎囊县| 哈巴河县| 连平县| 广水市| 青田县| 镇原县| 上蔡县| 天祝| 平潭县| 渝中区| 临安市| 昭觉县| 本溪| 南江县| 大冶市| 鄂托克旗| 天津市| 勐海县| 邹平县| 喀喇沁旗| 浦北县| 扎鲁特旗| 涟源市| 巩留县| 怀安县| 新乡市| 肃北| 屏山县| 黄陵县| 黄平县| 上林县| 商都县| 房产| 电白县| 兰州市| 外汇| 沙河市| 巩义市| 兰西县|