私はopenpyxl 2.4.8を使用していくつかのExcelファイルを生成しています。いくつかの列にデータを入力し、そのデータをプロットするグラフを挿入します。手動でExcelを実行すると、データソート方法を使用してデータポイントを削除すると、グラフが動的に更新されます。しかし、openpyxlで生成されたグラフは静的であり、このようなソートは無視されます。 Excelで生成されたチャートのxmlを見ると、openpyxlで生成されたグラフのxmlを見ると、多くの違いがあります(fx。すべてのタグはExcelで 'c:'で始まります)。コンテンツを自動的に更新します。私はこれをオンまたはオフにする設定をExcelで見つけることはできません。 私はExcelでグラフを使用してファイルを生成するために使用するコードはここにある:カラムをソートするときに、openpyxlで生成されたチャートを動的に更新します。
import numpy as np
from openpyxl import *
from random import random
from openpyxl.utils.cell import get_column_letter
from openpyxl.chart import (
LineChart,
BarChart,
ScatterChart,
Reference,
Series,
)
from openpyxl.drawing.text import CharacterProperties
wb = Workbook()
ws = wb.create_sheet()
ws.title = 'interactiveChart'
num = 9
ws.cell(column=1, row=2, value='X')
ws.cell(column=2, row=2, value='Y')
for i in range(num+1):
ws.cell(column=1, row=3+i, value=random()*100)
ws.cell(column=2, row=3+i, value='=A{0}*3+4+ABS(5/(11-A{0}))+ABS(10/(35- A{0}))+ABS(30/(67-A{0}))'.format(3+i))
textSize = 10
modeChart = ScatterChart()
modeChart.title = 'Resonance'
modeChart.title.tx.rich.p[0].r.rPr = CharacterProperties(sz=textSize*100, b=True)
modeChart.style = 48
modeChart.x_axis.title = "X"
modeChart.x_axis.title.tx.rich.p[0].r.rPr = CharacterProperties(sz=textSize*100, b=True)
modeChart.y_axis.title = "Y"
modeChart.y_axis.title.tx.rich.p[0].r.rPr = CharacterProperties(sz=textSize*100, b=True)
modeChart.legend = None
xvalues = Reference(ws, min_col=1, min_row=2, max_row=num+3)
yvalues = Reference(ws, min_col=2, min_row=2, max_row=num+3)
series = Series(yvalues, xvalues, title_from_data=False, title='Resonace')
modeChart.series.append(series)
s1 = modeChart.series[0]
s1.marker.symbol = "diamond"
s1.marker.graphicalProperties.solidFill = "6495ED"
s1.marker.graphicalProperties.line.solidFill = "6495ED"
s1.graphicalProperties.line.noFill = True
modeChart.x_axis.tickLblPos = "low"
modeChart.y_axis.tickLblPos = "low"
modeChart.width = 12
modeChart.height = 7
ws.add_chart(modeChart, "F6")
ws.auto_filter.ref = 'A2:B{}'.format(num+3)
ws = wb.get_sheet_by_name("Sheet")
wb.remove_sheet(ws)
wb.save('aTest.xlsx')
私はどちらかを探してすべきかどうか分からないので、私はこの動作への参照を見つけることができません。
あなたの 'openpyxl'バージョンを追加してください。 – stovfl