-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprintCodeGen.py
More file actions
55 lines (36 loc) · 1.1 KB
/
printCodeGen.py
File metadata and controls
55 lines (36 loc) · 1.1 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
from commonUtils import log, read_excel_file
import math
BASE_PRINT="""
With ActiveDocument.PrintSettings
.Copies = [[NO_COPIES]]
.PrintRange = prnPageRange
.PageRange = [[PAGE_RANGE]]
End With
ActiveDocument.PrintOut
"""
MACRO_END = """
End Sub
"""
MACRO_START = """
Sub printPages()
' This macro code is dynamically generated by "APPNAME"
"""
def generate_macro_code(no_pages_list):
try:
no_pages_list = list(map(lambda i: math.ceil(i), no_pages_list))
except TypeError as e:
log(e)
return e
# no_pages_list = [1,1,1313,1314]
printMacro = ""
printMacro+=f'{MACRO_START}\n'
for index, no_pages in enumerate(no_pages_list):
if index == 0:
print('pass')
continue
printMacro+=f'{BASE_PRINT.replace("[[NO_COPIES]]", str(no_pages)).replace("[[PAGE_RANGE]]", str(index+1))}\n'
printMacro+=MACRO_END
# print('hello')
# print(printMacro)
return printMacro
# generate_macro_code('C:/Users/sid/Desktop/test.xlsx', 1, 'a')