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)
# generate chart plt.bar(students.Name, students.Score, color='orange') 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'
# Establish the mapping based on the first row # headers; these will become the keys of our dictionary if i == 0: keys = tuple(text) continue # Construct a dictionary for this row, mapping # keys to values for this row row_data = tuple(text) data.append(row_data) for hero in heroes: hero_doc = Document() hero_doc.add_heading(hero, level=1) table = hero_doc.add_table(rows=1, cols=4) table.style = 'TableGrid' hdr_cells = table.rows[0].cells hdr_cells[0].text = unicode('Номер сцены', 'utf-8') hdr_cells[0].width = 1097280 hdr_cells[1].text = unicode('Описание', 'utf-8') hdr_cells[1].width = 4846320 hdr_cells[2].text = unicode('Персонажи', 'utf-8') hdr_cells[2].width = 2423160 hdr_cells[3].text = unicode('Примечания', 'utf-8') hdr_cells[3].width = 20583680 for row in data: if hero in u''.join(row[4]):
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')