Skip to content

Commit

Permalink
XLSX Done
Browse files Browse the repository at this point in the history
Issue #103
  • Loading branch information
damies13 committed Sep 13, 2023
1 parent c0cde43 commit a8e573f
Showing 1 changed file with 147 additions and 195 deletions.
342 changes: 147 additions & 195 deletions rfswarm_reporter/rfswarm_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5553,228 +5553,180 @@ def xlsx_sections_errors(self, id):
base.debugmsg(5, "errortexts:", errortexts)

if grouprn:
# add 2 columns for count
table.add_column(Cm(1.8))
table.add_column(Cm(0.8))

for result_name in list(grpdata["resultnames"].keys()):
basekey = grpdata["resultnames"][result_name]["keys"][0]
base.debugmsg(5, "basekey:", basekey)
rdata = base.reportdata[id][basekey]

cellcol = 0
cellrow += 1
cellcol = 1
rownum += 1

# if cellrow > 0:
# table.add_row()
#
# table.rows[cellrow].cells[cellcol].paragraphs[0].style = "Table Header"
# table.rows[cellrow].cells[cellcol].paragraphs[0].text = "{}:".format(lbl_Result)
# table.rows[cellrow].cells[cellcol].paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.LEFT
#
# cellcol += 1
# table.rows[cellrow].cells[cellcol].paragraphs[0].style = "Table Cell"
# a = table.cell(cellrow, cellcol)
# b = table.cell(cellrow, cellcol + 1)
# A = a.merge(b)
# table.rows[cellrow].cells[cellcol].paragraphs[0].text = rdata['result_name']
# table.rows[cellrow].cells[cellcol].paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.LEFT
# table.rows[cellrow].cells[cellcol].paragraphs[0].FitText = True
#
# cellcol += 2
# table.rows[cellrow].cells[cellcol].paragraphs[0].style = "Table Header"
# table.rows[cellrow].cells[cellcol].paragraphs[0].text = "{}:".format(lbl_Test)
# table.rows[cellrow].cells[cellcol].paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.LEFT
#
# cellcol += 1
# table.rows[cellrow].cells[cellcol].paragraphs[0].style = "Table Cell"
# table.rows[cellrow].cells[cellcol].paragraphs[0].text = rdata['test_name']
# table.rows[cellrow].cells[cellcol].paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.LEFT
#
# cellcol += 1
# table.rows[cellrow].cells[cellcol].paragraphs[0].style = "Table Header"
# table.rows[cellrow].cells[cellcol].paragraphs[0].text = "{}:".format(lbl_Script)
# table.rows[cellrow].cells[cellcol].paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.LEFT
# # table.columns[cellcol].width = Cm(1.8)
#
# cellcol += 1
# table.rows[cellrow].cells[cellcol].paragraphs[0].style = "Table Cell"
# table.rows[cellrow].cells[cellcol].paragraphs[0].text = rdata['script']
# table.rows[cellrow].cells[cellcol].paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.LEFT
#
# cellcol += 1
# table.rows[cellrow].cells[cellcol].paragraphs[0].style = "Table Header"
# table.rows[cellrow].cells[cellcol].paragraphs[0].text = "{}:".format(lbl_Count)
# table.rows[cellrow].cells[cellcol].paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.LEFT
# # table.columns[cellcol].width = Cm(1.8)
#
# count = len(grpdata["resultnames"][result_name]["keys"])
# base.debugmsg(5, "count:", count)
# cellcol += 1
# table.rows[cellrow].cells[cellcol].paragraphs[0].style = "Table Cell"
# table.rows[cellrow].cells[cellcol].paragraphs[0].text = str(count)
# table.rows[cellrow].cells[cellcol].paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.LEFT
self.xlsx_sections_errors_fill_cell(cellcol, rownum, "{}:".format(lbl_Result), "Table Heading", 0)
cellcol += 1
self.xlsx_sections_errors_fill_cell(cellcol, rownum, rdata['result_name'], "Table Data", 0)

cellcol += 1
self.xlsx_sections_errors_fill_cell(cellcol, rownum, "{}:".format(lbl_Test), "Table Heading", 0)
cellcol += 1
self.xlsx_sections_errors_fill_cell(cellcol, rownum, rdata['test_name'], "Table Data", 0)

cellcol += 1
self.xlsx_sections_errors_fill_cell(cellcol, rownum, "{}:".format(lbl_Script), "Table Heading", 0)
cellcol += 1
self.xlsx_sections_errors_fill_cell(cellcol, rownum, rdata['script'], "Table Data", 0)

