See the code of a graph that is already created - excel

I have a graph in Excel and want to use the exact format, size, axes, title etc. I know that I can just record a macro of me recreating a similar graph, but is there a way to step into the code of the one already created?

You can run the existing code. You'll have to adjust some of the hard-coded parts of the code, since the data range and the chart object name of the new chart will be different.
If you post the recorded code, someone might be able to help with this.

Related

How to print all the chart properties in Python-pptx

I have a existing chart in pptx file, i just want to update its values on daily basis, these charts are already plotted from excel and paste into pptx, i just want to modify the charts ,
but i don't know how many properties are there in charts like series, category and title properties.
i am able to print the chart series and category data, but when i modify these with chart.replace_data(chart_data)
i am getting error like below
return self._chart_part.related_parts[xlsx_part_rId]
KeyError: 'rId4'
I ma using below code to print the values ,
for series in chart.plots:
for i in series.categories:
cat_list.append(i)
for series in chart.series:
for value in series.values:
ser_list.append(value)
the graph looks like below
How can i modify such graphs with updated values which i will be passing from excel to pptx.
I suspect the problem is rooted in the "pasting from Excel" step.
One thing you can try is to right-click on the chart and choose "Edit values in Excel". If that doesn't work for any reason, that would explain the error you're seeing. If it does work, try saving and run the python-pptx code against the saved version.
An alternative, perhaps more reliable fix would be to recreate the chart natively in PowerPoint, starting from adding a new column-chart and adjusting it until you get what you see here. Then you should be able to update it daily with pretty much the code you mentioned (although your ser_list variable will accumulate values for all series in the chart if there is more than one).
To understand why this could be happening, it's important to observe that a chart does not have to have an Excel worksheet "behind" it. It can, and perhaps does in this pasting case, simply have fixed literal values that are embedded in the chart XML itself. The up-side of this is the pasting operation doesn't need to create a whole Excel spreadsheet, which might be tricky in a cut-and-paste context. The down-side is the values can't be conveniently changed using the standard methods.
I haven't tried working with one of those lately so I don't know if editing and saving the data adds a new Excel object created from the embedded values or not, but this might explain the behavior you're seeing.

No strCache/numCache if two different series types

This is occurring in my PowerPoint AddIn but it's chart code so posting here. I have a COM (not VSTO) AddIn.
If I populate 3 series that are all already a barChart (dir=col), by setting the values in the Worksheet.Cells and then setting Series.Name, XValues, & Values to the formula for each series' data, it all works great.
Now if I add 3 series of type lineChart and do the same thing setting the WorksheetCells and Series.Name, XValues, & Values I get a blank chart. If I save it the chart.xml is all correct, but it is mussing the strCache/numCache parts. And for the X values, it has multiLvlStrRef instead of strRef.
I do not set values in the Series.Points, just the data and the formula as that has been sufficient elsewhere. Should I be setting that too? And if I do, do I then not set it in the worksheet? Or if all three, does it need to be in a specific order?
I can code up a sample if needed, but I am hoping this is a know issue, hopefully with a work-around and so the description above is sufficient.
Any idea what's going on here. Is there something I need to do to have it populate the strCache/numCache parts?
This question is similar, but it's a different problem.
Found the solution. What I was doing is series by series I was setting the data in the backing worksheet and then setting the formula. That worked fine if all the series were the same chart type. But had the above problem for mixed types.
So I changed my code to write the data for all series to the backing worksheet, and then write all the formulas. Doing it that way it all works fine and the cached data is written to the chart.xml file.

Dynamically select cells in a row in Excel for using in a Graphic Chart

I´m kind of basic Excel user, so perhaps mi question is stupid but I´m really lost. So, I´m looking the way of generate a report in Excel by simply pasting a CSV content in a page inside a SpreadSheet.
The graph uses certain columns to get data and I need a way to select the column, from the first cell after header to last cell with content. I know I can do this manually but the main need here is to automatise the task. Just by pasting the new CSV info, the rest of pages on report (graphs) update automatically.
The real use is for Social Media, Analytics and Email Marketing stats.
Hope somebody can help me.
This question was answered extensively on this stack question: Dynamic chart range using INDIRECT: That function is not valid (despite range highlighted) Hope one of the many approaches shown will fit your needs. Cheers,

Unlink chart from excel and keep data editable?

for the longest of times I've been trying to achieve this to no avail. It seems like it should be a common problem but still I haven't been able find an answer. What I want to do is:
Have a chart in Excel and/or Powerpoint.
Copy this chart as a chart object into PPT.
Keep all characteristics of the original chart but maintain it editable (i.e. - add/remove axes, data labels etc)
Break the link to the original chart/workbook but keep the data editable. I.e., I want a new excel sheet opened when I want to edit the data, just like it works if I create a new chart object.
Preferably, I would like to convert the data of the original to this new chart sheet but this is not of really high importance.
Basically, I want to be able to use graphs as templates for a new graph without editing the original data. Please help!
PS. I didn't include any code as most of the code I've tried has tried to achieve something else. I mostly want to know if this is even possible to do (it should be!)?

load VBA data to line chart

I need to feed data into a line chart with VBA. I need to give a basic unidimensional range when I do it with Excel in a raw test. The thing is that now I need to hide some things in VBA code, so that the user just sees a curve resulting of some basic input at the click of a button.
I think there are at least two options for me :
either have the chart object placed in the Excel before, and having it point to some VBA snippet. In this case, should I somehow point to VBA from Excel ? Or would VBA access the chart area by some ID ?
create everything dynamically from VBA, the chart window, the chart, and the series input. This might be trickier to figure out maybe as I have frozen panes, so there would be the question of which pane is active (I'd like to avoid to have to do Selects to select the right one)
What would you recommend ? And in either case, how to actually do it ? What type of data to put in ?
Thank you so much !
I was involved in a project a couple of years ago that might be relevant.
A report was created monthly for the organisation's management board which contained dozens of charts. It was a near full time job for a statistician to collate and process data from across the organisation that provided the source data for these charts. I was asked to automate what could be automated.
It became clear that the appearance of the chart could not be automated. The statistician and the management board's staff held regular discussions and often agreed minor changes which they thought would better present the organisation's performance.
I could automate the collection of the data, its processing and placing of the results in the ranges from which the charts got their data. The most I ever did with a chart was change the size of a source range.
What would be the parameters that would control your macro's changes to a chart? How would your macro get the determine: type of chart, nature of the axes, text, etc?
Hope these thoughts help. I could look out my notes if my experience seems particularly relevant.

Resources