def writeRWFIB(result, document): answerInfo = result["answerInfo"] # 答案注释 idNum = result["id"] # uuid4 没用 questionInfo = result["questionInfo"] # 原文 videoUrl = result["videoUrl"] # 好像没用 splitedLst = re.compile(r"\[(.*?)\]").split(questionInfo) # print(len(splitedLst)) p = document.add_paragraph(None) if questionInfo != "": count = 0 for item in splitedLst: if count % 2 != 0: # set the every second item to bold and with color a = p.add_run(item) a.font.color.rgb = RGBColor(0x42, 0x24, 0xE9) a.bold = True else: p.add_run(item) count += 1 else: document.add_paragraph("无原文\n") document.add_paragraph("注释: ") document.add_paragraph(answerInfo) if videoUrl != "": p = document.add_paragraph("Some Video") add_hyperlink(p, 'link', videoUrl) document.add_page_break()
def Intro(self,company,manager,author): p = self.document.add_heading('INTRODUCTION', 0) p.alignment = WD_ALIGN_PARAGRAPH.CENTER l1 = self.document.add_paragraph(style = 'List Bullet') l1r = l1.add_run('Overview').bold = True style = self.document.styles['List Bullet'] font1 = style.font font1.name = 'Times New Roman' font1.color.rgb = RGBColor(23, 54, 93) font1.size = Pt(18) l1.style = self.document.styles['List Bullet'] p5 = self.document.add_paragraph('This report documents the findings for the Black Box Network Security Assessment of '+ company + ' The purpose of the engagement was to utilize exploitation techniques in order to identify and validate potential vulnerabilities in the perimeter security. ') p5.alignment = WD_ALIGN_PARAGRAPH.JUSTIFY records = ( ('Project Manager', manager), ('Onsite Technical Contact',author) ) table = self.document.add_table(rows=1, cols=2) table.style = 'Table Grid' hdr_cells = table.rows[0].cells hdr_cells[0].text = 'ROLE' hdr_cells[1].text = 'NAME' for qty, id, in records: row_cells = table.add_row().cells row_cells[0].text = str(qty) row_cells[1].text = id
def create_upload_file(location): today = datetime.date.today() yesterday = today - datetime.timedelta(days=1) path_or_stream = 'vansky_{}_{}.docx'.format(location, yesterday.strftime("%Y%m%d")) url = 'https://www.vansky.com/info/ZFBG08.html' resp = fetch(url) # step-1 post_entries = parse_article_entries(resp.text) metadata = get_paged_meta(url, location, num_pages=6) document = docx.Document() for meta in metadata: note, mata_time, article_content = get_article_content_meta( 'https://www.vansky.com/info/', meta['link'], meta['title'], meta['img']) p = document.add_paragraph('') r = p.add_run('({}) {}\n'.format(','.join(note), meta['title'])) r.font.bold = True #加粗 article_link = 'https://www.vansky.com/info/' + meta['link'] s = p.add_run('{}\n'.format(mata_time)) s.font.color.rgb = RGBColor(0xAA, 0xAA, 0xAA) add_hyperlink(p, article_link, article_link) p.add_run('\n{}\n'.format(article_content)) document.save(path_or_stream) google_upload(path_or_stream)
def font_converter(font_document, font_name, font_size, rgb_red, rgb_green, rgb_blue): font_style = font_document.styles['Normal'].font font_style.name = font_name font_style.size = Pt(font_size) font_style.color.rgb = RGBColor(rgb_red, rgb_green, rgb_blue) return font_style
def addContent(document, content): para = document.add_paragraph() run = para.add_run(content) font = run.font #font.name = 'Microsoft YaHei' font.size = Pt(16) font.color.rgb = RGBColor(0x08, 0x08, 0x08)
def check_words(file, words): document = Document(file) newdoc = Document() print(words) twords = tokenizer(words) for paragraph in document.paragraphs: tsentence = tokenizer(paragraph.text) nparagraph = newdoc.add_paragraph() font = nparagraph.add_run().font nparagraph.paragraph_format.alignment = paragraph.paragraph_format.alignment nparagraph.paragraph_format.left_indent = paragraph.paragraph_format.left_indent nparagraph.paragraph_format.right_indent = paragraph.paragraph_format.right_indent nparagraph.paragraph_format.line_spacing = 1 nparagraph.paragraph_format.space_after = 0 nparagraph.paragraph_format.space_before = paragraph.paragraph_format.space_before nparagraph.style.name = paragraph.style.name for word in tsentence: found = 0 for fword in twords: if fword[0] == word[0]: found = 1 if found: font.color.rgb = RGBColor(0x3f, 0x2c, 0x36) nparagraph.add_run(word[1] + ' ').bold = True font.highlight_color = WD_COLOR_INDEX.TURQUOISE else: nparagraph.add_run(word[1] + ' ').bold = False newdoc.save('newdoc.docx')
def set_tab_caption(self, caption_txt): run = self.doc.add_paragraph("").add_run(caption_txt) run.font.color.rgb = RGBColor(0, 0, 0) run.font.bold = True paragraph = self.doc.paragraphs[-1] paragraph.paragraph_format.alignment = WD_ALIGN_PARAGRAPH.CENTER
def setUpCorrectStyle(doc): global CORRECT_STYLE # CORRECT_STYLE preferences CORRECT_STYLE = doc.styles.add_style('Correct', WD_STYLE_TYPE.PARAGRAPH) CORRECT_STYLE.font.name = 'Calibri' CORRECT_STYLE.font.size = Pt(12) CORRECT_STYLE.font.color.rgb = RGBColor(245, 16, 16)
def load_echelle_calculee(excel, sheet, nbentete, log, thor): echelle = [] nbcolonnesignorees = thor["nbColonnesIgnorees"] try: # ouverture du fichier Excel wb = xlrd.open_workbook(excel, formatting_info=True) # Récupération de la feuille dans le fichie Excel sheet = wb.sheet_by_name(sheet) except BaseException as e: logupdate(log, "\nERROR : " + str(e)) if thor["debug"]: # si mode debug activ" # si mode debug activ" raise # levée de l'erreur return echelle try: # récupération de la taille du tableau, les fonctions max_row et # max_col retourne des valeurs éronnées maxrow = sheet.nrows # Nombre de lignes dans le fichier Excel for x in range(nbentete, maxrow): rgb = sheet.cell_value(x, 2 + nbcolonnesignorees).split(',') echelle.append( EchelleCalculee( sheet.cell_value(x, 0 + nbcolonnesignorees), sheet.cell_value(x, 1 + nbcolonnesignorees), "#" + str(RGBColor(int(rgb[0]), int(rgb[1]), int(rgb[2]))))) return echelle except BaseException as e: logupdate(log, "\nERROR : " + str(e)) if thor["debug"]: # si mode debug activ" # si mode debug activ" raise # levée de l'erreur
def __init__(self): self.document = Document() self.filename = 'public/' for style in self.document.styles: try: self.document.styles[style.name].font.name = 'Ancizar Sans' self.document.styles[style.name].font.color.rgb = RGBColor( 0x00, 0x00, 0x00) except: # pylint: disable=bare-except pass hyperlink_style = self.document.styles.add_style( 'List Hyperlink', enum.style.WD_STYLE_TYPE.PARAGRAPH) hyperlink_style.base_style = self.document.styles['List Bullet'] hyperlink_style.font.color.rgb = RGBColor(0x00, 0x00, 0xFF) hyperlink_style.font.underline = True self.case_count = 0