Board index » delphi » Accessing Excel.Chart.8 object within Word doc

Accessing Excel.Chart.8 object within Word doc

Can someone kindly help me out before I throttle someone/something.

I am kind of new to this whole automation stuff but with the help of
newsgroups etc and TurboPowers's OfficePartner, I have managed to cobble a
demo together where I open an existing document which I know has embedded
charts inside it. I can identify each one and even loop around showing the
names as follows...

//-------------------------
var
  oleObj: OleVariant;
  shp: OpWrd2k.InlineShape;
  oleRef: OpWrd2k.OleFormat;
  chartRef: variant;
...

    with OpWord.Server.ActiveDocument do
    begin
      if InLineShapes.Count>0 then
      begin
       ShowMessage(IntToStr(InLineShapes.Count)+' inline shapes');
       for i:=1 to InLineShapes.Count do
        begin
          shp := InLineShapes.Item(1);
          shp.Activate;
          ShowMessage(shp.OleFormat.ClassType); // Tells me they are
"Excel.Chart.8"
          oleRef := shp.OleFormat;
          chartRef := oleRef.Object_;
          chartRef.Activate; // Not sure whether this is required?
          ShowMessage('Title='+chartRef.Name);    // This line works
          ShowMessage('Title='+chartRef.ChartTitle); // This line doesn't
        end;
      end;
    end;
...

//-------------------------

I have tried looking at vbaxl9.chm and inside type libraries/object browsers
but almost all of the methods/properties that I seem to try result in the
message

"Method 'XXX' not supported by automation object"

Any help would be much appreciated!

David Cresswell
Eslington Technical Consultancy Ltd
d...@estechco.co.uk

 

Re:Accessing Excel.Chart.8 object within Word doc


<<David Cresswell:
ShowMessage(shp.OleFormat.ClassType); // Tells me they are
"Excel.Chart.8"
<snip>
ShowMessage('Title='+chartRef.ChartTitle); // This line
doesn't

Quote

There are two issues here. The first is that, despite all
its claims to the contrary, the embedded object is not a
chart object - it is a workook. The second is that the
Charttitle property is not a string property, but refers to
a Charttitle object, which has a Text property. So:

  Ch: ExcelChart;
..
  Ch := (Shp.OleFormat.Object_ as _Workbook).ActiveChart
         as _Chart;
  Ch.HasTitle[LOCALE_USER_DEFAULT] := True;
  Ch.ChartTitle[LOCALE_USER_DEFAULT].Text :=
    'This is not a chart';

--
Deborah Pate (TeamB) http://delphi-jedi.org

  TeamB don't see posts sent via Google or ISPs
  Use the real Borland server: newsgroups.borland.com
  http://www.borland.com/newsgroups/genl_faqs.html

Re:Accessing Excel.Chart.8 object within Word doc


<<Deborah Pate (TeamB):
  Ch: ExcelChart;

Quote

NB: if you use a variant for your chart object, you must
leave out the [LOCALE_USER_DEFAULT] when setting its
properties.

--
Deborah Pate (TeamB) http://delphi-jedi.org

  TeamB don't see posts sent via Google or ISPs
  Use the real Borland server: newsgroups.borland.com
  http://www.borland.com/newsgroups/genl_faqs.html

Re:Accessing Excel.Chart.8 object within Word doc


Deborah,

Many thanks for you response. Where is ExcelChart defined? I can't see it in
Excel_TLB or any of the OfficePartner units.
Should ch not be of type _Chart (given the "as")? Having said which when I
try it this way I get a

"No such interface supported message" on line

          Ch := (Shp.OleFormat.Object_ as _Workbook).ActiveChart as _Chart;

Any further assistance would be much appreciated!

David Cresswell
Eslington Technical Consultancy Ltd
d...@estechco.co.uk

"Deborah Pate (TeamB)" <d.p...@blueyonder.co.not-this-bit.uk> wrote in
message news:VA.000011c1.00b161ab@blueyonder.co.not-this-bit.uk...

Quote
> <<David Cresswell:
> ShowMessage(shp.OleFormat.ClassType); // Tells me they are
> "Excel.Chart.8"
> <snip>
> ShowMessage('Title='+chartRef.ChartTitle); // This line
> doesn't

> There are two issues here. The first is that, despite all
> its claims to the contrary, the embedded object is not a
> chart object - it is a workook. The second is that the
> Charttitle property is not a string property, but refers to
> a Charttitle object, which has a Text property. So:

