使用python更新excel

时间:2016-04-11 23:23:41

标签: python xlrd xlwt

我有一张包含多张纸的工作簿。我正在尝试读取一个工作表数据并匹配其他工作表中的列字段,以查看它们是否匹配更新该工作表的某些列。这就是我的尝试。但据我所知,XLRD不能用来写。任何人都可以指向python库或模块,它可以在sam时间进行读写操作:

`#!/usr/bin/python
import xlrd, xlwt
workbook = xlrd.open_workbook('nagios.xlsx')
workbook1 = xlwt.Workbook()
worksheet1 = workbook.sheet_by_name('contacts_users')
worksheet2 = workbook.sheet_by_name('contact_group_nagios')
    for row in range(1, worksheet2.nrows):
        print "value: ", worksheet2.cell(row,0).value
        print "value: ", worksheet2.cell(row,1).value
        s = worksheet2.cell(row,1).value
        grp_name = worksheet2.cell(row,0).value
        members = s.split(",")
            for member in members:
                for row1 in range(1, worksheet1.nrows):
                    if member == worksheet1.cell(row1,0).value:
                        s1 = worksheet1.cell(row1,3).value
                        s1 += grp_name
                        worksheet1.append(row1,3, s1)`

0 个答案:

没有答案