Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Excel automation problem
Message
De
02/03/2006 06:59:55
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
02/03/2006 05:05:41
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Divers
Thread ID:
01100443
Message ID:
01100800
Vues:
11
Nick,
I'm using Excel2002 and do not remember nor have 97 to test. As a workaround you can directly create the chart in its target sheet. ie:
#include xlconstants.h
Local oExcel as "Excel.Application"
oExcel = CreateObject("Excel.Application")
oExcel.Workbooks.Add()
oExcel.Visible= .T.
oExcel.ActiveWorkBook.Worksheets(2).Name = "Summary Source"
With oExcel.ActiveWorkbook.ActiveSheet
 .Range("A1").FormulaR1C1 = "Prod1"
 .Range("B1").FormulaR1C1 = "Amount"
 .Range("C1").FormulaR1C1 = "Code"
 .Range("A2").FormulaR1C1 = "111"
 .Range("A3").FormulaR1C1 = "222"
 .Range("A4").FormulaR1C1 = "333"
 .Range("B2").FormulaR1C1 = "11"
 .Range("B3").FormulaR1C1 = "22"
 .Range("B4").FormulaR1C1 = "33"
 .Range("C2").FormulaR1C1 = "1"
 .Range("C3").FormulaR1C1 = "2"
 .Range("C4").FormulaR1C1 = "3"
 .Range("A1:C4").Select
 .Range("C4").Activate
Endwith
with oExcel.ActiveWorkBook.Worksheets("Summary Source")
.ChartObjects.Add( ;
 oExcel.CentimetersToPoints( 3 ), ;
 oExcel.CentimetersToPoints( 2 ), ;
	oExcel.CentimetersToPoints( 11 ), ;
 oExcel.CentimetersToPoints( 11 ))
 With .ChartObjects(1).Chart
  .ChartType = xlBarStacked
  .SetSourceData( oExcel.ActiveWorkbook.Sheets('Sheet1').Range("A1:C4"), xlColumns)
  .HasTitle = .T.
  .ChartTitle.Characters.Text = "Deneme"
  .Axes(xlCategory, xlPrimary).HasTitle = .T.
  .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "XXXX"
  .Axes(xlValue, xlPrimary).HasTitle = .T.
  .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Merhaba"
 EndWith
endwith
Cetin

>Cetin
>
>Thanks but
>
>I just cut and paste your code and ran it.
>
>For me the chart gets created on sheet1 not on the "Summary Source" sheet.
>
>Seems to be ignoring the .Location
>
>I'm using VFP9 and Excel97
>
>Any thoughts ?
>
>I'll think about a workaround.
>
>Nick
>
>>>Hi
>>>
>>>I have a problem creating a chart on a sheet in a workbook.
>>>
>>>.ActiveChart.Location(xlLocationAsObject,"Summary Source")
>>>
>>>should create the chart on the sheet titled "Summary Source". This is the second sheet of four.
>>> But the chart is being created on the first sheet
>>>
>>>I tried selecting the sheet with
>>>
>>>.Sheets("Summary Source").Select
>>>
>>>and in Excel that is showing as the selected sheet but the chart still goes on the first sheet.
>>>
>>>Any ideas what I am doing wrong.
>>>
>>>Thanks
>>>
>>>Nick Mason
>>
>>Nick,
>>I haven't tried doing with .ActiveChart. This works for me:
>>
>>#include xlconstants.h
>>Local oExcel as "Excel.Application"
>>oExcel = CreateObject("Excel.Application")
>>oExcel.Workbooks.Add()
>>oExcel.Visible= .T.
>>oExcel.ActiveWorkbook.Worksheets(2).Name = "Summary Source"
>>With oExcel.ActiveWorkbook.ActiveSheet
>> .Range("A1").FormulaR1C1 = "Prod1"
>> .Range("B1").FormulaR1C1 = "Amount"
>> .Range("C1").FormulaR1C1 = "Code"
>> .Range("A2").FormulaR1C1 = "111"
>> .Range("A3").FormulaR1C1 = "222"
>> .Range("A4").FormulaR1C1 = "333"
>> .Range("B2").FormulaR1C1 = "11"
>> .Range("B3").FormulaR1C1 = "22"
>> .Range("B4").FormulaR1C1 = "33"
>> .Range("C2").FormulaR1C1 = "1"
>> .Range("C3").FormulaR1C1 = "2"
>> .Range("C4").FormulaR1C1 = "3"
>> .Range("A1:C4").Select
>> .Range("C4").Activate
>> .ChartObjects.Add( ;
>> oExcel.CentimetersToPoints( 3 ), ;
>> oExcel.CentimetersToPoints( 2 ), ;
>>	oExcel.CentimetersToPoints( 11 ), ;
>>oExcel.CentimetersToPoints( 11 ))
>> With .ChartObjects(1).Chart
>>  .ChartType = xlBarStacked
>>  .SetSourceData( oExcel.ActiveWorkbook.ActiveSheet.Range("A1:C4"), xlColumns)
>>  .Location( xlLocationAsObject, "Summary Source" )
>> Endwith
>>Endwith
>>
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform