日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python ppt表格样式展示

發布時間:2023/12/9 python 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python ppt表格样式展示 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

本篇文章是對另一篇文章的補充,好多情況下會遇到樣式的改變。在這里出現情況較多的時候可以封裝為函數,方便調用,復寫。
# -*- coding: utf-8 -*-
from pptx import Presentation
from pptx.enum.text import PP_PARAGRAPH_ALIGNMENT
from pptx.chart.data import ChartData
from pptx.util import Pt
from pptx.dml.color import RGBColor

def write_cell(table, row, col, content, size, name,rgb):
? ? table.cell(row, col).text_frame.clear()
? ? new = table.cell(row, col).text_frame.paragraphs[0]
? ? new.alignment = PP_PARAGRAPH_ALIGNMENT.CENTER
? ? new.text = content
? ? new.font.size = Pt(size)
? ? new.font.name = name
? ? new.font.color.rgb = rgb

def ppt(prs,template_path):
? ? # 表格
? ? table = [tb.table for tb in slide.shapes if tb.has_table][0]
? ? values = []
? ? for row in range(1,3):
? ? ? ? value = []
? ? ? ? for col in range(1,8):
? ? ? ? ? ? if type(sheet.cell(row, col).value) == type(1.1) and col== 7:
? ? ? ? ? ? ? ? s = str(round(sheet.cell(row, col).value * 100,2)) + '%'
? ? ? ? ? ? elif type(sheet.cell(row, col).value) == type(1.1) and col in [1,2,3,4,5,6]:
? ? ? ? ? ? ? ? s = str(round(sheet.cell(row, col).value))
? ? ? ? ? ? else :
? ? ? ? ? ? ? ? s = str(sheet.cell(row, col).value)
? ? ? ? ? ? value.append(s)
? ? ? ? values.append(value)
? ? for i in range(len(table.rows)):
? ? ? ? for j in range(len(table.columns)):
? ? ? ? ? ? if ?values[i][j].startswith('-'):
? ? ? ? ? ? ? ? write_cell(table, i, j, str(values[i][j]), 18, "宋體",RGBColor(255, 0, 0))
? ? ? ? ? ? else: ? ?
? ? ? ? ? ? ? ? write_cell(table, i, j, str(values[i][j]), 14, "宋體",RGBColor(0, 0, 0))

總結

以上是生活随笔為你收集整理的python ppt表格样式展示的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。