[Tutor] Remove a blank row of a Table
shouqiang1989 at sina.com
shouqiang1989 at sina.com
Fri Feb 27 04:19:51 CET 2015
Hello, everybody, I came accross a question a few days
ago. I wrote a Python script to copy something to a table in a word
file. For some reaons, there are some blank rows. And I want to remove
the blank rows. I tried many ways, but all didn't work. Below is the
code. The code in blue is to remove the blank row.
import codecs
import os
import textwrap
import win32com,string,shutil
from win32com.client import Dispatch,constants
def ReportPackage(reportName, reportApi, package=None):
desfile='C:\\Daten\\TestCASE5\\Model_hill.doc'
w = win32com.client.Dispatch('Word.Application')
w.Visible = 1
os.path.join(reportApi.GetReportDir(), reportName)
fd = w.Documents.Open(desfile) #open the model file info = reportApi.GetInfo()
if package is None:
package = reportApi.GetMainPackage()
result = info.GetResult()
execTime = info.GetExecutionTime()
pkgName =package.GetName()
else:
result = package.GetResult()
execTime = package.GetTime()
i=1
s=0
f=0
e=0
form = fd.Tables[6]
form.Rows.Add()
form.Rows.Last.Cells[2].Range.InsertAfter("%(pkgName)s" % {'pkgName': pkgName})
form.Rows.Last.Cells[3].Range.InsertAfter("%(executionTime)s" %{'executionTime': execTime})
form.Rows.Add()
lines = form.Rows.Last()
lines.Cells[0].Range.InsertAfter("Num")
lines.Cells[1].Range.InsertAfter("Time")
lines.Cells[2].Range.InsertAfter("Comment")
lines.Cells[3].Range.InsertAfter("Result")
testCase = package.GetTestCase(excludeSubPackages=reportApi.IsSet("hideSubPackages", "True"))
for reportItem in testCase.IterTestSteps():
try:
if reportItem.PResult == "NONE" : #constants.RESULT_NONE:
strResult = ''
else :
strResult = reportItem.PResult
lNam = textwrap.wrap(reportItem.PName)
maxLines = len(lNam)
fd.Tables[6].Rows.Add()
if strResult == 'SUCCESS':
fd.Tables[6].Rows.Last.Cells[3].Shading.BackgroundPatternColorIndex=4
s=s+1
elif strResult == 'FAILED':
fd.Tables[6].Rows.Last.Cells[3].Shading.BackgroundPatternColor=250
f=f+1
elif strResult == 'ERROR' :
fd.Tables[6].Rows.Last.Cells[3].Shading.BackgroundPatternColor=180
e=e+1
if strResult == 'SUCCESS' or strResult == 'FAILED' or strResult == 'ERROR' :
fd.Tables[6].Rows.Last.Cells[3].Range.InsertAfter(strResult)
fd.Tables[6].Rows.Last.Cells[2].Range.InsertAfter(lNam[0])
fd.Tables[6].Rows.Last.Cells[1].Range.InsertAfter(("%.3f" % reportItem.PTimestamp))
fd.Tables[6].Rows.Last.Cells[0].Range.InsertAfter(i)
i=i+1
else :
pass
for idx in xrange (1,maxLines) :
if fd.Tables[6].Rows[idx].Cells[1] == None :
fd.Tables[6].Rows[idx].Remove()
else :
pass
except :
break
s=str(s)
f=str(f)
e=str(e)
fd.Tables[6].Rows.Add()
fd.Tables[6].Rows.Last.Cells[2].Range.InsertAfter("s="+s+' ')
fd.Tables[6].Rows.Last.Cells[2].Range.InsertAfter("f="+f+' ')
fd.Tables[6].Rows.Last.Cells[2].Range.InsertAfter("e="+e+' ')
#insert the results in table 7
fd.Save.im_self
fd.Close()
def _ReportProjectElement():
return()
def ReportProject():
return()
Thanks in advance.
--------------------------------
Tutor maillist - Tutor at python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list