cellcol += 1
self.xlsx_sections_errors_fill_cell(cellcol, rownum, "{}:".format(lbl_Count), "Table Heading", 0)
count = len(grpdata["resultnames"][result_name]["keys"])
cellcol += 1
self.xlsx_sections_errors_fill_cell(cellcol, rownum, str(count), "Table Data", 0)

if groupet:
for errortext in list(grpdata["resultnames"][result_name]["errortexts"].keys()):
basekey = grpdata["resultnames"][result_name]["errortexts"][errortext]["keys"][0]
base.debugmsg(5, "basekey:", basekey)
rdata = base.reportdata[id][basekey]

cellcol = 0
cellrow += 1
# table.add_row()
#
# table.rows[cellrow].cells[cellcol].paragraphs[0].style = "Table Header"
# table.rows[cellrow].cells[cellcol].paragraphs[0].text = "{}:".format(lbl_Error)
# table.rows[cellrow].cells[cellcol].paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.LEFT
#
# cellcol += 1
# a = table.cell(cellrow, cellcol)
# b = table.cell(cellrow, cellcol + 5)
# A = a.merge(b)
#
# table.rows[cellrow].cells[cellcol].paragraphs[0].style = "Table Cell"
# table.rows[cellrow].cells[cellcol].paragraphs[0].text = rdata['error']
# table.rows[cellrow].cells[cellcol].paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.LEFT
#
# cellcol += 6
# table.rows[cellrow].cells[cellcol].paragraphs[0].style = "Table Header"
# table.rows[cellrow].cells[cellcol].paragraphs[0].text = "{}:".format(lbl_Count)
# table.rows[cellrow].cells[cellcol].paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.LEFT
# # table.columns[cellcol].width = Cm(1.8)
#
# count = len(grpdata["resultnames"][result_name]["errortexts"][errortext]["keys"])
# base.debugmsg(5, "count:", count)
# cellcol += 1
# table.rows[cellrow].cells[cellcol].paragraphs[0].style = "Table Cell"
# table.rows[cellrow].cells[cellcol].paragraphs[0].text = str(count)
# table.rows[cellrow].cells[cellcol].paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.LEFT
#
# if showimages:
# cellcol = 0
# cellrow += 1
# table.add_row()
#
# table.rows[cellrow].cells[cellcol].paragraphs[0].style = "Table Header"
# table.rows[cellrow].cells[cellcol].paragraphs[0].text = "{}:".format(lbl_Screenshot)
# table.rows[cellrow].cells[cellcol].paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.LEFT
#
# cellcol += 1
# a = table.cell(cellrow, cellcol)
# b = table.cell(cellrow, cellcol + 7)
# A = a.merge(b)
# table.rows[cellrow].cells[cellcol].paragraphs[0].style = "Table Cell"
# if 'image_file' in rdata:
# run = table.rows[cellrow].cells[cellcol].paragraphs[0].add_run()
# run.add_picture(rdata['image_file'], width = imgsizew)
# else:
# table.rows[cellrow].cells[cellcol].paragraphs[0].text = lbl_NoScreenshot
# table.rows[cellrow].cells[cellcol].paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.LEFT
cellcol = 1
rownum += 1
self.xlsx_sections_errors_fill_cell(cellcol, rownum, "{}:".format(lbl_Error), "Table Heading", 0)
cellcol += 1
self.xlsx_sections_errors_fill_cell(cellcol, rownum, rdata['error'], "Table Data", 4)

cellcol += 5
self.xlsx_sections_errors_fill_cell(cellcol, rownum, "{}:".format(lbl_Count), "Table Heading", 0)
count = len(grpdata["resultnames"][result_name]["errortexts"][errortext]["keys"])
cellcol += 1
self.xlsx_sections_errors_fill_cell(cellcol, rownum, str(count), "Table Data", 0)

if showimages:
cellcol = 1
rownum += 1
self.xlsx_sections_errors_fill_cell(cellcol, rownum, "{}:".format(lbl_Screenshot), "Table Heading", 0)

cellcol += 1

if 'image_file' in rdata:
self.xlsx_sections_errors_fill_cell(cellcol, rownum, " ", "Table Data", 4)
img = openpyxl.drawing.image.Image(rdata['image_file'])
cellname = ws.cell(row=rownum, column=cellcol).coordinate

