forked from alocshrestha/Crystal_API
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrpi.py
85 lines (65 loc) · 1.64 KB
/
crpi.py
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
62
63
64
65
66
67
68
69
70
71
72
73
74
#dcr stuff here..
import sys, ast, uuid
import win32com
from win32com.client import Dispatch
def connect(rpt):
rep = openreport(rpt)
tbl = rep.Database.Tables.Item(1)
prop = tbl.ConnectionProperties('Password')
prop.Value = ""
prop = tbl.ConnectionProperties('Server')
prop.Value = ''
return rep
def openreport(name):
app = Dispatch('CrystalRunTime.Application')
return app.OpenReport(name)
def get_params(self):
return self.ParameterFields
#do not change the constants; ref:CRFieldValueType
def get_valuetype(self):
vtype = "none"
if self.valuetype == 12:
vtype = "string"
elif self.valuetype == 9:
vtype == "bool"
elif self.valuetype == 8:
vtype == "curr"
elif self.valuetype == 10:
vtype = "date"
elif self.valuetype == 16:
vtype = "datetime"
elif self.valuetype == 7:
vtype = "number"
elif self.valuetype == 11:
vtype = "time"
return vtype
def get_fieldname(self):
return self.parameterfieldname
def get_prompt_text(self):
return self.prompt
def get_literals(self):
return ast.literal_eval(self)
def gen_filekey():
x = uuid.uuid4()
return str(x)
#do not change the constants; ref:CRExportFormatType
def set_exportoption(r, typ):
exp = r.ExportOptions
key = gen_filekey()
filename = ""
if typ in "csv":
exp.DestinationType = 1
exp.DiskFileName = './output/'+key+'.csv'
exp.FormatType = 7
filename = key + '.csv'
elif typ in "pdf":
exp.DestinationType = 1
exp.FormatType = 31
exp.DiskFileName = './output/'+key+'.pdf'
filename = key + '.pdf'
elif typ in "excel":
exp.DestinationType = 1
exp.FormatType = 36
exp.DiskFileName = './output/'+key+'.xls'
filename = key + '.xls'
return filename