def sdf2ppt(mols=[]): mol_count=0 page_count=1 for mol in mols: # when we have num_mols_per_page mols, create new slide and header if mol_count % num_mols_per_page == 0: print "Creating new slide %i/%i" % (page_count, num_pages) new_slide = prs.slides.add_slide(text_slide_layout) title = new_slide.shapes.title title.text = "Docking Results for %s %i/%i" % (options.sdfile, page_count, num_pages) mol_count=0 page_count+=1 # # logger.debug("Processing molecule %s" % mol.GetProp("_Name")) Mol2PNG (mol,'%s.png' % ( mol.GetProp("_Name")), logger=logger ) img_path = '%s.png' % ( mol.GetProp("_Name")) # # track position in column if mol_count % (num_mols_per_page/2) == 0: pos_count=0 # # track position in row if mol_count < (num_mols_per_page/2): top = top_border_first_line else: top = top_border_second_line # # left=left_border+pos_count*image_width pos_count+=1 logger.debug("Image info: %i %i %i %i" % ( mol_count, pos_count, left, top)) #pic = new_slide.shapes.add_picture(img_path, Px(left), Px(top), Px(image_width), Px(image_height)) pic = new_slide.shapes.add_picture(img_path, Cm(left), Cm(top), Cm(image_width), Cm(image_height)) txBox = new_slide.shapes.add_textbox(Cm(left), Cm(top+image_height), Cm(image_width), Cm(label_vert_size)) tf = txBox.textframe tf.text = mol.GetProp("_Name") p = tf.paragraphs[0] p.font.size=Pt(12) p.alignment=PP_ALIGN.CENTER mol_count+=1 # # prs.save(options.sdfile.replace(".sdf", ".pptx"))
class TextFormatting: """ margin_top: margin_left: margin_bottom: margin_right: vertical_align: 'top', 'middle', 'bottom' """ margin_top: Cm = 0 margin_left: Cm = 0 margin_bottom: Cm = 0 margin_right: Cm = 0 vertical_align: str = 'middle' horizontal_align: str = 'centre' font_size: Pt = Pt(10) font_bold: bool = False font_italic: bool = False font_colour: Color = Color(rgb=(0.1, 0.1, 0.1))
def model_3(prs, title, pic_path): slide = prs.slides.add_slide(prs.slide_layouts[6]) slide.shapes.add_picture(ppt_bg_path, cm_to_in(0), cm_to_in(0), cm_to_in(25.4), cm_to_in(14.288)) img = slide.shapes.add_picture(pic_path, cm_to_in(0), cm_to_in(0), height=cm_to_in(11.72)) img.left = int(prs.slide_width / 4 + (prs.slide_width / 2 - img.width) / 2) img.top = int((prs.slide_height - img.height) / 2) title_box = slide.shapes.add_textbox(cm_to_in(2), cm_to_in(5.35), int(prs.slide_width / 3), cm_to_in(3.59)) paragraph = title_box.text_frame.add_paragraph() paragraph.text = title paragraph.font.size = Pt(44) paragraph.font.name = '微软雅黑' paragraph.font.color.rgb = RGBColor(255, 255, 255)
def handle(self, dbTitle, output): ''' See :meth:`.AbstractOutputHandler.handle`. ''' outString = "\n".join([ " | ".join("{0}".format(value) for value in row) for row in output ]) ppt = Presentation(self.__outputPath) slideIndex = self.__slideNum - 1 slide = ppt.slides[slideIndex] shape = self.__getTargetShape(slide) shape.text = outString textFrame = shape.text_frame textFrame.paragraphs[0].font.size = Pt(12) textFrame.word_wrap = True textFrame.auto_size = MSO_AUTO_SIZE.TEXT_TO_FIT_SHAPE ppt.save(self.__outputPath)
def slide_num(n, txt, pres): prs = Presentation(pres) slide = prs.slides[n] for shape in slide.shapes: if not shape.has_text_frame: continue text_frame = shape.text_frame a = df.iloc[0]['revision'] p = text_frame.paragraphs[0] run = p.add_run() run.text = txt.format(str(a)) font = run.font font.name = 'Source Sans Pro' font.size = Pt(16) font.bold = False font.italic = None # cause value to be inherited from theme font.color.rgb = RGBColor(0xff, 0xff, 0xff) prs.save(pres)
def doParagraph(args): global gPrs para = ' '.join(args).split('@') para = doReverseSubstitutions(para) slide = getCurrentSlide() shapes = slide.shapes bodyShape = shapes.placeholders[1] tf = bodyShape.text_frame id = 0 for b in para: id = id + 1 if id == 1: tf.text = b else: p = tf.add_paragraph() p.text = b p.font.size = Pt(24)
def get_line(color, connector, bright=None): try: colors_dict = { "Red": RGBColor(255, 0, 0), "Green": RGBColor(0, 255, 0), "Blue": RGBColor(0, 0, 255) } line = LineFormat(connector) line.fill.solid() line.fill.fore_color.rgb = colors_dict["{}".format(color)] if bright: line.color.brightness = 0.7 else: line.color.brightness = 0.5 line.width = Pt(7) return line.fill.fore_color.rgb except Exception as e: print(e)
def preflightaddshape(slide, msg, lvl, boxplacement): left = top = Inches(boxplacement) width = height = Inches(2.5) shape = slide.shapes.add_shape(MSO_SHAPE.RECTANGLE, left, top, width, height) fill = shape.fill fill.solid() if lvl == 'high': fill.fore_color.rgb = RGBColor(255, 0, 0) else: fill.fore_color.rgb = RGBColor(255, 255, 0) line = shape.line line.fill.background() shape.shadow.inherit = False shape.text = msg shape.text_frame.paragraphs[ 0].font.color.theme_color = MSO_THEME_COLOR.TEXT_1 shape.text_frame.paragraphs[0].font.color.size = Pt(10)
def create_stackedbar(data): # Define chart data chart_data = CategoryChartData() # Transpose data, because that's how the stacked bar chart data requirement for ppt is dataT = data.set_index('Scale').transpose() # Reverse order of columns, similar to 'Values in reverse order' in ppt dataT = dataT[dataT.columns[::-1]] # For each column in the transposed data, add a series to the data for col_id, col in enumerate(dataT.columns): chart_data.add_series(dataT.columns[col_id], (dataT.iloc[:, col_id])) data_cat_list = [] # Using the original data, create a list containing all the categories for i in range(1, data.shape[1]): data_cat_list.append(data.columns[i]) chart_data.categories = data_cat_list # Add chart to slide x, y, cx, cy = Cm(2), Cm(5), Cm(10), Cm(8) graphic_frame = slide.shapes.add_chart(XL_CHART_TYPE.COLUMN_STACKED, x, y, cx, cy, chart_data) chart = graphic_frame.chart # data labels plot = chart.plots[0] plot.has_data_labels = True data_labels = plot.data_labels data_labels.number_format = '0"%"' # value_axis value_axis = chart.value_axis value_axis.minimum_scale = 0 value_axis.maximum_scale = 100.0 value_axis.has_minor_gridlines = False tick_labels = value_axis.tick_labels tick_labels.number_format = '0"%"' tick_labels.font.bold = True tick_labels.font.size = Pt(14)
def plot_executivesummary(): TITLE_AND_CONTENT = 1 slide = prs.slides.add_slide(prs.slide_layouts[TITLE_AND_CONTENT]) shapes = slide.shapes title = shapes.title text_frame = title.text_frame p = text_frame.paragraphs[0] run = p.add_run() run.text = 'Executive Summary – Infrastructure Risk Overview ' font = run.font font.name = 'Verdana' font.size = Pt(15) font.bold = True font.italic = None for shape in slide.shapes: if shape.is_placeholder: phf = shape.placeholder_format print('%d, %s' % (phf.idx, phf.type)) rows = 17 cols = 6 left = Inches(0.5) top = Inches(0.70) # right = Inches(0.5) width = Inches(6.0) height = Inches(0.02) table = shapes.add_table(rows, cols, left, top, width, height).table # set column widths table.columns[0].width = Inches(1.5) table.columns[1].width = Inches(1.5) table.columns[2].width = Inches(3.0) table.cell(0, 0).text = 'ID' table.cell(0, 1).text = 'Category' table.cell(0, 2).text = 'Highlights' table.cell(0, 3).text = ' ' table.cell(0, 4).text = ' ' table.cell(0, 5).text = 'Trend' format_table_headers(table) fixed_table_content_es(table) format_table_content_es(table) prs.save('chart-01.pptx')
def copy_txtbox_properties(shp_copy_from, shp_copy_to): ''' Copies over one textbox's properties to another. ''' # get original slide's shapes dimensions left = shp_copy_from.left top = shp_copy_from.top width = shp_copy_from.width height = shp_copy_from.height # access textframe property for both original and replica shapes txtframe_ori = shp_copy_from.text_frame txtframe_rep = shp_copy_to.text_frame # transfer textbox setters from original to replica at textbox level txtframe_rep.margin_bottom = txtframe_ori.margin_bottom txtframe_rep.margin_left = txtframe_ori.margin_left txtframe_rep.margin_right = txtframe_ori.margin_right txtframe_rep.margin_top = txtframe_ori.margin_top txtframe_rep.vertical_anchor = txtframe_ori.vertical_anchor txtframe_rep.word_wrap = txtframe_ori.word_wrap txtframe_rep.paragraphs[0].text = txtframe_ori.paragraphs[0].text txtframe_rep.paragraphs[0].alignment = txtframe_ori.paragraphs[0].alignment # color textboxes accordingly try: color_code = str(shp_copy_from.fill.fore_color.rgb) txfill = shp_copy_to.fill txfill.solid() txfill.fore_color.rgb = RGBColor.from_string(color_code) except: pass # get font size and transfer it to replica shapes for paragraph in txtframe_ori.paragraphs: for run in paragraph.runs: font = run.font try: font_size = font.size.pt t = txtframe_rep.paragraphs[0] t.font.size = Pt(font_size) except: pass
def parse_table(self, df, table): '''parse a pandas dataframe into a powerpoint table ''' # append rows to table for i in range(df.shape[0] - 1): new_row = copy.deepcopy(table._tbl.tr_lst[-1]) table._tbl.append(new_row) for i in range(df.shape[0]): for j in range(df.shape[1]): table.cell(i + 1, j).text = df.iloc[i, j] if table.cell(i + 1, j).text: font = table.cell(i + 1, j).text_frame.paragraphs[0].runs[0].font font.color.rgb = RGBColor(0, 0, 0) font.size = Pt(9) font.name = 'Calibri' font.bold = False return table
def add_text(slide, experiment, text_params): text_box = slide.shapes.add_textbox( Cm(text_params["left"]), Cm(text_params["top"]), Cm(text_params["width"]), Cm(text_params["height"]), ) summary = load_summary(experiment) text_frame = text_box.text_frame text_frame.text = text_params["text"].replace("{rank}", str(summary["model_rank"])) for paragraph in text_frame.paragraphs: paragraph.font.name = FONT_NAME paragraph.font.bold = True paragraph.font.size = Pt(text_params.get("size", 14)) paragraph.alignment = PP_ALIGN.LEFT text_frame.vertical_anchor = MSO_ANCHOR.TOP
def _draw_textbox(slide, left, top, width, height, text, text_color=RGBColor(0, 0, 0), dash=False): txBox = slide.shapes.add_textbox(Inches(left), Inches(top), Inches(width), Inches(height)) txBox.text = str(text) if dash is True: txBox.line.dash_style = MSO_LINE.ROUND_DOT txBox.line.color.rgb = RGBColor(0, 0, 0) txBox.line.width = Pt(1.0) txBox.text_frame.auto_size = MSO_AUTO_SIZE.TEXT_TO_FIT_SHAPE txBox.text_frame.paragraphs[0].alignment = PP_ALIGN.CENTER txBox.text_frame.vertical_anchor = MSO_ANCHOR.MIDDLE txBox.text_frame.paragraphs[0].font.color.rgb = text_color
def add_textbox_formatted(preso, slide_num, text_config, text): """ add a text box to slide with formatted text""" slide = preso.slides[slide_num] color = text_config['color'] pos = text_config['pos'] # left, top, width, height text_box = slide.shapes.add_textbox(Inches(pos[0]), Inches(pos[1]), Inches(pos[2]), Inches(pos[3])) text_frame = text_box.text_frame paragraph = text_frame.add_paragraph() run = paragraph.add_run() run.text = text font = run.font font.name = text_config['font'] font.size = Pt(text_config['size']) paragraph.font.color.rgb = RGBColor(*color)
def createPowerpoint(title, song_list, details): prs = Presentation() left = top = width = height = Inches(1) blank_slide_layout = prs.slide_layouts[6] for song in song_list: s_details = song[0] + "Writers: " + details[0] + "CCLI: " + details[1] slide = prs.slides.add_slide(blank_slide_layout) p_lines = slide.shapes.add_textbox(left, top, Inches(8), height).text_frame.add_paragraph() p_lines.text = "".join(song[1]) p_lines.font.size = FONT_SIZE p_details = slide.shapes.add_textbox(Inches(5), Inches(6.5), width, height).text_frame.add_paragraph() p_details.text = s_details p_details.font.size = Pt(12) slide.notes_slide.notes_text_frame.text = s_details prs.save(title.replace(FILE_EXTENTSION, "") + ".pptx")
def add_hindex(self): """ Adds Twitter H-index :return: """ top = Cm(15.99) left = Cm(0.81) width = Cm(3) height = Cm(1) tx_box = self.shapes.add_textbox(left, top, width, height) tframe = tx_box.text_frame.paragraphs[0] run = tframe.add_run() font = run.font font.name = 'Calibri' font.size = Pt(18) font.bold = True font.italic = None font.color.rgb = RGBColor(0xFF, 0x7F, 0x50) run.text = "H-INDEX:"+str(self.data_row['hindex'])
def create_slide(ppt, sentences): bullet_slide_layout = ppt.slide_layouts[1] slide = ppt.slides.add_slide(bullet_slide_layout) shapes = slide.shapes title_shape = shapes.title body_shape = shapes.placeholders[1] title_shape.text = 'Topic Name' tf = body_shape.text_frame tf.word_wrap = True tf.auto_size = MSO_AUTO_SIZE.SHAPE_TO_FIT_TEXT for sentence in sentences: p = tf.add_paragraph() p.font.size = Pt(18) p.text = sentence p.level = 0
def title_image_slide(prs, title): """ Creates a new slide in the presentation (prs) with a formatted title. Parameters ---------- prs : presentation object pptx presentation object title : str title of slide Returns ------- slide : slide object pptx slide object """ # Add a title slide title_slide_layout = prs.slide_layouts[5] slide = prs.slides.add_slide(title_slide_layout) # Add text to title and edit its layout title_placeholder = slide.shapes.title title_placeholder.top = Inches(0) title_placeholder.width = Inches(10) title_placeholder.height = Inches(0.5) title_placeholder.text = title # Edit margins within textbox text_frame = title_placeholder.text_frame text_frame.margin_bottom = Inches(0) text_frame.margin_top = Inches(0.1) text_frame.vertical_anchor = MSO_ANCHOR.TOP # Edit title fontsize and style p = text_frame.paragraphs[0] run = p.runs[0] font = run.font font.size = Pt(16) font.bold = True return slide
def generar_power(inicio, fin, nombre): arucosx = 0 arucosy = 0 # inicio = 0 prs = Presentation("template.pptx") blank_slide_layout = prs.slide_layouts[6] # slide = prs.slides.add_slide(blank_slide_layout) slide = prs.slides[0] x = 0.6 y = 0.6 for i in range(inicio,fin): img = 'id_' + str(i) + '.png' imagelist.append(img) for img in imagelist: txBox = slide.shapes.add_textbox(Cm(x), Cm(y-.7), Cm(5), Cm(3)) tf = txBox.text_frame p = tf.paragraphs[0] run = p.add_run() run.text = "Id: " + str(inicio) font = run.font font.name = 'Calibri' font.size = Pt(16) font.bold = True pic = slide.shapes.add_picture(img, Cm(x), Cm(y) ,height=Cm(4.2)) x += 5.4 arucosx += 1 inicio += 1 line1=slide.shapes.add_connector(MSO_CONNECTOR.STRAIGHT, Cm(x-.6), Cm(0), Cm(x-.6), Cm(65)) if arucosx == 16: x = 0.6 arucosx = 0 y += 5.4 arucosy += 1 line2=slide.shapes.add_connector(MSO_CONNECTOR.STRAIGHT, Cm(0), Cm(y-.6), Cm(87), Cm(y-.6)) if arucosy == 12: arucosy = 0 slide = prs.slides.add_slide(blank_slide_layout) x = 0.6 y = 0.6 prs.save(nombre + '.pptx')
def place_text(txt: str, pos: tuple, color=(0, 0, 0), pt_size=24, bold=False, italic=False, alignment=PP_ALIGN.LEFT): text_box = slide.shapes.add_textbox(*pos) text_frame = text_box.text_frame p = text_frame.add_paragraph() run = p.add_run() font = run.font font.size = Pt(pt_size) font.bold = bold font.italic = italic p.alignment = alignment font.color.rgb = RGBColor(*color) run.text = txt
def addParagraphs(self, tf, Paragraphs): # print Paragraphs # try: print 'No. Paragraphs:', len(Paragraphs) for i in range(len(Paragraphs)): p = tf.add_paragraph() p.text = Paragraphs[i][0] p.font.size = Pt(int(Paragraphs[i][1])) p.font.color.theme_color = MSO_THEME_COLOR.ACCENT_1 try: if Paragraphs[i][2] == 'b': p.font.bold = True if Paragraphs[i][3] == 'i': p.font.italic = True if Paragraphs[i][4] == 'r': p.font.color.rgb = self.red elif Paragraphs[i][4] == 'b': p.font.color.rgb = self.black except: pass
def add_table_markup(table): """ Adjusts font size and adds hyperlinks """ for cell in iter_cells(table): for paragraph in cell.text_frame.paragraphs: for run in paragraph.runs: run.font.size = Pt(16) run.font.name = 'Calibri' if re.search(r'https://*', cell.text): ticket = str(cell.text.split('/')[-1]) run.text = ticket hlink = run.hyperlink hlink.address = cell.text if re.search(r'@', cell.text): email = str(cell.text.split('@')[0]) domain = str(cell.text.split('@')[1]) run.text = email hlink = run.hyperlink hlink.address = 'mailto:' + email + '@' + domain
def _default(): prs = Presentation() blank_slide_layout = prs.slide_layouts[6] slide = prs.slides.add_slide(blank_slide_layout) left = top = width = height = Inches(1) txBox = slide.shapes.add_textbox(left, top, width, height) tf = txBox.text_frame tf.text = "This is text inside a textbox" p = tf.add_paragraph() p.text = "This is a second paragraph that's bold" p.font.bold = True p = tf.add_paragraph() p.text = "This is a third paragraph that's big" p.font.size = Pt(40) prs.save('test.pptx')
def directory2(): slide = prs.slides.add_slide(blank_slide_layout) #设置背景图片和标题 img_path = 'backgrounds/2_2.jpg' left, top, width, height = Inches(0), Inches(0), Inches(13.5), Inches(7.5) pic = slide.shapes.add_picture(img_path, left, top, width, height) #目录标题 left, top, width, height = Inches(1), Inches(0), Inches(3), Inches(1) txBox = slide.shapes.add_textbox(left, top, width, height) p = txBox.text_frame.add_paragraph() p.font.name = '黑体' p.font.bold = True p.text = "目录" p.font.size = Pt(50) #目录 left, top, width, height = Inches(2.4), Inches(1.4), Inches(3), Inches(5) txBox = slide.shapes.add_textbox(left, top, width, height) tf = txBox.text_frame p = tf.add_paragraph() p.font.name = '黑体' p.font.size = Pt(20) p.text = "● 第一个目录\n" p = tf.add_paragraph() p.font.name = '黑体' p.font.size = Pt(20) p.text = "● 第二个目录\n" p = tf.add_paragraph() p.font.name = '黑体' p.font.size = Pt(20) p.text = "● 第三个目录\n" p = tf.add_paragraph() p.font.name = '黑体' p.font.size = Pt(20) p.text = "● 第四个目录\n" p = tf.add_paragraph() p.font.name = '黑体' p.font.size = Pt(20) p.text = "● 第五个目录\n" p = tf.add_paragraph() p.font.name = '黑体' p.font.size = Pt(20) p.text = "● 第六个目录\n" prs.save('test.pptx')
def setShapeFont(shape, size=15, isBold=False, isItalic=False, isUnderline=False, level=1): if not shape.has_text_frame: return textFrame = shape.text_frame # 设置文字输入框的上下边距 textFrame.margin_top = Inches(1) # 上方空出1的空白 # 设置文字的排版方式 textFrame.margin_left = 0 textFrame.vertical_anchor = MSO_VERTICAL_ANCHOR.MIDDLE # 靠中间排列 textFrame.word_wrap = True paraNum = len(textFrame.paragraphs) for iNum in range(paraNum): para = textFrame.paragraphs[iNum] para.font.name = 'Calibri' # Microsoft Yahei 设置字体 para.font.size = Pt(size) # 文字大小 para.font.color.rgb = RGBColor(0xFF, 0x7F, 0x50) # 设置文本颜色 para.font.bold = isBold # 文字加粗 para.font.italic = isItalic # 文字斜体 para.font.underline = isUnderline # 文字下划线 para.level = level # 新段落的级别
def configureText(self, para, text, size, align=2, clr='000000', bold=False, italic=False): para.alignment = align run = para.add_run() run.text = str(text) font = run.font font.name = 'Liberation Serif' font.size = Pt(int(size)) font.bold = bold font.italic = italic font.fill.solid() color = RGBColor.from_string(clr) font.fill.fore_color.rgb = color
def insert_images(slide, slide_num, images_path, image_df): """ Insert images into a slide. :param slide: = slide object from Presentation class :param slide_num: the template slide number for formatting :param images_path: the directory to the folder with all the images :param image_df: Pandas data frame regarding information of each image in images_path :return: None """ placeholders = get_image_placeholders(slide) print('placeholders: ', placeholders) image_pool = image_df[image_df['slide_num'] == slide_num] print('image_pool: ', image_pool) try: assert len(placeholders) == len(image_pool.index) except AssertionError: print('Length of placeholders in slide does not match image naming.') i = 0 for idx, image in image_pool.iterrows(): #print(image) image_path = os.path.join(images_path, image.path) placeholder = slide.placeholders[placeholders[i]] pic = placeholder.insert_picture(image_path) adjust_picture_to_fit(pic) #print(image.path) line = pic.line #print(image['view']) if image['view'] == 'red': line.color.rgb = RGBColor(255, 0, 0) elif image['view'] == 'green': line.color.rgb = RGBColor(0, 255, 0) elif image['view'] == 'blue': line.color.rgb = RGBColor(50, 205, 255) else: line.color.rgb = RGBColor(0, 0, 0) line.width = Pt(2.25) i += 1
def prt_table1(): rows = 7+3 cols = 10 left, top, width, height = Cm(1.2), Cm(2.8), Cm(23), Cm(13.5) table = slide.shapes.add_table(rows, cols, left, top, width, height).table col_width =[Cm(3.2), Cm(2.8), Cm(1.9), Cm(2.4), Cm(1.8), Cm(1.8), Cm(1.8), Cm(1.8), Cm(2.0), Cm(3.5)] tt = ['A1', 'A2', 'A3', 'A4','A5', 'A6', 'A7', 'A8', 'A9', 'A0'] for r in range(rows): table.rows[r].height = Cm(0.8) for c in range(cols): table.columns[c].width = col_width[c] for r in range(rows): table.cell(r, c).text_frame.paragraphs[0].font.size=Pt(9) table.cell(r, c).vertical_anchor = MSO_VERTICAL_ANCHOR.MIDDLE tp = table.cell(0, c).text_frame.paragraphs[0] tp.text = tt[c] tp.font.bold = True tp.alignment = PP_ALIGN.CENTER d_tit = table.cell(1, 0).text_frame.paragraphs[0] s_tit = table.cell(7, 0).text_frame.paragraphs[0] d_tit.text = 'd_tit_text'; d_tit.alignment = PP_ALIGN.CENTER s_tit.text = 's_tit_text'; s_tit.alignment = PP_ALIGN.CENTER # avgdata = lambda x: round(sum(x) / len(x), 2) j = 1 for i in range(rows -1): for qq in range(1, 10): table.cell(j, qq).vertival_anchor = MSO_VERTICAL_ANCHOR.MIDDLE table.cell(j, 1).text_frame.paragraphs[0].text = "table.cell." + str(j).zfill(2) table.cell(j, 1).text_frame.paragraphs[0].alignment = PP_ALIGN.CENTER j += 1 return table
def plot_textbox(prs,texts,title=u'我是文本框页标题',summary=u'我是内容',footnote='',layouts=[0,0]): ''' 只绘制一个文本框,用于目录、小结等 ''' slide_width=prs.slide_width slide_height=prs.slide_height # 可能需要修改以适应更多的情形 title_only_slide = prs.slide_masters[layouts[0]].slide_layouts[layouts[1]] slide = prs.slides.add_slide(title_only_slide) #title=u'这里是标题' slide.shapes.title.text = title # 绘制副标题 if summary: left,top = Emu(0.15*slide_width), Emu(0.10*slide_height) width,height = Emu(0.7*slide_width), Emu(0.1*slide_height) txBox = slide.shapes.add_textbox(left, top, width, height) txBox.text_frame.text=summary # 绘制主体 left,top = Emu(0.15*slide_width), Emu(0.20*slide_height) width,height = Emu(0.7*slide_width), Emu(0.7*slide_height) txBox = slide.shapes.add_textbox(left, top, width, height) txBox.text_frame.text=texts # 添加脚注 footnote=u'这里是脚注' if footnote: left,top = Emu(0.025*slide_width), Emu(0.95*slide_height) width,height = Emu(0.70*slide_width), Emu(0.10*slide_height) txBox = slide.shapes.add_textbox(left, top, width, height) #p = text_frame.paragraphs[0] p=txBox.text_frame.paragraphs[0] p.text=footnote p.font.size = Pt(10) p.font.language_id = 3076 p.font.name='Microsoft YaHei UI' p.font.color.rgb=RGBColor(127,127,127) try: txBox.text_frame.fit_text(max_size=10) except: pass #print('cannot fit the size of font') return prs