-
Notifications
You must be signed in to change notification settings - Fork 0
/
excel1.py
211 lines (167 loc) · 6.12 KB
/
excel1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# from win32com.client import Dispatch
# xlApp = Dispatch("Excel.Application")
# xlWb1 = xlApp.Workbooks.Open("C:\Users\inprsha\Desktop\PA_Test_Detail_Faults.xlsx")
# xlSht1 = xlWb1.WorkSheets(3)
# xlSht1.Visible = True
# print xlSht1.Cells(3,2).Value
# xlApp.Application.Quit()
from win32com.client import Dispatch
import os
import win32com.client as win32
from excel2 import excel2
class excel1(object):
# This class fetches Device Details from MS Word Template and write in MS Excel Template
faults=[]
High = []
Medium = []
Low = []
device=[]
excel2Object=[]
def __init__(self):
word = Dispatch('Word.Application')
xlApp = Dispatch("Excel.Application")
xlApp.Visible = True
print "Please give path of Ms WOrd report template "
self.doc1 = word.Documents.Open(raw_input())
print "Please give path and name of excel file having fAULTS details e.g C:\Users\inprsha\Downloads\PA_Test_Detail_Faults.xlsx"
print "\n"
self.xlWb1 =xlApp.Workbooks.Open(raw_input())
self.xlSht1 = self.xlWb1.WorkSheets(3)
print "Please give path and name to save file e.g C:\Users\inprsha\Desktop\hello.xlsx"
print "\n"
self.xlWb1.SaveAs(raw_input())
# xlApp.Application.Quit()
def fetchpnum(self,searchable):
# print self.doc1.Paragraphs.Count
for i in range(1, self.doc1.Paragraphs.Count):
value = self.doc1.Paragraphs(i).Range.Text.lower()
if value.startswith(searchable.lower()):
return i
return 0
def highfaults(self):
start=self.fetchpnum('High severity faults in detail')
end=self.fetchpnum('Medium severity faults in detail')
for i in range(start+1,end):
value=self.doc1.Paragraphs(i).Range.Text
if value[:-1].lower()!="No High severity faults were observed.".lower():
self.High.append(value)
self.High=filter(lambda name: name.strip(), self.High)
self.faults.append(self.High)
# print "hello from fnctn"
# print self.High
# print "=============================="
def mediumfaults(self):
start=self.fetchpnum('Medium severity faults in detail')+1
end=self.fetchpnum('Low severity faults in detail')
for i in range(start,end):
value=self.doc1.Paragraphs(i).Range.Text
if value[:-1].lower()!="No Medium severity faults were observed.".lower():
self.Medium.append(value)
self.Medium=filter(lambda name: name.strip(), self.Medium)
self.faults.append(self.Medium)
def lowfaults(self):
start=self.fetchpnum('Low severity faults in detail')
end=self.fetchpnum('Comparison with respect to previous test ')
# print start
# print end
for i in range(start+1,end):
value=self.doc1.Paragraphs(i).Range.Text
if value[:-1].lower()!="No Low severity faults were observed.".lower():
self.Low.append(value)
self.Low=filter(lambda name: name.strip(), self.Low)
self.faults.append(self.Low)
def writeinxl(self):
self.xlSht1.Cells(16,4).Value=len(self.High)
self.xlSht1.Cells(17,4).Value=len(self.Medium)
self.xlSht1.Cells(18,4).Value=len(self.Low)
i=13
a=["Achilles","Nmap","Nessus","Mu-8000","ISIC"]
for m in range(0,3):
for k in range(0,len(self.faults[m])):
self.xlSht1.Rows(i).Insert()
self.xlSht1.Rows(i).Interior.Color="&hFFFFFF"
self.xlSht1.Cells(i,5).Value=self.faults[m][k]
s=self.xlSht1.Cells(i,5).Value
for imm in range(0,len(a)):
if s.find(a[imm]) != -1:
self.xlSht1.Cells(i,6).Value=a[imm]
i=i+1
def fetchdvcdetails(self):
rngDoc = self.doc1.Range(0, 0)
table = self.doc1.Tables(1)
self.device.append(table.Cell(Row=1, Column=2).Range.Text.split('.')[1])#device name
self.device.append(table.Cell(Row=1, Column=2).Range.Text.split('.')[2][:-1])#test run
# print table.Cell(Row=1, Column=2).Range.Text.split('.')[2]
self.device.append(table.Cell(Row=3, Column=2).Range.Text[:-1])#test date
table = self.doc1.Tables(4)
self.device.append(table.Cell(Row=5, Column=2).Range.Text[:-1])#os
self.device.append(table.Cell(Row=4, Column=2).Range.Text[:-1])#firmware version
# for i in range(len(self.device)):
# print self.device[i]
self.device=filter(lambda name: name.strip(), self.device)
def filldvcdetails(self):
self.xlSht1.Cells(3,2).Value=self.device[0]
self.xlSht1.Cells(4,2).Value=self.device[3]
self.xlSht1.Cells(5,2).Value=self.device[4]
self.xlSht1.Cells(6,2).Value=self.device[1]
self.xlSht1.Cells(7,2).Value=self.device[2]
def severity(self):
lenHigh=len(self.High)
lenMedium=len(self.Medium)
lenLow=len(self.Low)
i=13
for ip in range(0,lenHigh):
self.xlSht1.Cells(i,10).Value="High"
for m in range(1,11):
self.xlSht1.Cells(i,m).Font.Color="&hFF"
i=i+1
# print i
for ipp in range(0,lenMedium):
self.xlSht1.Cells(i,10).Value="Medium"
for m in range(1,11):
self.xlSht1.Cells(i,m).Font.Color="&hFF0000"
i=i+1
# print i
for ippp in range(0,lenLow):
self.xlSht1.Cells(i,10).Value="Low"
for m in range(1,11):
self.xlSht1.Cells(i,m).Font.Color="&h00"
i=i+1
# print i
def Srno(self):
p=13
total=len(self.High)+len(self.Medium)+len(self.Low)
for no in range(1,total+1):
self.xlSht1.Cells(p,1).Value=no
p=p+1
def storeforObj(self):
self.excel2Object.append(excel2(self.doc1,self.xlWb1,len(self.High),len(self.Medium),len(self.Low)))
for objs in self.excel2Object :
objs.fetchdvcdetails()
objs.filldvcdetails()
objs.NoOfFauts()
objs.testtype()
objs.devarrival()
objs.testedprotocol()
# self.excel2Object.append(excel2(len(self.High),len(self.Medium),len(self.Low)))
if __name__ == "__main__":
r =excel1()
r.fetchdvcdetails()
r.filldvcdetails()
r.highfaults()
r.mediumfaults()
r.lowfaults()
# print r.faults
r.writeinxl()
r.severity()
r.Srno()
r.storeforObj()
# print "=============================="
# print r.faults[2]
# # print r.High
# print "=============================="
# print r.faults[3]
# # print r.Medium
# # print "=============================="
# # print r.Low
# # print "=============================="