使用 Python 对 PowerPoint 图表数据进行排序?

Sort PowerPoint chart data with Python?

我使用 Openpyxl 从 excel 电子表格中获取图表数据。

我需要能够按照从大到小的顺序对这些数据进行排序,而不会将其弄乱。有时图表中有多个系列。

有什么方法可以实现吗?

如果在放入plot之前无法排序,有没有什么办法可以在放入plot之后进行排序?我想它需要定位,然后分类。文档中的每个图表都需要这样做。

以下是我为解决此问题所做的工作,目前似乎有效。如果有人建议简化此过程,我会洗耳恭听!

        for cat in data_collect['categories']: #creates new lists by category
            new_list = []
            for key in data_collect:
                if key != 'categories':
                    new_list.append(data_collect[key][indexcounter])  
                else:
                    pass
            new_list.insert(1, cat)
            indexcounter += 1
            data_sort.append(new_list)

        data_sort.sort() #sorts list by first column
        cat_list_sorted = []

        for lst in data_sort: #removes sorted category list and drops it into the chart
            cat_list_sorted.append(lst[1])
            del lst[1]
        chart_data.categories = cat_list_sorted

        indexcounter = 0 #pulls data back apart and creates new series lists. Drops each series into ChartData()
        while indexcounter < len(series_name_list):
            series_sorted = []
            for lst in data_sort:
                series_sorted.append(lst[indexcounter])
            series_name = series_name_list[indexcounter]
            chart_data.add_series(series_name, series_sorted, '0%')
            indexcounter += 1```