>   Ch: ExcelChart;
> ..
>   Ch := (Shp.OleFormat.Object_ as _Workbook).ActiveChart
>          as _Chart;
>   Ch.HasTitle[LOCALE_USER_DEFAULT] := True;
>   Ch.ChartTitle[LOCALE_USER_DEFAULT].Text :=
>     'This is not a chart';

> --
> Deborah Pate (TeamB) http://delphi-jedi.org

>   TeamB don't see posts sent via Google or ISPs
>   Use the real Borland server: newsgroups.borland.com
>   http://www.borland.com/newsgroups/genl_faqs.html

Re:Accessing Excel.Chart.8 object within Word doc


<<David Cresswell:
Should ch not be of type _Chart (given the "as")?

Quote

That should be ok. ExcelChart is in Excel2000.pas, but it's
just an alias for _Chart. I've never used OfficePartner.

<<David:
"No such interface supported message"

Quote

Oh dear. Can you break the line apart to see whether it's
the _Workbook or the _Chart that causes the problem?

--
Deborah Pate (TeamB) http://delphi-jedi.org

  TeamB don't see posts sent via Google or ISPs
  Use the real Borland server: newsgroups.borland.com
  http://www.borland.com/newsgroups/genl_faqs.html

Re:Accessing Excel.Chart.8 object within Word doc


Deborah,

It's now stumbling over:-

          wb := (Shp.OleFormat.Object_ as _Workbook);

Is it worth me mentioning that I have been using D4 so far. I do have D6 if
you think it might make a difference?

David Cresswell
Eslington Technical Consultancy Ltd
d...@estechco.co.uk

"Deborah Pate (TeamB)" <d.p...@blueyonder.co.not-this-bit.uk> wrote in
message news:VA.000011cc.005e6216@blueyonder.co.not-this-bit.uk...

Quote
> <<David Cresswell:
> Should ch not be of type _Chart (given the "as")?

> That should be ok. ExcelChart is in Excel2000.pas, but it's
> just an alias for _Chart. I've never used OfficePartner.

> <<David:
> "No such interface supported message"

> Oh dear. Can you break the line apart to see whether it's
> the _Workbook or the _Chart that causes the problem?

> --
> Deborah Pate (TeamB) http://delphi-jedi.org

>   TeamB don't see posts sent via Google or ISPs
>   Use the real Borland server: newsgroups.borland.com
>   http://www.borland.com/newsgroups/genl_faqs.html

Re:Accessing Excel.Chart.8 object within Word doc


Deborah,

It would appear I have been misleading you slightly. I said in my first post
that the objects (of which there were three) were all coming out as
Excel.Chart.8's. In actual fact, due to the nature in which I set up my test
document I have one each of...

    Excel.Sheet.8
    Excel.Chart.8
    MSGraph.Chart.8

Is any one of these better to use than the other?

David Cresswell
Eslington Technical Consultancy Ltd
d...@estechco.co.uk

Re:Accessing Excel.Chart.8 object within Word doc


Deborah,

I seem to have sorted it out for myself (largely through trial and error)

If I use MSGraph.Chart.8 rather than Excel, then I can get away with...

var
  chartRef, ds, x, y: variant;
...
  shp := InLineShapes.Item(i);
  oleRef := shp.OleFormat;
  oleRef.Activate;
  chartRef := oleRef.Object_;
  ds := chartRef.Application.DataSheet;
   x := ds.Range['A1','A1'];
   y := x.Value;
   ShowMessage('A1='+FloatToStr(y));

Thank you kindly for your input anyway!

David Cresswell
Eslington Technical Consultancy Ltd
d...@estechco.co.uk

Re:Accessing Excel.Chart.8 object within Word doc


<<David Cresswell:
    Excel.Sheet.8
    Excel.Chart.8
    MSGraph.Chart.8

Is any one of these better to use than the other?

Quote

Ah, that explains the anomaly. If a simple chart is all you
need MSGraph is fine, IMO - you can do more with Excel
objects, but you get more baggage too.

--
Deborah Pate (TeamB) http://delphi-jedi.org

  TeamB don't see posts sent via Google or ISPs
  Use the real Borland server: newsgroups.borland.com
  http://www.borland.com/newsgroups/genl_faqs.html

Other Threads