Esempio n. 1
0
def finalizer(filed=[]):
    files = [
        "static/merge/planning and organising.docx",
        "static/merge/customer service.docx", "static/merge/leadership.docx",
        "static/merge/commercial awareness.docx",
        "static/merge/initiative.docx",
        "static/merge/persuasive oral communication.docx"
    ]
    output_doc = Document("static/merge/nicopon.docx")
    for file in filed:
        if file in files:
            pass
        else:
            files.append(file)
    for index, file in enumerate(files):
        try:
            input_doc = Document(file)
            paro = 0
            if index < len(files):
                output_doc.add_page_break()
            for para in input_doc.paragraphs:
                get_para_data(output_doc, para, paro)
                paro += 1
        except Exception as e:
            print("mhhh")
            print(e)
    p = output_doc.add_paragraph()
    r = p.add_run()
    r.add_picture('static/end.PNG', width=Inches(7.09), height=Inches(8.76))
    output_doc.save('static/merge/report.docx')
Esempio n. 2
0
def main(directory, file_name):

    if not directory:
        return
    if not file_name:
        file_name = 'test'

    document = Document()
    total_lines = 0
    for root, dirs, fs in os.walk(directory):
        for f in fs:
            suffix = os.path.splitext(f)[1]
            if suffix not in [".java", ".py", ".js", ".go", ".css", ".html", ".cpp", ".h"]:
                continue

            fpath = os.path.join(root, f)
            with open(fpath, "r") as fp:
                try:
                    lines = fp.readlines()
                except Exception as e:
                    print(fpath)
                    continue

                for line in lines:
                    line = line.strip("\n").strip("\r\n")
                    if not line:
                        continue
                    if "__author__ " in line or "__datetime__" in line:
                        continue

                    if total_lines > 3500:
                        break
                    document.add_paragraph(line)
                    total_lines += 1

    document.save(file_name+".docx")
Esempio n. 3
0
def merger(docs=[]):
    list_of_data = []
    list_of_names = []
    for z in docs:
        name = z.split(".")
        na = name[0]
        list_of_names.append(na)
    list_of_names = session["docies"]
    for x in docs:
        list_of_data.append(read_table(x))
    #documentx = Document("static/merge/nicopon.docx")
    y = 0
    x = 0
    op = list_of_data
    list_of_comments = []
    k = 0
    m = 0
    for x in range(len(op)):
        templist = []
        for y in op[x]:
            kk = y['comments']
            kk = str(kk).replace("+", "")
            kk = str(kk).replace("-", "")
            templist.append(kk)
        list_of_comments.append(templist)

    list_of_titles = []
    for x in range(len(op)):
        templist = []
        print(x)
        for y in op[x]:
            print(y['title'])
            templist.append(y['title'])
        list_of_titles.append(templist)
    post = 0
    print(list_of_titles)
    #return(0)
    list_of_filex = []
    for x in range(len(list_of_titles)):
        for y in range(len(list_of_titles[x])):
            if x == 0:
                if list_of_titles[x][y] in list_of_titles[1]:
                    nn = list_of_titles[x][y]
                    ind = list_of_titles[x + 1].index(nn)
                    ti = list_of_titles[x][y]
                    ti = ti.split("\n")
                    ti = ti[0]
                    titi = "static/merge/" + str(ti) + ".docx"
                    titi = titi.lower()
                    list_of_filex.append(titi)
                    documentx = Document()
                    documentx.add_heading(list_of_titles[x][y])
                    i = 0
                    while i < len(list_of_titles):
                        head = list_of_names[i] + '\n'
                        p = documentx.add_paragraph('\n')
                        p.add_run(head).bold = True
                        if i == 0:
                            p.add_run(list_of_comments[x][y])
                        else:
                            p.add_run(list_of_comments[x + 1][ind])
                        i += 1
                    documentx.save(titi)
                else:
                    ti = list_of_titles[x][y]
                    ti = ti.split("\n")
                    ti = ti[0]
                    titi = "static/merge/" + ti + ".docx"
                    titi = titi.lower()
                    list_of_filex.append(titi)
                    documentx = Document()
                    documentx.add_heading(list_of_titles[x][y])
                    head = list_of_names[x] + '\n'
                    p = documentx.add_paragraph('\n')
                    p.add_run(head).bold = True
                    p.add_run(list_of_comments[x][y])
                    documentx.save(titi)
            else:
                if list_of_titles[x][y] in list_of_titles[0]:
                    pass
                else:
                    ti = list_of_titles[x][y]
                    ti = ti.split("\n")
                    ti = ti[0]
                    titi = "static/merge/" + str(ti) + ".docx"
                    titi = titi.lower()
                    list_of_filex.append(titi)
                    documentx = Document()
                    documentx.add_heading(list_of_titles[x][y])
                    head = list_of_names[x] + '\n'
                    p = documentx.add_paragraph('\n')
                    p.add_run(head).bold = True
                    p.add_run(list_of_comments[x][y])
                    documentx.save(titi)
    print("kkk")
    print(list_of_filex)
    finalizer(list_of_filex)
Esempio n. 4
0
def make_docx(infile):

  #generate facture number and filename for saving
  facture_n, outfile = create_facture_n()

  #step 1: get info from text
  commande_n, reference_n, total_ht, total_tva, total_ttc, tasks, prices = get_contents(infile)
  

  #step 2b: append the reference number to the end of the pdf file
  move_pdf(infile, reference_n)

  #step 3: make the doc file
  #prepare shadings for 2 final table cells
  shading_1 = parse_xml(r'<w:shd {} w:fill="#99ccff"/>'.format(nsdecls('w')))
  shading_2 = parse_xml(r'<w:shd {} w:fill="#99ccff"/>'.format(nsdecls('w')))

  newdoc = Document()

  #Title info
  p1 = newdoc.add_paragraph()
  p1.add_run('Tom Viart').bold = True
  p1.add_run('''
132 rue du Chemin Vert
75011 PARIS
Tél : 06 47 59 86 17''')
  p1.add_run('''
Identifiant SIRET : 75105892600021
N° TVA : FR 68 751058926''').bold = True

  p2 = newdoc.add_paragraph('À l’attention d’')
  p2.add_run('ALTO').bold = True
  p2.add_run('''
99, rue du Faubourg Saint Martin
75010 PARIS
  ''')
  p2.alignment = WD_ALIGN_PARAGRAPH.RIGHT

  today = datetime.datetime.today().strftime('%d/%m/%Y')
  p3 = newdoc.add_paragraph()
  p3.add_run('FACTURE %d' % facture_n).bold = True
  p3.add_run('''
  En date du %s''' % today)
  p3.alignment = WD_ALIGN_PARAGRAPH.CENTER


  #make the table of prices
  table = newdoc.add_table(rows=5, cols=2)
  table.style = 'Table Grid'
  table.alignment = WD_ALIGN_PARAGRAPH.CENTER


  # format cell widths
  for cell in table.columns[0].cells:
    cell.width = Inches(4.0)
  for cell in table.columns[1].cells:
    cell.width = Inches(0.9)

  a = table.cell(0, 0)
  b = table.cell(0,1)
  A = a.merge(b)

  tt = 'Commande N° %s \nRéférence %s\n' % (commande_n,reference_n)
  A2 = A.add_paragraph(tt)
  A2.alignment = WD_ALIGN_PARAGRAPH.CENTER

  c = table.cell(1,0)
  c.text = tasks
  d = table.cell(1,1)
  d.text = prices
  d.paragraphs[0].paragraph_format.alignment = WD_ALIGN_PARAGRAPH.CENTER
  e = table.cell(2,0)
  e.text = "Total HT"
  e.paragraphs[0].paragraph_format.alignment = WD_ALIGN_PARAGRAPH.CENTER
  e2 = table.cell(2,1)
  e2.text = total_ht
  e2.paragraphs[0].paragraph_format.alignment = WD_ALIGN_PARAGRAPH.CENTER
  f = table.cell(3,0)
  f.text = "TVA 20 %"
  f.paragraphs[0].paragraph_format.alignment = WD_ALIGN_PARAGRAPH.CENTER
  f2 = table.cell(3,1)
  f2.text = total_tva
  f2.paragraphs[0].paragraph_format.alignment = WD_ALIGN_PARAGRAPH.CENTER
  g = table.cell(4,0)
  g.text = "Total TTC"
  g.paragraphs[0].paragraph_format.alignment = WD_ALIGN_PARAGRAPH.CENTER
  g._tc.get_or_add_tcPr().append(shading_1)
  g2 = table.cell(4,1)
  g2.text = total_ttc
  g2.paragraphs[0].paragraph_format.alignment = WD_ALIGN_PARAGRAPH.CENTER
  g2._tc.get_or_add_tcPr().append(shading_2)




  ### End of document -- does not change
  newdoc.add_paragraph('''\n\nValeur en votre aimable règlement à réception (RIB ci-joint)
  ''')
  newdoc.add_paragraph('''\nRELEVE D’IDENTITE BANCAIRE''')

  table2 = newdoc.add_table(rows=2, cols=4)
  table2.style = 'Table Grid'

  a = table2.cell(0,0)
  a.text = "Banque"
  a = table2.cell(0,1)
  a.text = "Guichet"
  a = table2.cell(0,2)
  a.text = "Numéro de compte"
  a = table2.cell(0,3)
  a.text = "Clé RIB"

  b = table2.cell(1,0)
  b.text = "10278"
  b = table2.cell(1,1)
  b.text = "06041"
  b = table2.cell(1,2)
  b.text = "00020864601"
  b = table2.cell(1,3)
  b.text = "54"


  newdoc.add_paragraph('''
  IDENTIFICATION INTERNATIONALE''')

  table3 = newdoc.add_table(rows=1, cols=1)
  table3.style = 'Table Grid'
  a = table3.cell(0,0)
  a.text = '''IBAN : FR76 1027 8060 4100 0208 6460 154
BIC : CMCIFR2A'''


  newdoc.save(outfile)
  out_location = os.path.abspath(os.path.join(os.getcwd(), outfile))

  # Update the facture xls document using update facture() function
  try:
    update_facture(facture_n, reference_n, total_ht)
    print("   Created file: ",outfile)
  except:
    print("!! Error making excel file for {}".format(infile))
    #print("\n".join([commande_n, reference_n, total_ht, total_tva, total_ttc, tasks, prices]))
    

  #open DOC file
  open_file_for_tom(r'C:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE', out_location)
  
  #create a warning message if not all values were found
  if '' in [commande_n, reference_n, total_ht, total_tva, total_ttc, tasks, prices]:
    from easygui import msgbox
    msgbox(msg='Error: program did not correctly find all values', title='Error', ok_button='OK', image=None, root=None)
    errors = pd.DataFrame([commande_n, reference_n, total_ht, total_tva, total_ttc, tasks, prices],columns = ['commande_n', 'reference_n', 'total_ht', 'total_tva', 'total_ttc', 'tasks', 'prices'])
    errors.to_csv('errors.csv',index=False)
