LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Copy chart in C#

Hello everyone

I'm having problems with copying chart from an excel workbook to word, using
C# in a class I've created.

I create the charts dynamically, and do stuff like:

---------------------------------------------------------------------------
Excel.Chart selfLedelseChart;
selfLedelseChart = (Excel.Chart)oExcelApplic.Charts.Add(Type.Missing,
Type.Missing, Type.Missing, Type.Missing);

Excel.Range rng = (Excel.Range)ledelseSelf.Cells.get_Range("A1:B" +
(ledelseSelfRow-1).ToString(), Type.Missing);
selfLedelseChart.HasLegend = false;
selfLedelseChart.ChartType = Excel.XlChartType.xlRadarMarkers;
selfLedelseChart.SetSourceData(rng, Excel.XlRowCol.xlColumns);
---------------------------------------------------------------------------

The creation process works fine, and I can paste the chart into a workbook
using:

---------------------------------------------------------------------------
selfLedelseChart.Location(Excel.XlChartLocation.xl LocationAsObject,
ledelseSelf.Name);
---------------------------------------------------------------------------

And this is where my problem begins. After the insertion I can't use the
variable selfLedelseChart anymore. It kind of loses focus or something like
that...

So I created a makro:
---------------------------------------------------------------------------
ActiveSheet.ChartObjects("Diagram 2").Activate
ActiveChart.ChartArea.Select
---------------------------------------------------------------------------
And tried to translate that into C#, but I can't really do it. I get an
error saying the specified cast is not allowed. I tried several solutions,
but I can't get a variable to point to the chart after I've inserted it into
the chart.
I can use the code:

---------------------------------------------------------------------------
Excel.ChartObject chartObject =
(Excel.ChartObject)ledelseSelf.ChartObjects(1);
---------------------------------------------------------------------------
But I can't go anywhere from there. I need the charts in 2 places in the
workbook total, so I also need to copy them internally, because I need to
paste charts on top of oneanother.

The funny part is that I can resize the object after insertion:

---------------------------------------------------------------------------
ledelseSelf.Shapes.Item(1).Width = chartWidth;
ledelseSelf.Shapes.Item(1).Height = chartHeight;
ledelseSelf.Shapes.Item(1).Top = chartTop;
ledelseSelf.Shapes.Item(1).Left = chartLeft;
---------------------------------------------------------------------------

So I'm looking for a way to get a variable to point to a chart in a certain
worksheet, and a way to copy to word in C#. Does anyone know hoe to do this?
Or can anyone point me in the right direction? Or can you tell me where to
get help?

Please help!!!

Thanks!

Regards


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
copy chart formatting and chart templates in Excel 2007 Astelix Charts and Charting in Excel 4 March 4th 10 04:10 AM
Is it possible to copy all formatting from one chart to another? OK Charts and Charting in Excel 1 November 27th 07 09:31 PM
How do you link chart source data when you copy the chart? mamagirl Charts and Charting in Excel 1 December 8th 06 02:40 AM
copy charts & paste as picture, hide chart, size & place same picture as chart Gunnar Johansson Excel Programming 0 October 30th 04 01:22 AM
Code to copy chart Helen Trim Excel Programming 0 July 16th 03 01:59 PM


All times are GMT +1. The time now is 10:09 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"