You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.3 KiB

9 months ago
# pip install pywin32
# https://blog.csdn.net/weixin_42927998/article/details/115086797
import win32com
from win32com.client import Dispatch
docApp = win32com.client.Dispatch('Word.Application')
docApp.Visible = True
docApp.DisplayAlerts = 0
doc = docApp.Documents.Open('c:/1.docx')
9 months ago
'''
1柱形图Column
2折线图Line
3饼图Pie
51堆叠柱形图Stacked Column
52堆叠线图Stacked Line
53堆叠区域图Stacked Area
55雷达图Radar
65树状图Treemap
73旭日图Sunburst
77水桶图Funnel
109散点图Scatter
183气泡图Bubble
'''
9 months ago
# 遍历文档中的所有内嵌形状
9 months ago
idx = 1
9 months ago
for inline_shape in doc.InlineShapes:
if inline_shape.Type == win32com.client.constants.wdInlineShapeChart: # 检查是否为内嵌图表
print("找到一个图表")
9 months ago
pic1 = doc.InlineShapes(idx)
print(pic1.Chart.ChartType)
# print(pic1.Chart.ChartData.Workbook.FullName)
print(pic1.Chart.ChartStyle)
print(pic1.Chart.ChartTitle.Text)
9 months ago
sheet = pic1.Chart.ChartData.Workbook.Worksheets("Sheet1")
print(sheet.Range("A2").Text)
9 months ago
idx = idx + 1
9 months ago
# 这里可以对图表进行操作,比如获取图表的类型、数据等
doc.Close()
docApp.Quit()