-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInvoiceDoc.py
More file actions
127 lines (91 loc) · 2.75 KB
/
Copy pathInvoiceDoc.py
File metadata and controls
127 lines (91 loc) · 2.75 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
'''
Created on 2014-4-22
@author: Sindo
'''
import os,sys,locale
import re
from docx import *
from datetime import date
from datetime import datetime
from datetime import timedelta
from Navigator import Navigator
def printSecSepor(seporName="========") :
print ""
print "========================================================================"
print "=========================== %s ===================================" % (seporName)
print "========================================================================"
print ""
class InvoiceDoc :
def __init__(self, userName, userPswd, workDir, debug=False):
self.debug = debug
self.userName = userName
self.userPswd = userPswd
self.workDir = workDir
def perform(self, docFile):
print "docFile is " + (docFile)
document = Document(docFile)
sections = document.sections
print "section_length:%d" % len(sections)
def testCase(self):
document = Document()
document.add_heading(u'云水谣主题餐厅', 0)
p = document.add_paragraph(u'小河直街店')
p.add_run('bold').bold = True
p.add_run(' and some ')
p.add_run('italic.').italic = True
document.add_heading('Heading, level 1', level=1)
document.add_paragraph('Intense quote', style='IntenseQuote')
document.add_paragraph(
'first item in unordered list', style='ListBullet'
)
document.add_paragraph(
'first item in ordered list', style='ListNumber'
)
#document.add_picture('monty-truth.png', width=Inches(1.25))
recordset = []
infoColDict = {
"qty" : 0,
"id": 1,
"desc": "TEST"
}
recordset.append(infoColDict)
infoColDict = {
"qty" : 0,
"id": 1,
"desc": "TEST"
}
recordset.append(infoColDict)
infoColDict = {
"qty" : 0,
"id": 1,
"desc": "TEST"
}
recordset.append(infoColDict)
table = document.add_table(rows=1, cols=3)
hdr_cells = table.rows[0].cells
hdr_cells[0].text = 'Qty'
hdr_cells[1].text = 'Id'
hdr_cells[2].text = 'Desc'
for item in recordset:
row_cells = table.add_row().cells
row_cells[0].text = str(item["qty"])
row_cells[1].text = str(item["id"])
row_cells[2].text = item["desc"]
document.add_page_break()
document.save('demo.docx')
if __name__ == '__main__': # sys.argv[0], sys.argv[1]
reload(sys)
sys.setdefaultencoding("utf-8")
print "InvoiceDoc_process_begin......" + sys.argv[0]
resVal = False
debugMode = False
userName = 'lijj'
userPswd = os.getenv("aintPswd")
workDir = u"E:"
invoiceDoc = InvoiceDoc(userName, userPswd, workDir, debugMode)
docFile = u"InvoiceTest.docx"
resVal = invoiceDoc.testCase()
resVal= invoiceDoc.perform(docFile)
printSecSepor()
if resVal: print "congratulations_your_work_is_done_successfully"
else: print "unfortunately_your_work_is_failed"