base.debugmsg(5, "img.width:", img.width, " img.height:", img.height) #, " img.info:", img.info)
# 31.75 32.60
# 22.23 22.82 ==> 70%
newiw = 850
ratio = newiw / img.width
base.debugmsg(5, "ratio:", ratio)
newih = img.height * ratio
base.debugmsg(5, "newih:", newih)
img.width = newiw
img.height = newih

newh = newih * 0.76
# 43.44 cm ==> 32.95 cm ==> 76%
base.debugmsg(5, "newh:", newh)
ws.row_dimensions[rownum].height = newh

ws.add_image(img, cellname)
else:
self.xlsx_sections_errors_fill_cell(cellcol, rownum, lbl_NoScreenshot, "Table Data", 4)

else:
for keyi in grpdata["resultnames"][result_name]["keys"]:
rdata = base.reportdata[id][keyi]

cellcol = 0
cellrow += 1
# table.add_row()
#
# table.rows[cellrow].cells[cellcol].paragraphs[0].style = "Table Header"
# table.rows[cellrow].cells[cellcol].paragraphs[0].text = "{}:".format(lbl_Error)
# table.rows[cellrow].cells[cellcol].paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.LEFT
#
# cellcol += 1
# a = table.cell(cellrow, cellcol)
# b = table.cell(cellrow, cellcol + 7)
# A = a.merge(b)
#
# table.rows[cellrow].cells[cellcol].paragraphs[0].style = "Table Cell"
# table.rows[cellrow].cells[cellcol].paragraphs[0].text = rdata['error']
# table.rows[cellrow].cells[cellcol].paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.LEFT
#
# if showimages:
# cellcol = 0
# cellrow += 1
# table.add_row()
#
# table.rows[cellrow].cells[cellcol].paragraphs[0].style = "Table Header"
# table.rows[cellrow].cells[cellcol].paragraphs[0].text = "{}:".format(lbl_Screenshot)
# table.rows[cellrow].cells[cellcol].paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.LEFT
#
# cellcol += 1
# a = table.cell(cellrow, cellcol)
# b = table.cell(cellrow, cellcol + 7)
# A = a.merge(b)
# table.rows[cellrow].cells[cellcol].paragraphs[0].style = "Table Cell"
# if 'image_file' in rdata:
# run = table.rows[cellrow].cells[cellcol].paragraphs[0].add_run()
# run.add_picture(rdata['image_file'], width = imgsizew)
# else:
# table.rows[cellrow].cells[cellcol].paragraphs[0].text = lbl_NoScreenshot
# table.rows[cellrow].cells[cellcol].paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.LEFT
cellcol = 1
rownum += 1

if groupet and not grouprn:
# add 2 columns for count
table.add_column(Cm(1.8))
table.add_column(Cm(0.8))
self.xlsx_sections_errors_fill_cell(cellcol, rownum, "{}:".format(lbl_Error), "Table Heading", 0)
cellcol += 1
self.xlsx_sections_errors_fill_cell(cellcol, rownum, rdata['error'], "Table Data", 4)

if showimages:
cellcol = 1
rownum += 1
self.xlsx_sections_errors_fill_cell(cellcol, rownum, "{}:".format(lbl_Screenshot), "Table Heading", 0)

cellcol += 1

if 'image_file' in rdata:
self.xlsx_sections_errors_fill_cell(cellcol, rownum, " ", "Table Data", 4)
img = openpyxl.drawing.image.Image(rdata['image_file'])
cellname = ws.cell(row=rownum, column=cellcol).coordinate

base.debugmsg(5, "img.width:", img.width, " img.height:", img.height) #, " img.info:", img.info)
# 31.75 32.60
# 22.23 22.82 ==> 70%
newiw = 850
ratio = newiw / img.width
base.debugmsg(5, "ratio:", ratio)
newih = img.height * ratio
base.debugmsg(5, "newih:", newih)
img.width = newiw
img.height = newih

newh = newih * 0.76
# 43.44 cm ==> 32.95 cm ==> 76%
base.debugmsg(5, "newh:", newh)
ws.row_dimensions[rownum].height = newh

ws.add_image(img, cellname)
else:
self.xlsx_sections_errors_fill_cell(cellcol, rownum, lbl_NoScreenshot, "Table Data", 4)

if groupet and not grouprn:
for errortext in list(grpdata["errortexts"].keys()):
basekey = grpdata["errortexts"][errortext]["keys"][0]
base.debugmsg(5, "basekey:", basekey)
rdata = base.reportdata[id][basekey]

cellcol = 0
cellrow += 1
colspan = 8

