Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VBA for Excel Graph
Message
From
08/02/2000 10:34:36
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
07/02/2000 14:38:14
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00327529
Message ID:
00328792
Views:
28
>Hi Cetin,
>
>Thanks for the response. I had searched for that and found your code but did not recognize it as using Excel and did not have time to take another path - yet.
>
>I went back today and found other examples. Thanks.
>
>Regards,
>
>Paige


Hi Paige,
I also read that you want to paste chart in word. I hope this sample helps (You'd need Excel constants header file name changed as appropriate) :
* Excel constants header file
#include "xlConstants.h"

*** set the LOCALEID to English
nlLocaleId=sys(3004)		&& Save local id
=sys(3006,1033)				&& We will be sending instructions in English
ox = crea('excel.application')

* If data is not few like in this sample better save as an xls file
* and open it in excel :
* ox.workbooks.open(cFileNameAndPath)
* instead of ox.workbooks.add()
ox.workbooks.add()
* ox.visible = .t. && Uncomment if you want to see command actions
* Notice speed difference if you do so
With ox.activeworkbook.worksheets(1)
  .Cells(1,1).Value = "Product Name"
  .Cells(1,2).Value = "Period"
  .Cells(1,3).Value = "Amount"
  .Cells(1,4).value = "Quota"
  .Cells(2,1).Value = ""
  .Cells(2,2).Value = ""
  .Cells(2,3).Value = " (In millions)"
  .Cells(2,4).value = " (In thousands)"
  .Cells(3,1).Value = "Product1"
  .Cells(3,2).Value = "Feb99"
  .Cells(3,3).Value = 12000
  .Cells(3,4).value = 13200
  .Cells(4,1).Value = "Product2"
  .Cells(4,2).Value = "May99"
  .Cells(4,3).Value = 45000
  .Cells(4,4).value = 45500
  .Cells(5,1).Value = "Product3"
  .Cells(5,2).Value = "Oct99"
  .Cells(5,3).Value = 37000
  .Cells(5,4).value = 42000

  lnCategoryLabels = 2  && Category description columns
  lnSeriesLabels = 2  && Series description rows
  lnSubGalleryFormat = 7 && Seventh type in gallery
  llHasLegend = .f.

  *   ox.charts.add()  && Add as a separate sheet
  *   loChart = ox.charts(1)
  With ox
    lnTop = .CentimetersToPoints(2)
    lnLeft = .CentimetersToPoints(0.5)
    lnWidth = .CentimetersToPoints(20)
    lnHeight = .CentimetersToPoints(15)
  Endwith
  .chartobjects.Add(lnLeft, lnTop, lnWidth, lnHeight) && Add as an object in a sheet

  loChart = .chartobjects(1).chart

  loChart.chartwizard(.range(.Cells(1,1),.Cells(5,4)),;
  xl3DColumn,lnSubGalleryFormat,xlColumns,;
  lnCategoryLabels,lnSeriesLabels,llHasLegend,"Title","Category Title","Value Title")

  PlayWithChart(loChart) && Titles will change too - comment to see difference

  loChart.ChartArea.copy() && Copy to clipboard
Endwith
*ox.charts(1).PrintOut   && Print chart
*ox.visible = .t. && Make excel visible
ox.activeworkbook.saved = .t. && Suppress save dialog
ox.quit

* Paste chart in clipboard to a word doc
oWrd = createobject("Word.application")
With oWrd
  .documents.add()
  With .activedocument
    #Define wdOrientLandscape  1
    #Define wdOrientPortrait  0
    .PageSetup.Orientation = wdOrientLandscape
    .content.paste && Paste chart
  Endwith
  .visible = .t.
  .Activate
Endwith
* Play with page setup, object position, size etc
* add some mail merge data and fire print voila :)

**** Set the LocaleId to the previous value
=sys(3006,val(nlLocaleId))


Function PlayWithChart
Lparameters toChartObject
With toChartObject
  *	.hastitle = .t.
  *	.haslegend = .t.
  .ChartTitle.caption = "This is chart title"
  *	.SetSourceData(ox.activeworkbook.worksheets(1).range("A1:C4"), xlColumns)
  *	.ChartType=xl3DArea
  *	.plotby = xlColumns
  With .Axes(xlCategory)
    .HasTitle = .t.
    With .TickLabels
      .Font.Size = 8
      .Orientation = 45 && Rotate labels 45 degrees
    Endwith
    With .AxisTitle
      .Caption = "This is category title"
      .Font.Name = "Arial"
      .Font.Size = 10
      .Font.Bold = .t.
    Endwith
  Endwith
  With .Axes(xlValue)
    .HasTitle = .T.
    With .AxisTitle
      .Caption = "This is Rotated Value title"
      With .Font
        .Size = 10
        .Bold = .f.
      Endwith
      .Orientation = 90 && Show 90 degrees rotated - clockwise

      With .Characters(len("This is R"),len("Rotated")).Font
        .Italic = .t.
        .Bold = .t.
        .Color = rgb(255,0,255)
      Endwith
    Endwith
  Endwith
  With .Axes(xlSeries)
    .HasTitle = .T.
    With .AxisTitle
      .Caption = "Rotated Series title"
      With .Font
        .Size = 8
        .Bold = .f.
      Endwith
      .Orientation = 75 && Show 75 degrees rotated - clockwise

      With .Characters(1,len("Rotated")).Font
        .Italic = .t.
        .Bold = .t.
        .Color = rgb(255,0,0)
      Endwith
    Endwith
  Endwith
  .PlotArea.Border.Color = rgb(255,0,0) && Red border
  .ChartArea.Border.Color = rgb(0,255,0) && Green border
  .Walls.Interior.ColorIndex = xlColorIndexNone
  .SeriesCollection(2).border.ColorIndex = 7
  .SeriesCollection(2).Interior.ColorIndex = 6
  .Floor.Interior.ColorIndex = 4

  .Axes(xlCategory).MajorGridlines.Border.ColorIndex = 2
  .Axes(xlSeries).MajorGridlines.Border.ColorIndex = 2
  .Axes(xlValue).Border.LineStyle = xlNone
  .Axes(xlCategory).Border.LineStyle = xlNone
  .Axes(xlSeries).Border.LineStyle = xlNone
  .Walls.Border.LineStyle = xlNone
  .Floor.Border.LineStyle = xlNone
Endwith
As you can see you can comment - uncomment various parts to see effect.
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform