Copy excel chart chart to clipboard using c #

I am writing a C # application.

One of the tasks is to open an Excel spreadsheet and paste the chart table from it into the C # application. Note that I mean CHART SHEET ... not a chart object embedded in a regular worksheet.

There is a reason I'm trying to be precise here.

I am using regular COM to communicate with C # in Excel ...

using using Microsoft.Office.Interop.Excel;  

In a situation where a chart is embedded in a regular worksheet, the API works. I am extracting worksheets from a workbook, on the worksheet that I get chartObject, and issuing a copy to chartObject works as expected, that is, the contents of the clipboard, as if you had initiated the copy from Excel itself.

When working with a chart sheet, everything is different. I get the diagrams from the book, and then I get the instance of the diagram that interests me. All is well. However, issuing Copy () on the diagram here does not cause the clipboard to look as if the action was initiated from Excel. CopyPicture also does not help, because the pic is really blown out of proportion, and the Clipboard does not have the usual PNG, GIFF, JPEG formats - Clipboard.getImage () returns null, and doI sees that the image is on the clipboard. Copy () only creates Clip, DataObject and OLE Private Data on the clipboard instead of many others ...

//this does not work - it is for chart sheets
Excel.Charts charts = wb.Charts;
Excel.Chart chart = charts["mychartname"];
chart.Copy(); or chart.CopyPicture();    <-- these do not work as expected...


// this works fine but only covers embedded charts
Excel.ChartObjects charts = ws.ChartObjects;
Excel.ChartObject chart = charts["mychartname"];
chart.Copy();

Why is copying on a ChartObject different from copying on a chart? Copy () is such a trivial operation ... and to see that it does not work on the diagram is a huge surprise ...

? , , "" # Excel.

, Chart Sheet ... . , , ( ) .

.

0
1

.

Copy() , ChartArea .

Excel.Charts charts = wb.Charts;
Excel.Chart chart = charts["mychartname"];
Excel.ChartArea chartArea = chart.ChartArea;
chartArea.Copy();

COM COM-:)

0

All Articles