diff --git a/BaiHu/Tools/DocxTuBiaoRead.py b/BaiHu/Tools/DocxTuBiaoRead.py index fa926ab5..7c2f6db5 100644 --- a/BaiHu/Tools/DocxTuBiaoRead.py +++ b/BaiHu/Tools/DocxTuBiaoRead.py @@ -12,27 +12,7 @@ docApp.DisplayAlerts = 0 # doc = docApp.Documents.Open('c:/昆明市人口变化及其对教育的影响20240419.docx') doc = docApp.Documents.Open('c:/红河哈尼族彝族自治州人口变化及其对教育的影响20240419.docx') -# 遍历文档中的所有内嵌形状 -# idx = 1 -# for inline_shape in doc.InlineShapes: -# if inline_shape.Type == win32com.client.constants.wdInlineShapeChart: # 检查是否为内嵌图表 -# shape = doc.InlineShapes(idx) -# # 获取图表的标题,此项目中图表没有标题 -# # print(shape.Chart.ChartTitle.Text) -# sheet = shape.Chart.ChartData.Workbook.Worksheets("Sheet1") -# # 行数 -# row_size = sheet.UsedRange.rows.Count -# # 列数 -# col_size = sheet.UsedRange.columns.Count -# # 遍历获取表格中的数据 -# for i in range(1, row_size + 1): -# for j in range(1, col_size + 1): -# print(sheet.Cells(i, j).Value, end=" ") -# print("") -# print("") -# # 下一个图表的索引号 -# idx = idx + 1 -# print(idx) + # 遍历文档中所有的文字段落,判断是不是以 图+数字开头 idx = 1 for para in doc.Paragraphs: @@ -41,6 +21,29 @@ for para in doc.Paragraphs: print(x) idx = idx + 1 +# 遍历文档中的所有内嵌形状 +idx = 1 +for inline_shape in doc.InlineShapes: + if inline_shape.Type == win32com.client.constants.wdInlineShapeChart: # 检查是否为内嵌图表 + shape = doc.InlineShapes(idx) + # 获取图表的标题,此项目中图表没有标题 + # print(shape.Chart.ChartTitle.Text) + sheet = shape.Chart.ChartData.Workbook.Worksheets("Sheet1") + # 行数 + row_size = sheet.UsedRange.rows.Count + # 列数 + col_size = sheet.UsedRange.columns.Count + # 遍历获取表格中的数据 + for i in range(1, row_size + 1): + for j in range(1, col_size + 1): + print(sheet.Cells(i, j).Value, end=" ") + print("") + print("") + # 下一个图表的索引号 + idx = idx + 1 +print(idx-1) + + # 关闭文档和Word应用 doc.Close() docApp.Quit()