From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Programmatically Save Excel Chart as PNG Files

Hi all:

 

I'm very new to ActiveX and its Automation functions so I need some guidance.

 

I'm trying save an Excel chart as a PNG image.

 

The chart was not created by LabVIEW; LabVIEW just copies data into a template with the chart configured to dynamically detect ranges and plot the corresponding data. (I'm not sure how Excel recognizes the chart - MSObject or MSChart?)

 

Here's what I've done so far but it isn't working (attached) - Error pops up immediately after the ActiveX Variant to Data VI. (Index of graph is 0 - no other objects in the file)

 

Any help or advice will be appreciated.

0 Kudos
Message 1 of 5
(3,459 Views)

You should post your code as a VI snippet or attach your VI so that others could try to run/modify your code.

 

(Normally I like screenshots because I can see them without having to open LabVIEW but in this case, it would be useful to be able to modify the code...I'm not going to re-create it from scratch!!)

 

My suspicion is that the 'Item' you get out of the 'Sheets' node is a 'Sheet' rather than a 'Chart' so trying to convert back from the variant is failing. Either that or the items are 1-indexed instead of 0-indexed?

 


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 2 of 5
(3,408 Views)

Is it an especially hard chart to generate? It might be easier to generate the graph in LabVIEW (even if it's a hidden indicator) and then save that as a .png, but I don't know your specific requirement.

0 Kudos
Message 3 of 5
(3,348 Views)

VyRianS a écrit :

Hi all:

 

I'm very new to ActiveX and its Automation functions so I need some guidance.

 

I'm trying save an Excel chart as a PNG image.

 

The chart was not created by LabVIEW; LabVIEW just copies data into a template with the chart configured to dynamically detect ranges and plot the corresponding data. (I'm not sure how Excel recognizes the chart - MSObject or MSChart?)

 

Here's what I've done so far but it isn't working (attached) - Error pops up immediately after the ActiveX Variant to Data VI. (Index of graph is 0 - no other objects in the file)

 

Any help or advice will be appreciated.


Where is the chart located, in the worksheet that contain the data or in a separate chartsheet? These are two different objects.

I would guess it is included in the worksheet where the data is written. In this case it is a ChartObject object. You access it throught the ChartObjects collection of the worksheet. In Excel the first object of a collection is at index 1 (not 0, that will throw an error).

 

Ben64

 

export graph.png

Message 4 of 5
(3,311 Views)

Having seen Ben's solution (pretty complicated!), let me echo Gregory's question and ask "Why Excel"?  From the initial description of your problem, it sounds like you have LabVIEW data and want to make a .PNG file that contains a graph of the data, using Excel as a "conduit" to convert LabVIEW data points into such an Image file.  If this is the only reason to involve Excel (i.e. if you are not saving the data points themselves in Excel for some purpose), then it would seem a lot simpler to explore a "pure LabVIEW" approach to this problem.

 

You were also asked to post the VI (or VIs) that you are developing to solve this problem, and so far have not done so.  Posting your VIs gives us a much better idea of what you are really trying to do (and haven't clearly explained to us), and allows us to be more helpful to you.  It's not too late to do so ...

 

Bob Schor

0 Kudos
Message 5 of 5
(3,291 Views)