Esempio n. 5
0
plt.title('Student Score', fontsize=16)
plt.xlabel('Name')
plt.ylabel('Score')

plt.xticks(students.Name, rotation='90')
plt.tight_layout()
# plt.show()
plt.savefig(imgname)

# generate word
document = Document()
document.add_heading('Data analysis Report', level=0)
first_student = students.iloc[0, :]['Name']
first_score = students.iloc[0, :]['Score']

p = document.add_paragraph('The highest score is student ')
p.add_run(str(first_student)).bold = True
p.add_run(', score is ')
p.add_run(str(first_score)).bold = True

p1 = document.add_paragraph(
    f'Totally {len(students.Name)} students attended the test, the summary of the testing is:'
)

table = document.add_table(rows=len(students.Name) + 1, cols=2)
table.style = 'LightShading-Accent1'

table.cell(0, 0).text = 'Student Name'
table.cell(0, 1).text = 'Student Score'

for i, (index, row) in enumerate(students.iterrows()):
Esempio n. 6
0
def merger(docs=[]):
    list_of_data = []
    list_of_names = []
    for z in docs:
        name = z.split(".")
        na = name[0]
        k = na.split("static/merge/")
        na = k[1]
        list_of_names.append(na)
    for x in docs:
        list_of_data.append(read_table(x))


##    print(list_of_names)
##    print(list_of_data)
##    return(0)

    documentx = Document("static/merge/start.docx")
    documentx.add_page_break()
    y = 0
    #print(list_of_data[0][0])
    x = 0
    op = list_of_data
    list_of_comments = []
    k = 0
    m = 0
    while True:
        templist = []
        try:
            for y in op[m]:
                templist.append(y['comments'])
            list_of_comments.append(templist)
        except Exception as e:
            break
        m += 1

    list_of_titles = []
    k = 0
    for x in op:
        templist = []
        for y in op[0]:
            templist.append(y['title'])
        list_of_titles.append(templist)
        k += 1
        list_of_titles = list_of_titles[0]
        break
    post = 0
    for data in list_of_data:
        com = 0
        for z in data[0]:
            xc = len(data[0])
            documentx.add_heading(list_of_titles[post], level=1)
            post += 1
            y = len(list_of_data)
            x = 0
            #print(list_of_comments)
            while x < len(list_of_data):
                print(x, com)
                head = list_of_names[x] + '\n'
                p = documentx.add_paragraph('\n')
                p.add_run(head).bold = True
                p.add_run(list_of_comments[x][com])
                x += 1
            com += 1
            documentx.add_page_break()
        break
    documentx.save('static/merge/report.docx')