# if cellrow > 0:
# table.add_row()
#
# table.rows[cellrow].cells[cellcol].paragraphs[0].style = "Table Header"
# table.rows[cellrow].cells[cellcol].paragraphs[0].text = "{}:".format(lbl_Error)
# table.rows[cellrow].cells[cellcol].paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.LEFT
#
# cellcol += 1
# a = table.cell(cellrow, cellcol)
# b = table.cell(cellrow, cellcol + 5)
# A = a.merge(b)
#
# table.rows[cellrow].cells[cellcol].paragraphs[0].style = "Table Cell"
# table.rows[cellrow].cells[cellcol].paragraphs[0].text = rdata['error']
# table.rows[cellrow].cells[cellcol].paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.LEFT
#
# cellcol += 6
# table.rows[cellrow].cells[cellcol].paragraphs[0].style = "Table Header"
# table.rows[cellrow].cells[cellcol].paragraphs[0].text = "{}:".format(lbl_Count)
# table.rows[cellrow].cells[cellcol].paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.LEFT
#
# count = len(grpdata["errortexts"][errortext]["keys"])
# base.debugmsg(5, "count:", count)
# cellcol += 1
# table.rows[cellrow].cells[cellcol].paragraphs[0].style = "Table Cell"
# table.rows[cellrow].cells[cellcol].paragraphs[0].text = str(count)
# table.rows[cellrow].cells[cellcol].paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.LEFT
#
# if showimages:
# cellcol = 0
# cellrow += 1
# table.add_row()
#
# table.rows[cellrow].cells[cellcol].paragraphs[0].style = "Table Header"
# table.rows[cellrow].cells[cellcol].paragraphs[0].text = "{}:".format(lbl_Screenshot)
# table.rows[cellrow].cells[cellcol].paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.LEFT
#
# cellcol += 1
# a = table.cell(cellrow, cellcol)
# b = table.cell(cellrow, cellcol + 7)
# A = a.merge(b)
# table.rows[cellrow].cells[cellcol].paragraphs[0].style = "Table Cell"
# if 'image_file' in rdata:
# run = table.rows[cellrow].cells[cellcol].paragraphs[0].add_run()
# run.add_picture(rdata['image_file'], width = imgsizew)
# else:
# table.rows[cellrow].cells[cellcol].paragraphs[0].text = lbl_NoScreenshot
# table.rows[cellrow].cells[cellcol].paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.LEFT
cellcol = 1
rownum += 1

self.xlsx_sections_errors_fill_cell(cellcol, rownum, "{}:".format(lbl_Error), "Table Heading", 0)
cellcol += 1
self.xlsx_sections_errors_fill_cell(cellcol, rownum, rdata['error'], "Table Data", colspan)

cellcol += colspan + 1
self.xlsx_sections_errors_fill_cell(cellcol, rownum, "{}:".format(lbl_Count), "Table Heading", 0)
count = len(grpdata["errortexts"][errortext]["keys"])
cellcol += 1
self.xlsx_sections_errors_fill_cell(cellcol, rownum, str(count), "Table Data", 0)

if showimages:
cellcol = 1
rownum += 1
self.xlsx_sections_errors_fill_cell(cellcol, rownum, "{}:".format(lbl_Screenshot), "Table Heading", 0)

cellcol += 1

if 'image_file' in rdata:
self.xlsx_sections_errors_fill_cell(cellcol, rownum, " ", "Table Data", colspan)
img = openpyxl.drawing.image.Image(rdata['image_file'])
cellname = ws.cell(row=rownum, column=cellcol).coordinate

base.debugmsg(5, "img.width:", img.width, " img.height:", img.height) #, " img.info:", img.info)
# 31.75 32.60
# 22.23 22.82 ==> 70%
newiw = 850
ratio = newiw / img.width
base.debugmsg(5, "ratio:", ratio)
newih = img.height * ratio
base.debugmsg(5, "newih:", newih)
img.width = newiw
img.height = newih

newh = newih * 0.76
# 43.44 cm ==> 32.95 cm ==> 76%
base.debugmsg(5, "newh:", newh)
ws.row_dimensions[rownum].height = newh

ws.add_image(img, cellname)
else:
self.xlsx_sections_errors_fill_cell(cellcol, rownum, lbl_NoScreenshot, "Table Data", colspan)

if not grouprn and not groupet:
keys = list(base.reportdata[id].keys())
Expand Down

0 comments on commit a8e573f

Please sign in to comment.