一个人的闲言碎语

dr0v

blog.drov.com.cn
一个人碎碎念。
About Me
A lazy security employee.

2015年5月12日星期二


首先应该是需要导入win32com.client模块
而且 据说必须在win系统里用 没有尝试mac下怎么处理这些东西
然后代码大概是这样的:
# -*- coding: utf-8 -*-  
import win32com.client as win32
import sys

new_report = {
    'virusname':[3,3,2],
    'area':[5,2,2],
    'level':[5,1,2],
    'sp':[7,2,1],
    'sp_des':[7,2,2],
    'phone':[8,2,1],
    'phone-des':[8,2,2],
    'url':[9,2,1],
    'url-des':[9,2,2],
    'bev-des':[3,4,2],
    'loc-des':[3,5,2],
    'int-des':[3,6,2],
    'gen':[11,1,1],
    'sf':[13,1,1],
    'other':[14,1,1]
    }

if __name__ == '__main__':
    word = win32.Dispatch("Word.Application")
    word.Visible = 0
    if len(sys.argv) <= 1:
        exit()
    word.Documents.Open(sys.argv[1])
    doc = word.ActiveDocument
    print doc.Tables.Count
    print doc.Tables(1).Rows.Count
    if doc.Tables.Count == 14:
        for i in new_report:
            if i == 'sp' or i == 'sp-des' or i == 'phone' or i == 'phone-des' or i == 'url' or i == 'url-des':
                icount = 1
                while icount < doc.Tables(new_report[i][0]).Rows.Count:
                    print i + ':' + doc.Tables(new_report[i][0]).Cell(Row=icount+1, Column=new_report[i][2]).Range.Text
                    icount = icount + 1
            else:
                print i + ':' + doc.Tables(new_report[i][0]).Cell(Row=new_report[i][1], Column=new_report[i][2]).Range.Text
    word.Quit()
Categories: ,

0 评论:

发表评论