1

We need to update xlsx sheet using python script which do some calcualtion and update one worksheet. I choose openpyxl as it supoort writing/updating xlsx File. In the Excel sheet contain some graphs also but When I update excel sheet than graph does not work into excel and data update respectively. I think we had some issue for updating graph with openpyxl.Can anyone provide me some input to fix this issue

or In other word,In the Excel sheet I have 10 worksheet.In worksheet 1, it contain graphs. I have updated worksheet number 5. Worksheet is updated successfully. But I have loose the graphs of worksheet 1.

#!/usr/bin/env python
from openpyxl import load_workbook
import openpyxl 
print "pylx"
ddr_sam45_flop =  "Flip_Flop.xlsx"
flop_workbook     = load_workbook(ddr_sam45_flop)
raw_flop_workbook = flop_workbook.get_sheet_by_name(name ='RAW')
raw_flop_workbook.cell(row = 1 , column = 1).value = 889999
flop_workbook.save(ddr_sam45_flop)
print "End"

(Please consider me new to openpyxl)

user765443
  • 1,856
  • 7
  • 31
  • 56

2 Answers2

2

Openpyxl does not support graphs or chart as of now

user765443
  • 1,856
  • 7
  • 31
  • 56
1

Any graphs that exist in the document before opening will be deleted after saving. The only way around this ( i know of) is to create the chart in code.

Here is the documentation on how to create a chart in openpyxl

The example is a little broken, compare to this instead.

    values = Reference(ws, (1, 1), (1, 95))
    series = Series(values, title="Sample" )
    chart = LineChart()
    chart.append(series)
    ws.add_chart(chart)  
oden
  • 3,461
  • 1
  • 31
  • 33
  • would it be possible to find an existing chart, copy it, and add it back in rather than creating it manually? – MetaStack Apr 25 '17 at 22:08
  • @LegitStack This does not seem to work from my testing. The save action recreates the xml document which deletes the chart. Real shame as I wanted this feature also. – oden May 01 '17 at 02:03
  • new link: https://openpyxl.readthedocs.io/en/stable/charts/introduction.html – Boop Sep 19 '20 at 13:28