I would think the best way to do this would be to create an OLE link to
excel, then open the worksheet using the object model
 
      try
        ExcelApp := GetActiveOLEObject('Excel.Application');
      except
        VarClear(ExcelApp);
      end;
 
      //We will have to create the object
      if VarIsEmpty(ExcelApp) then
      begin
        try
          ExcelApp := CreateOLEObject('Excel.Application');
        except
          VarClear(ExcelApp);
        end;
      end;
 
      //The reason we run through this third part is because of an
AntiVirus bug with Nortons, not sure if its needed with Excel, but
definitely with Word
      If VarIsEmpty(ExcelApp) then
      begin
        try
          ExcelApp := GetActiveOLEObject('Excel.Application');
        except
        end;
      end;
 
      if VarIsEmpty(ExcelApp) then
      begin
        ShowMessage('Error creating instance of Microsoft Excel');
      end
 
this works fine here
 
then to open a file use the worksheet or workbook commands. Refer to the
object model (Alt+F11 then F2 in excel)
 
Jason
 
 
-----Original Message-----
From: Colin Dillicar [mailto:[EMAIL PROTECTED]] 
Sent: Monday, 3 September 2001 10:04
To: Multiple recipients of list delphi
Subject: [DUG]: Interfacing to Excel
 
Guidance please.
 
  I have asked a similar question previously but not had a satisfactory
response. Here's hoping.
 
  I need to be able to create a text "Master" file and append data to it
from time to time from a delphi application.
 
  On occassions an operator will need to asyncronously access this file
and use Excel to manipulate and display the current data. I'm hoping to
have this process initiated within my application, firstly creating an
Excel compatible (*.csv) copy of the "Master" text file thus ensuring
that the original isn't used and maybe altered in some way, then calling
Excel.
 
  I have run many applications from within Delphi using the following
code example :
           WinExec('C:\Windows\NotePad.exe
C:\Temp\Sample.txt',sw_normal); 
 
{ Displays the text file 'Sample.txt' in Windows Notepad}
  This is similar to starting the Notepad program, with an argument,
from the Application "RUN" menu.

  Wheras calling Excel in the same way eg:- 
           WinExec('C:\MicrosoftOffice\Office\Excel.exe Sample.csv',
sw_normal);
will not start Excel and automatically load the 'Sample.csv' file, and
neither can I make it start in a similar fashion from the Windows
Application "RUN" menu. 
 
  What is so different about Excel?  I can call it from Explorer. I can
even double-click on a .CSV file in explorer and start Excel
by association thus loading and displaying the file I clicked on.
 
I have also tried connecting to Excel by setting up a Server Link to an
Excel component on a form using D5 but somehow I'm missing something in
the process.
 
  Please :- How best should I do this? Preferably in the simplest way
possible. Sample code would be appreciated.
 
 TIA
 
    Colin
 
---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED]
with body of "unsubscribe delphi"
Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/

Reply via email to