Python Generate Reports - majorsilence/My-FyiReporting GitHub Wiki
You can download the python wrapper for RdlCmd from the release page or you can download it from the master branch.
- https://github.com/majorsilence/My-FyiReporting/releases
- https://github.com/majorsilence/My-FyiReporting/tree/master/LanguageWrappers/python
- Examples of using python are in the Examples folder in the above link.
Tested with python-3.13.2.
The recommend way to use this code is to copy the report.pyfile into your project. It is a thin layer and rarely changes.
Details
report.py
- Class: Report(path_to_rdl_file, path_to_rdlcmd, path_to_dotnet)
- Functions:
- export(export_type, save_path)
- export_type: "pdf", "csv", "xslx", "xml", "rtf", "tif", "html"
- If type does not match it will default to pdf
- save_path: the directory path and file name that will be generated
- export_type: "pdf", "csv", "xslx", "xml", "rtf", "tif", "html"
- export_to_memory(export_type)
- export type: "pdf", "csv", "xslx", "xml", "rtf", "tif", "html"
- If type does not match it will default to pdf
- export(export_type, save_path)
Examples
The examples demonstrate setup and generating a report.
basic example
Example of calling a basic report and generating the file test1.pdf.
#! /usr/bin/env python
import sys
sys.path.append("..")
import report
import os
import platform
# SETUP
current_directory = os.path.dirname(os.path.abspath(__file__))
base_directory = os.path.join(current_directory, '..', '..', '..')
base_directory = os.path.abspath(base_directory)
db_path = os.path.join(current_directory, '..', '..', '..', 'Examples', 'northwindEF.db')
db_path = os.path.abspath(db_path)
report_path = os.path.join(current_directory, '..', '..', '..', 'Examples', 'SqliteExamples', 'SimpleTest1.rdl')
report_path = os.path.abspath(report_path)
if platform.system() == 'Windows':
# if self hosted or on windows we do not need to set the path to dotnet, rdlcmd can be run directly
path_to_dotnet = None
path_to_rdlcmd = os.path.join(base_directory, "RdlCmd\\bin\\Debug\\net8.0\\RdlCmd.exe")
else:
# dotnet is required to run rdlcmd
path_to_dotnet= "dotnet"
path_to_rdlcmd = os.path.join(base_directory, "RdlCmd/bin/Debug/net8.0/RdlCmd.dll")
path_to_rdlcmd = os.path.abspath(path_to_rdlcmd)
output_directory = os.path.join(current_directory, 'output')
if not os.path.exists(output_directory):
os.makedirs(output_directory)
# REPORT EXAMPLE
rpt = report.Report(report_path, path_to_rdlcmd, path_to_dotnet)
rpt.set_connection_string('Data Source=' + db_path)
rpt.export("pdf", os.path.join(output_directory, 'test1.pdf'))
Example generating setting parameters and a connection string
#! /usr/bin/env python
import sys
sys.path.append("..")
import report
import os
import platform
# SETUP
current_directory = os.path.dirname(os.path.abspath(__file__))
base_directory = os.path.join(current_directory, '..', '..', '..')
base_directory = os.path.abspath(base_directory)
db_path = os.path.join(current_directory, '..', '..', '..', 'Examples', 'northwindEF.db')
db_path = os.path.abspath(db_path)
report_path = os.path.join(current_directory, '..', '..', '..', 'Examples', 'SqliteExamples', 'SimpleTest3WithParameters.rdl')
report_path = os.path.abspath(report_path)
if platform.system() == 'Windows':
# if self hosted or on windows we do not need to set the path to dotnet, rdlcmd can be run directly
path_to_dotnet = None
path_to_rdlcmd = os.path.join(base_directory, "RdlCmd\\bin\\Debug\\net8.0\\RdlCmd.exe")
else:
# dotnet is required to run rdlcmd
path_to_dotnet= "dotnet"
path_to_rdlcmd = os.path.join(base_directory, "RdlCmd/bin/Debug/net8.0/RdlCmd.dll")
path_to_rdlcmd = os.path.abspath(path_to_rdlcmd)
output_directory = os.path.join(current_directory, 'output')
if not os.path.exists(output_directory):
os.makedirs(output_directory)
# REPORT EXAMPLE
rpt = report.Report(report_path, path_to_rdlcmd, path_to_dotnet)
rpt.set_parameter("TestParam1", 'I am a parameter value.')
rpt.set_parameter("TestParam2", 'The second parameter.')
rpt.set_connection_string('Data Source=' + db_path)
rpt.export("pdf", os.path.join(output_directory, 'test2-parameters.pdf'))
Generate report and return the data
This example generates a report and loads it into memory using the export_to_memory function. It prints the data to the console/web.
#! /usr/bin/env python
import sys
sys.path.append("..")
import report
import os
import platform
# SETUP
current_directory = os.path.dirname(os.path.abspath(__file__))
base_directory = os.path.join(current_directory, '..', '..', '..')
base_directory = os.path.abspath(base_directory)
db_path = os.path.join(current_directory, '..', '..', '..', 'Examples', 'northwindEF.db')
db_path = os.path.abspath(db_path)
report_path = os.path.join(current_directory, '..', '..', '..', 'Examples', 'SqliteExamples', 'SimpleTest1.rdl')
if platform.system() == 'Windows':
# if self hosted or on windows we do not need to set the path to dotnet, rdlcmd can be run directly
path_to_dotnet = None
path_to_rdlcmd = os.path.join(base_directory, "RdlCmd\\bin\\Debug\\net8.0\\RdlCmd.exe")
else:
# dotnet is required to run rdlcmd
path_to_dotnet= "dotnet"
path_to_rdlcmd = os.path.join(base_directory, "RdlCmd/bin/Debug/net8.0/RdlCmd.dll")
path_to_rdlcmd = os.path.abspath(path_to_rdlcmd)
# REPORT EXAMPLE
rpt = report.Report(report_path, path_to_rdlcmd, path_to_dotnet)
rpt.set_connection_string('Data Source=' + db_path)
data = rpt.export_to_memory("pdf")
print(data)
# This is where you output data on your site using wsgi, cgi, or whatever python framework/library you are using