Solved

insert an Excel chart into a word Document ??

Posted on 2000-04-26
7
433 Views
Last Modified: 2010-04-04
if you have a chart which is  contained in a specific sheet in the spreadsheet, How do you place the CHART AREA in the word doc ?  What am I trying to accomplish ?  I have stored with in spread sheet sheets chart objects and would like to insert these charts in to a mail merge doc., that is to say chart 1 from sheet1 is placed om page1 of the doc chart2 from sheet will be placed on page 2 of the doc...and so on


Using D 5.01 Pro and Late binding.
None of the server components have been used.
 Paul sutton
0
Comment
Question by:psutton
7 Comments
 
LVL 13

Expert Comment

by:Epsylon
ID: 2753373
Just a thought, maybe you could build a macro that does the main part of the job. Then this macro can be called from Delphi...

Look here for info on Excel and Word automation:

http://www.djpate.freeserve.co.uk/Automation.htm


Regards,

Epsylon.
0
 

Author Comment

by:psutton
ID: 2753446
Macros are out at least at this time.
0
 

Author Comment

by:psutton
ID: 2753865
Adjusted points from 400 to 600
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 11

Expert Comment

by:robert_marquardt
ID: 2754237
Do it in Word and record it as macro. Then have a look at the macro source. Reimplementing this in Delphi should be easier then.
0
 
LVL 4

Accepted Solution

by:
jeurk earned 600 total points
ID: 2754463
Hello,
You should do a cut and paste,
here is a sample that shows how to create a chart with excell and we copy paste it to a word doc.
we are assuming that we are already connected to excell.
the word connxion is done here.
here we goes :

procedure TfmMain.btExample5Click(Sender: TObject);
var
 WorkBook,Sheet1,Sheet2,Chart:variant;
 Sheet,SeriesCollection:Variant;
 vrange:variant;
 WD,WordDocument,wRange,Shape:variant;
 i,j:integer;
begin
 Excel.SheetsInNewWorkbook := 2;
 WorkBook:=Excel.Workbooks.Add;
 Sheet1:=WorkBook.WorkSheets[1];
 Sheet2:=WorkBook.WorkSheets[2];
 Chart:=WorkBook.Charts.Add;
 Sheet1.Name:='Table 1';
 Sheet2.Name:='Table 2';
 for j:=1 to 2 do begin
  Sheet:=WorkBook.WorkSheets[j];
  for i:=1 to 11 do begin
   Sheet.Cells.Item[i,1].Value:=i;
   Sheet.Cells.Item[i,2].Value:=i*2;
  end;
 end;
 vrange:=Sheet1.range['A1:A10'];
 SeriesCollection:=Chart.SeriesCollection;
 SeriesCollection.Add(vrange);
 vrange:=Sheet2.Range['B1:B10'];
 SeriesCollection.Add(vrange);
 Chart.Select;
 Excel.Selection.Copy;
 WD:=CreateOleObject('Word.Application');
 WordDocument:=WD.Documents.Add;
 if Chart.PageSetup.Orientation=xlLandscape
 then WordDocument.PageSetup.Orientation:=wdOrientLandscape
 else WordDocument.PageSetup.Orientation:=wdOrientPortrait;
 for i:=1 to 5 do begin
  WordDocument.Paragraphs.Add;
 end;
 wRange:=WordDocument.Range(0,1);
 wRange.Paste;
 showmessage(inttostr(WordDocument.Shapes.Count));
// Shape:=WordDocument.Shapes.Item(WordDocument.Shapes.Count);
// Shape.Height:=round(0.75*Shape.Height);
 wRange:=WordDocument.Range(2,2);
 wRange.Text:='Chart From Excel ';
 WD.visible:=true;
 WD:=unassigned;
end;

---

to connect to excell :
procedure TfmMain.btExcelConnectClick(Sender: TObject);
var
 Excel1:variant;
begin
 try
  Excel1:=GetActiveOleObject('Excel.Application');
  Excel:=Unassigned;
  Excel1:=Unassigned;
  Excel:=GetActiveOleObject('Excel.Application');
  isConnected:=true;
 except
  Excel:=Unassigned;
  showmessage('Active Excel not found');
 end;
 RefreshInfo;
 SetForegroundWindow(Handle);
end;

if you give me an email, i'll send you the whole project doing excell automation stuff.
I can't remember where I found so I'm unable to give you the link...
Regards.
0
 

Author Comment

by:psutton
ID: 2755308
Thanks. Your answer was prety much what I had in mind, I just didn't know how to get the different charts in to word.
email addr is psutton0623@yahoo.com
0
 
LVL 4

Expert Comment

by:jeurk
ID: 2755330
You're welcome. I sent it.
-Jeurk.
0

Featured Post

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question