forked from FRReinert/PySSRS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoadReport.py
More file actions
61 lines (45 loc) · 1.48 KB
/
Copy pathLoadReport.py
File metadata and controls
61 lines (45 loc) · 1.48 KB
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import connection_data as d
import context
import os
from SSRS import SSRS
RS = SSRS(d._service, d._execution, d._user, d._psw)
'''
Part 1
This Section will load the report and it's data
you can get parameters data, page size, and every info from it
'''
try:
Report = RS.RequestReport(path='/Faturamento/Notas por Transportadora')
except BaseException as e:
print('Error loadint report: %s' % str(e))
'''
Part 2
This section will use the pre-loaded data to render the report
'''
try:
# Put the parameters into a dictionary
Parameters = {
'Transp': -1,
'Frete' : 'C'
}
RenderedReport = RS.RenderReport(LoadedReport=Report, format='PDF', parameters=Parameters)
except BaseException as e:
print('Error rendering report: %s' % str(e))
# This block will return all the information that SSRS can handle
for k, v in RenderedReport.items():
if k == 'Result':
pass
else:
print(k,': ',v)
'''
This block will render the report into a file
But you can use it in Django/Flask Request, for example...
<> IMPORTANT - If you want to render a file <>
Compiled files like PDF, Word, Excel should use "wb" on the file opening
Text based files (xml, html...) are "OK" to use the "w" mode
'''
filename = os.path.join(os.path.dirname(__file__),'report'+ '.' + RenderedReport['Extension'])
fopen = open(filename, 'wb')
fopen.write(RenderedReport['Result'])