Solved

insert an Excel chart into a word Document ??

Posted on 2000-04-26
7
429 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
Comment Utility
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
Comment Utility
Macros are out at least at this time.
0
 

Author Comment

by:psutton
Comment Utility
Adjusted points from 400 to 600
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 11

Expert Comment

by:robert_marquardt
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
You're welcome. I sent it.
-Jeurk.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now