Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
copy chart formatting and chart templates in Excel 2007 | Charts and Charting in Excel | |||
Is it possible to copy all formatting from one chart to another? | Charts and Charting in Excel | |||
How do you link chart source data when you copy the chart? | Charts and Charting in Excel | |||
copy charts & paste as picture, hide chart, size & place same picture as chart | Excel Programming | |||
Code to copy chart | Excel Programming |