Report#
Report APIs to create presentations and pdfs.
Image#
Create an image with name, type, and size in the active report session.
Syntax#
img = Image(name=<’name’>,source=<’file’>,path=<’path’>)
Arguments#
- name
The name of the image. Type = method img.name=<’name’>
- path
The path to the image if the source is of type “file”. Type = string img.path=<’image_file_path’>
- caption
The image caption. Type = string img.caption = <’image_caption>
- session
Returns the current session object. Type = object sesObj = img.session
- setAttributes()
Set multiple attributes simultaneously. Type = method img.setAttributes(name=<’name’>,source=<’file’>,path==<’image_file_path’>)
- source
Type = string img.source=<’graphic’/’file’> Note: In 2023.0 only ‘file’ is supported
- type
The image file type. Type = string img.type=<’png’/’jpg’/’bmp’/’tif’/’avi’/’gif’/’h3d’>
- ensureFit
Ensure Fit for Image. Type = bool img.ensureFit=<’True’/’False’>
Example#
image = Image()
image4.path = 'D:/temp/demo_image.png'
image4.caption = 'Demo Image'
Layout#
Handling of the report layouts.
Syntax#
reportSession.getLayouts()
Arguments#
- name
The layout name. Type = string layout.name
- getPlaceholderInfo
Returns a list of the placeholder types and the positions. Type = method
Example#
from hw.report.hwxpptxtypes import *
import os
session = ReportSession(name='MyReportSession')
for layout in session.getLayouts():
print('Layout = '+layout.name)
print('Placeholders:')
print(layout.getPlaceholderInfo())
print('--------------------')
Presentation#
Create or save a presentation in the active report session.
Syntax#
pres=Presentation()
Arguments#
- setAttributes()
Set multiple attributes simultaneously. Type = method pres.setAttributes(name=<name>,workDir=<’workDir’>,session=’ReportSession1’)
- name
The name of the presentation. Type = string pres.name=<’name’>
- size
The active session. Type = method pres.size(<’16:9’, ‘4:3’>
- session
The active session. Type = object sesObj = pres.session
- resolution
The presentation default resolution. Type = string pres.resolution = <’HD’/’UHD’/’Desktop’/’Medium’>
- savePDF
The presentation default resolution. Type = method Optional Attributes range=<’range_syntax’> pres.savePDF(<’pdfFile’>, range=’2,5-7’)
- savePPTX
The presentation default resolution. Type = method Optional Attributes open=<True/False> (Default False) mode=<’write’/’append’/’prepend’> (Default ‘write’) range=<’range_syntax’> pres.savePPTX(<’pptFile’>,open=True,mode=’append’, range=’2,5-7’)
- template
The presentation template which contains the layouts. Type = string pres.template=<’template_file’>
Example#
templatefile = os.path.join(src_path, "data", "pptTemplate.pptx")
outfile = os.path.join(os.path.expanduser("~"), "Documents", "alllayout.pptx").replace("\\","/")
pres = Presentation()
pres.template=templatefile
pres.resolution = 'UHD'
pres.savePPTX(outfile, open=True, mode='append', range='2,5-7')
ReportManager#
Report Manager to handle sessions.
Syntax#
rep_man=ReportManager()
Arguments#
- activeSession
Get the active report session. Type = string activeSession = rep_man.activeSession Set the active report session. rep_man.activeSession = <ReportSessionName>
- getAllSessionNames()
Get a list of all report sessions. Type = method sessionList = rep_man.getAllSessionNames()
Example#
for reportSession in rep_man.getAllSessionNames():
print(reportSession)
ReportSession#
Create a report session.
Syntax#
rep_ses=ReportSession()
Arguments#
- activePresentation
Active presentation of the report session. Type = object activePresentation = rep_ses.activePresentation
- reset
Resets the report session. Type = method rep_ses.reset()
- delete
Delete any entity in the session using the entity object. Type = method rep_ses.delete(<object>)
- name
Create a report session with the given name. The name of a created Report Session can’t be changed. Type = string rep_ses=ReportSession(name=”ReportSession1”)
- get
Get method on ReportSession to retrieve a handle for any entity. Type = method entity_obj=rep_ses.get(<entity_class>,<”name”> )
- getLayouts
Get list of available layouts. Type = method layoutList = rep_ses.getLayouts()
Example#
from hw.report.hwxpptxtypes import *
import os
session = ReportSession(name='MyReportSession')
for layout in session.getLayouts():
print('Layout = '+layout.name)
print('Placeholders:')
print(layout.getPlaceholderInfo())
print('--------------------')
Layout = Divider Slide - Orange
Placeholders:
Slide Number Placeholder 5 : ['Slide Number', [5, 90, 22, 5]]
Title 1 : ['Center Title', [12, 45, 75, 9]]
None
--------------------
Layout = Two table
Placeholders:
Table1 : ['Table', [55, 33, 42, 62]]
Slide Number Placeholder 2 : ['Slide Number', [5, 90, 22, 5]]
Table2 : ['Table', [4, 18, 46, 50]]
Title 1 : ['Title', [5, 8, 89, 5]]
None
--------------------
Layout = One Table with Text and Image
Placeholders:
Title 1 : ['Title', [5, 8, 89, 5]]
Table Placeholder 4 : ['Table', [4, 18, 60, 62]]
Text Placeholder 5 : ['Text', [5, 82, 89, 7]]
Picture Placeholder 9 : ['Picture', [66, 18, 28, 62]]
None
........
Slide#
Create a slide in the active report session.
Syntax#
slide=Slide()
Arguments#
- setAttributes()
Set multiple attributes simultaneously. Type = method slide.setAttributes(name=<’name’>,presentation=’Presentation1’)
- name
The name of the slide. Type = string slide.name=<’name’>
- presentation
Type = object (read only) pres=slide.presentation
- layout()
Slide layout. Setting a new slide layout deletes the existing one. Type = method slide.layout(<’slide_layout_name’>
- add()
Add an image, text or table. Type = method slimg= slide.add(<image/text/table>,name=<’name’>)
- titleText
Slide title text. Type = string slide.titleText(<’Slide Title’>)
- titlePosition
Slide title Position requires 4 positional arguments: x, y, width, and height. Type = double slide.titlePosition(x, y, width, height)
- applySlidePlaceholderList ()
Placeholders from the referenced slide will be used. Match by id if exist in both slides, no placeholder type check. Type = method slide. applySlidePlaceholderList (<slide_id>)
Example#
pres = Presentation()
imagea = Image()
imagea.path = <'patha'>
imagea.caption = 'Image A'
slide = Slide('SlideOneImage', presentation=pres)
slide.layout("One Images Only")
slide.add(imagea,"imga",position="Picture1")
SlideImage#
Create a slide image in an existing slide.
Syntax#
slideimage=SlideImage(slide)
Arguments#
- setAttributes()
Set multiple attributes simultaneously. Type = method slideimage.setAttributes(name=<name>, session=’ReportSession1’)
- caption
The image caption. Type = string slideimage.caption = <’image_caption>
- name
The slide name. Type = string slideimage.name=<’name’>
- source
The slide image source file. Only type file is supported in 2023. Type = string slideimage.source=<’file’>
- session
The report session where the slide image is located (read only) Type = object sesObj = slideimage.session
- type
The slide image type. Type = string imageType = slideimage.type
- path
The file path to the slide image. Type = string slideimage.path=<’file_path’>
- position
The slide image position as list [<x>,<y>,<width>,<heigth>] Type = list slideimage.position=[5,10,20,50]
- x
The slide image x value of the upper left corner in percentage. Type = double slideimage.x=<x>
y
The slide imagey value of the upper left corner in percentage. Type = double slideimage.y=<y>
- width
The slide image width value in percentage. Type = double slideimage.width=<width>
- heigth
The slide image height value in percentage. Type = double slideimage.heigth=<heigth>
Example#
slide_image = SlideImage(slide=<slide>, image=<image1>, position=[50, 13, 10, 21], name='SlideImage1')
slide_image.caption='Image 1'
SlideTable#
Create a slide table in the active report session.
Syntax#
sltab=SlideTable(slide)
Arguments#
- setAttributes()
Set multiple attributes simultaneously. Type = method sltab.setAttributes(name=<name>,csvFile=<’csv_file’>)
- name
The slide table name. Type = string sltab.name=<’name’>
- session
The active report session. (Read only) Type = object sesObj = sltab.session
- csvFile
The path to the table CSV file. Type = string sltab.csvFile=<’csv_file’>
- caption
The slide table caption. Type = string sltab.caption=<’slide table caption’>
- split
Turn auto split on/off. Type = Boolean sltab.split=<True/False>
- splitBy
Split by rows/columns. Type = string sltab.splitBy=<’rows’/’columns’>
- maxRows
The number of maximum rows where to split, default is 0. Type = integer sltab.maxRows(<integer>)
- maxColumns
The number of maximum columns where to split, default is 0. Type = string sltab.maxColumns(<integer>)
- position
The slide table position as list [<x>,<y>,<width>,<heigth>] Type = list sltab.position=[5,10,20,50]
- x
The slide table x value of the upper left corner in percentage. Type = double sltab.x=<x>
- y
The slide table y value of the upper left corner in percentage. Type = double sltab.y=<y>
- width
The slide table width value in percentage. Type = double sltab.width=<width>
- heigth
The slide image height value in percentage. Type = double slideimage.heigth=<heigth>
Example#
table = Table()
table.caption = 'Table caption'
table.csvFile = path5
table.split=True
table.maxColumns=5
table.maxRows=9
table.stretch
SlideText#
Create slide text.
Syntax#
slidetext=SlideText(slide)
Arguments#
- setAttributes()
Set multiple attributes simultaneously. Type = method slidetext.setAttributes(name=<name>, session=’ReportSession1’)
- name
The slide text name. Type = string slidetext.name=<’name’>
- session
The report session where the text is located (read only) Type = object sesObj = slidetext.session
- text
The text displayed in the slide text. Type = string slidetext.text=<’text’>
- position
The slide image position as list [<x>,<y>,<width>,<heigth>] Type = list slidetext.position=[5,10,20,50]
- x
The slide text x value of the upper left corner in percentage. Type = double slidetext.x=<x>
- y
The slide text y value of the upper left corner in percentage. Type = double slidetext.y=<y>
- width
The slide text width value in percentage. Type = double slidetext.width=<width>
- heigth
The slide text height value in percentage. Type = double slidetext.heigth=<heigth>
Example#
slidetext = Slidetext(slide=<slide>, text='Demo Slide text, name='SlideText1')
slidetext.position=[5,10,20,50]
Table#
Create a table with a default name in the active session
Syntax#
tab=Table()
Arguments#
- name
The table name. Type = string tab.name=<’name’>
- session
The session where the table is located (read only). Type = object sesObj = tab.session
- csvFile
Path to the table CSV file. Type = string tab.csvFile=<’csv_file’>
- caption
The table caption. Type = string tab.caption=<’caption’>
- split
Turn auto split on/off. Type = Boolean tab.split=<True/False>
- splitBy
Split by rows and columns. Type = string tab.splitBy=<’rows’/’columns’>
- stretch
Stretch the table to fill the available table width. Type = Boolean tab.stretch=<True/False>
- maxRows
The number of the maximum rows where to split, default is 0. Type = string tab.maxRows(<integer>)
- maxColumns
The number of maximum columns where to split, default is 0. Type = string tab.maxColumns(<integer>)
- setAttributes()
Set multiple attributes simultaneously. Type = method tab.setAttributes(name=<name>,csvFile=<’csv_file’>)
- addColumn(self)
Add Column to Table. Type = Method tab.addColumn()
- setDimension(self,rows:int,cols:int)
Set Dimensions of Table. Type = Method tab.setDimension(rows=<’rows’>, cols=<’cols’>)
- setCellValue(self, row:int,col:int,value)
Set Table Cell Value. Type = Method tab.setCellValue(row=<’row’>, col=<’col’>, value=<’value’>)
- getCellValue(self, row:int,col:int)
Get Table Cell Value. Type = Method tab.getCellValue(row=<’row’>, col=<’col’>)
- removeColumn(self, col:int)
Remove Table Column. Type = Method tab.removeColumn(col=<’col’>)
- removeRow(self, row:int)
Remove Table Row. Type = Method tab.removeRow(row=<’row’>)
- loadCsv(self,file:str)
Load CSV File. Type = Method tab.loadCsv(file=<’file path’>)
- exportCsv(self,file:str)
Export Table to Csv. Type = Method tab.exportCsv(file=<’file path’>)
- cell(self, row_idx, col_idx)
Get the Cell of Table. Type = Method tab.cell(row_idx=<row_idx>, col_idx=<’col_idx’>)
- mergeCells(self, cell1, cell2)
Merge Table Cells. Type = Method tab.mergeCells(cell1=<’cell1 obj’>, cell2=<’cell2 obj’>)
- addToCells(self, cell)
Add to the Table Cells. Type = Method tab.addToCells(cell=<’cell’>)
- rows(self)
Number of Rows. Type = Int tab.rows
- columns(self)
Number of Columns. Type = Int tab.columns
Example#
Create Table Object:
table = Table()
table.caption = 'Table caption'
table.csvFile = <csv file path>
table.split=<bool>
table.maxColumns=<int>
table.maxRows=<int>
table.rows = <int>
table.columns = <int>
To set table Dimensions:
table.setDimension(<rows>, <cols>)
To Load and Export Csv:
table.loadCsv(<csv file path>)
table.exportCsv(<csv file path>)
To Get Cell:
cell1 = table.cell(<row index>, <column index>)
cell2 = table.cell(<row index>, <column index>)
To Merge cells:
table.mergeCells(cell1, cell2)
To get Cell Run:
cell = table.cell(<row index>, <column index>)
run = cell.getCellRun(<index>)
To Remove Cell Run:
cell = table.cell(<row index>, <column index>)
cell.removeCellRun(<index>)
To add Run to Table Cell:
Get cell:
cell = table.cell(<row index>, <column index>)
run = txt.addCellRun(text=<'text'>,
font_name=<'font name'>,
font_size=<'font size'>,
font_color=<'font color'>,
bold=<'bold'>,
italic=<'italic'>,
underline=<'underline'>,
line_break=<'line break'>,
tab_space=<'tab space'>,
image_path=<'image path'>,
hyperlink=<'hyperlink'>)
To set Run properties:
run.runText = <text>
run.fontName = <font name>
run.fontSize = <font size>
run.fontColor = <font color>
run.boldFont = <bold>
run.italicFont = <italic>
run.underLine = <underline>
run.lineBreak = <line break>
run.tableSpace = <tab space>
run.runImagePath = <image path> # works only for word document
run.hyperLink = <hyperlink>
Text#
Create text with the default name and default text in active report session.
Syntax#
txt=Text()
Arguments#
- setAttributes()
Set multiple attributes simultaneously. Type = method txt.setAttributes(name=<’name’>, text=<’My text’>)
- name
The text name. Type = string txt.name=<’name’>
- session
The active session. (Read only) Type = object sesObj = txt.session
- text
The text string. Type = string txt.text=<’text’>
- getRun(self, index:int)
Get Run using Index. Type = method txt.getRun(index=<’index’>)
- addRun(self,
text : Optional[str] = “”, font_name : Optional[str] = “Arial”, font_size : Optional[int] = 9, font_color : Optional[List[int]] = [0,0,0], bold : Optional[bool] = “False”, italic : Optional[bool] = “False”, underline : Optional[bool] = “False”, line_break : Optional[bool] = “False”, tab_space : Optional[bool] = “False”, image_path : Optional[str] = “”, hyperlink : Optional[str] = “”
- )
Add Run. Type = Method txt.addRun()
- removeRun(self, index:int)
Remove Run. Type = Method txt.removeRun(index=<’index’>)
Example#
Create Text Object:
txt=Text(name=<'name'>, text=<'My text'>, session=<session>)
txt.text = <text>
To Get Run:
txt.getRun(index = <index>)
To Remove Run:
Txt.removeRun(index = <index>)
To add Run to Text:
run = txt.addRun(text=<'text'>,
font_name=<'font name'>,
font_size=<'font size'>,
font_color=<'font color'>,
bold=<'bold'>,
italic=<'italic'>,
underline=<'underline'>,
line_break=<'line break'>,
tab_space=<'tab space'>,
image_path=<'image path'>,
hyperlink=<'hyperlink'>)
To set Run properties:
run.runText = <text>
run.fontName = <font name>
run.fontSize = <font size>
run.fontColor = <font color>
run.boldFont = <bold>
run.italicFont = <italic>
run.underLine = <underline>
run.lineBreak = <line break>
run.tableSpace = <tab space>
run.runImagePath = <image path> # works only for word document
run.hyperLink = <hyperlink>