Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Excel 2000 chart location problem

Hi!

I'm trying to create charts in Excel 2000 Professional (SP-3)
programmatically, using C# (Visual Studio .NET 2005), but there seems
to be a problem. When I set the location of a chart, it is always
placed on the first worksheet, no matter what parameter I specify as
the worksheet name.

For example, the following code:

Excel._Application applic = new Excel.Application();
if (applic == null)
{
Console.WriteLine("Error!");
return;
}

applic.Visible = true;

Workbooks workbooks = applic.Workbooks;
_Workbook workbook = workbooks.Add(XlWBATemplate.xlWBATWorksheet);
_Worksheet worksheet = (_Worksheet)workbook.Worksheets.get_Item(1);
worksheet.Name = "Worksheet1";
_Worksheet newWorksheet =
(_Worksheet)workbook.Worksheets.Add(Missing.Value,
(_Worksheet)workbook.Worksheets.get_Item(1), 1,
XlSheetType.xlWorksheet);
newWorksheet.Name = "Worksheet2";
Range oRange = worksheet.get_Range("B2", "E2");

_Chart oChart = (_Chart)workbook.Charts.Add(Missing.Value,
Missing.Value, Missing.Value, Missing.Value);
oChart.ChartWizard(oRange, Missing.Value, Missing.Value,
XlRowCol.xlRows, Missing.Value, Missing.Value, Missing.Value, "My
chart", Missing.Value, Missing.Value, Missing.Value);

// here's the problem
oChart.Location(XlChartLocation.xlLocationAsObject , "Worksheet2"); //
instead of placing the chart on "Worksheet2", the chart appears on
"Worksheet1" !!!

Console.ReadLine(); // so that Excel doesn't close immediately
applic.Quit();


Could anyone please explain why the chart is not where it is supposed
to be?
And why does this happen only in Excel 2000? In Excel 2003 and Office
XP, the chart is placed correctly (on the second worksheet).

I have to place a chart on a worksheet different from the first one in
Excel 2000; please tell me how to do this in a different way (the above
code doesn't behave as expected).

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,582
Default Excel 2000 chart location problem

Can't help you with the C# bit (I thought that was "C-pound" until my
musician daughter laughed at me!!). But there's another way to add an
embedded chart to a worksheet. Instead of creating a chart sheet using
Charts.Add, then putting it on the sheet with .Location, you can directly
create a chart object (the container for an embedded chart) in a worksheet.
In VBA this is the ChartObjects.Add method of the Worksheet object, and it
includes four arguments: these are the .left, .top, .width, and .height
properties of the chart object relative to the worksheet in points.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services - Tutorials and Custom Solutions -
http://PeltierTech.com/
2006 Excel User Conference, 19-21 April, Atlantic City, NJ
http://peltiertech.com/Excel/ExcelUserConf06.html
_______

wrote in message
ups.com...
Hi!

I'm trying to create charts in Excel 2000 Professional (SP-3)
programmatically, using C# (Visual Studio .NET 2005), but there seems
to be a problem. When I set the location of a chart, it is always
placed on the first worksheet, no matter what parameter I specify as
the worksheet name.

For example, the following code:

Excel._Application applic = new Excel.Application();
if (applic == null)
{
Console.WriteLine("Error!");
return;
}

applic.Visible = true;

Workbooks workbooks = applic.Workbooks;
_Workbook workbook = workbooks.Add(XlWBATemplate.xlWBATWorksheet);
_Worksheet worksheet = (_Worksheet)workbook.Worksheets.get_Item(1);
worksheet.Name = "Worksheet1";
_Worksheet newWorksheet =
(_Worksheet)workbook.Worksheets.Add(Missing.Value,
(_Worksheet)workbook.Worksheets.get_Item(1), 1,
XlSheetType.xlWorksheet);
newWorksheet.Name = "Worksheet2";
Range oRange = worksheet.get_Range("B2", "E2");

_Chart oChart = (_Chart)workbook.Charts.Add(Missing.Value,
Missing.Value, Missing.Value, Missing.Value);
oChart.ChartWizard(oRange, Missing.Value, Missing.Value,
XlRowCol.xlRows, Missing.Value, Missing.Value, Missing.Value, "My
chart", Missing.Value, Missing.Value, Missing.Value);

// here's the problem
oChart.Location(XlChartLocation.xlLocationAsObject , "Worksheet2"); //
instead of placing the chart on "Worksheet2", the chart appears on
"Worksheet1" !!!

Console.ReadLine(); // so that Excel doesn't close immediately
applic.Quit();


Could anyone please explain why the chart is not where it is supposed
to be?
And why does this happen only in Excel 2000? In Excel 2003 and Office
XP, the chart is placed correctly (on the second worksheet).

I have to place a chart on a worksheet different from the first one in
Excel 2000; please tell me how to do this in a different way (the above
code doesn't behave as expected).



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Excel 2000 chart location problem

Thanks!

In the meantime I've tried several workarounds, but the only one that
works is indeed the one using ChartObjects.Add. I still haven't found
the reason for which it didn't work with Location, but it doesn't
matter anymore, since there is another way to do it :)

Cosmina

Reply
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
EXcel 2000 pro auto backup location Tazzer Excel Discussion (Misc queries) 2 January 12th 09 06:08 PM
PROBLEM:How to squeeze 2 Page sized Chart in Excel 2000 & embed in Word 2000 and print from Word to fit one page ??? [email protected] Excel Discussion (Misc queries) 2 September 10th 08 11:07 AM
PROBLEM:How to squeeze 2 Page sized Chart in Excel 2000 & embed in Word 2000 and print from Word to fit one page ??? [email protected] New Users to Excel 2 September 10th 08 11:07 AM
Excel 2000 - How to find cell location of a link to another file? WINDMILL Excel Discussion (Misc queries) 2 July 12th 07 03:46 PM
Chart SeriesCollection. Problem changing from Excel 2000 to 2002 [email protected] Excel Programming 4 July 6th 04 08:15 AM


All times are GMT +1. The time now is 08:35 PM.

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

About Us

"It's about Microsoft Excel"