1
|
|
|
#!/usr/bin/env python |
2
|
|
|
# -*- coding: utf-8 -*- |
3
|
|
|
|
4
|
|
|
import sys |
5
|
|
|
from optparse import OptionParser |
6
|
|
|
|
7
|
|
|
from abstract_generator.AbstractGenerator import AbstractGenerator |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
def main(): |
11
|
|
|
usage = 'Usage: %prog [options] input.xlsx output.docx' |
12
|
|
|
version = '%prog 20161121' |
13
|
|
|
parser = OptionParser(usage=usage, version=version) |
14
|
|
|
parser.add_option('-i', '--imagedir', metavar='IMAGE_DIR', |
15
|
|
|
dest='image_dir', default='image', |
16
|
|
|
help='image directory (default image)') |
17
|
|
|
parser.add_option('-t', '--template', metavar='TEMPLATE_TYPE', |
18
|
|
|
dest='template_type', default='aini2016', |
19
|
|
|
help='template type: \'aini2016\' or \'jscpb2016\' (default aini2016)') |
20
|
|
|
(options, args) = parser.parse_args() |
21
|
|
|
if len(args) != 2: |
22
|
|
|
parser.error('incorrect number of arguments') |
23
|
|
|
input_xlsx = args[0] |
24
|
|
|
output_docx = args[1] |
25
|
|
|
template_docx = 'template-' + options.template_type + '.docx' |
26
|
|
|
|
27
|
|
|
abgen = AbstractGenerator(options.image_dir, options.template_type) |
28
|
|
|
abgen.read_xlsx(input_xlsx) |
29
|
|
|
abgen.write_docx(output_docx, template_docx) |
30
|
|
|
sys.exit() |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
if __name__ == '__main__': |
34
|
|
|
# main() |
35
|
|
|
abgen = AbstractGenerator('', 'jscpb2016') |
36
|
|
|
|
37
|
|
|
abgen.read_xlsx('eguide_20170923.xlsx') |
38
|
|
|
abgen.write_docx('output.docx', 'template-jscpb2017.docx') |
39
|
|
|
|