python - 如何使用 openpyxls 将数据表添加到图表空间?

标签 python excel openpyxl

openpyxl 中有一个 openpyxl.chart.chartspace.DataTable 类,但没有示例。当我尝试使用它时,我得到:

AttributeError: 'BarChart' object has no attribute 'DataTable' 

或者我无法使用以下代码在图表空间中获取数据表:

from openpyxl.chart.chartspace import DataTable

chart1 = BarChart()
chart1.DataTable = DataTable(showHorzBorder=None , showVertBorder=None,showOutline=None, showKeys=None, spPr=None,txPr=None, extLst=None)

最佳答案

也许为时已晚..这对我有用

from openpyxl.chart.plotarea import DataTable

chart1 = BarChart()
chart1.plot_area.dTable = DataTable()
chart1.plot_area.dTable.showHorzBorder = True
chart1.plot_area.dTable.showVertBorder = True
chart1.plot_area.dTable.showOutline = True
chart1.plot_area.dTable.showKeys = True

关于python - 如何使用 openpyxls 将数据表添加到图表空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44143123/

相关文章:

vba - 加载的 XML 文件会被缓存,不会更新

openpyxl - 使用openpyxl从命名范围读取值

excel - 从列表框用户窗体中删除一行

php - 如何连接来自不同行的单行列中的列

python - 从特定列和行开始的现有工作表开始,使用 Openpyxl 写入现有 excel 文件

python - 如何在工作簿中定位图表

python - 在 python 中从矩阵创建网格

python - VSCode "Python: Select interpreter"添加自定义路径

python - 类型错误 : 'module' object is not callable - using datetime

python - 连接元组的元组时的 PEP8 检查