Newbie Question-How do I open excel file with Delphi 2007

I'm completely new to Delphi Programming, I got a little experience with VB but this is completely different.  All I want to do is open a Excel 2003 document.

Edited by: Terrance MacDonald on Jan 28, 2009 7:48 AM
0
Terrance
1/28/2009 3:48:13 PM
embarcadero.delphi.ole 598 articles. 1 followers. Follow

2 Replies
524 Views

Similar Articles

[PageSpeed] 23

Terrance MacDonald wrote:

> I'm completely new to Delphi Programming, I got a little experience
> with VB but this is completely different.  All I want to do is open a
> Excel 2003 document.
> 
> Edited by: Terrance MacDonald on Jan 28, 2009 7:48 AM

You can find a lot of information on OLE automation with Delphi on this
site: http://www.djpate.freeserve.co.uk/Automation.htm

Look at the Servers tab in the component palette. If you have used the
default installation options you should have components like
TExcelApplication, which are component wrappers around the Excel object
model. They use early binding, which, together with
Delphi's strong typing, makes usage a bit cumbersome at times:

  ExcelApplication1.Connect;
  ExcelApplication1.Workbooks.Open(CFilename, EmptyParam, EmptyParam,
    EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,
    EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,
    GetThreadLocale);
  ExcelApplication1.Visible[GetThreadLocale] := true;

That would load a workbook and show Excel with it loaded. You cannot
leave off optional parameters when using early binding, but have to
pass EmptyParam (a variant constant) for each. The alternative is late
binding, which saves on typing but has the big disadvantage of not
allowing any syntax checking on the automation calls you make at
compile-time. And it is slower.

var
  Excel: OLEVariant;
begin
  Excel := CreateOleObject('Excel.Application');
  Excel.Workbooks.Open(CFilename);
  Excel.Visible := true;

This requires the ComObj unit to be added to the Uses clause. Using
early binding requires ExcelXP or Excel2000, which get added
automatically when you drop a TExcelApplication on a form and save.

-- 
Peter Below (TeamB)  
Don't be a vampire (http://slash7.com/pages/vampires), 
use the newsgroup archives :
http://www.tamaracka.com/search.htm
http://groups.google.com
0
Peter
1/28/2009 6:09:30 PM
> I'm completely new to Delphi Programming, I got a little experience with 
> VB but this is completely different.
>  All I want to do is open a Excel 2003 document.
Do you want to display the loaded xls-file in form?
If yes, then use the TOLEContainer component:
yourOLEContainer.CreateObjectFromFile('c:\aaa.xls', False)

-- 
With best regards, Mike Shkolnik
http://www.scalabium.com
0
Mike
1/28/2009 10:08:56 PM
Reply:

Similar Artilces:

How to use a delphi XE3 obj file in delphi 2007?
Hi, I'm migrating an application from delphi 2007 to delphi XE3 and I would like to do it in several steps. To do this I need to use a part of my new code (XE3) in the current delphi 2007 application. So I want to use the .obj file from my XE3 file. I know I have to use the {$L 'Filename'} and I know that I have to declare the functions that I want to use in external in my D2007 project. I wanted to make an easy and simple example to see how it works with only 1 function 'hello world' compiled in obj with XE3 but I can't find the way to use it in D2007. In D200...

Newbie Question about Delphi 2007 Editor
Is it possible to respect the end-of-line in Delphi 2007...like VB6 and most other text editors do? In other words, if you're on a long line and cursor down to a short one, the cursor would jump to the end of the short line? Or if you're at the end of a line and you cursor right, it would jump to the next line? Thanks, Rob Robert Morley wrote: > Is it possible to respect the end-of-line in Delphi 2007...like VB6 and most > other text editors do? In other words, if you're on a long line and cursor > down to a short one, the cursor would jump to the...

Delphi 2007 to Delphi 7
I've written a class in Delphi 2007 that is not supported in Delphi 7. What would be the best way to achive what I've done in Delphi 2007 in Delphi 7? Thanks, Tom type BondConstants = class { Bond Types } type BondType = record const TREASURY = 3; AGENCY = 0; CORP = 1; MUNI = 2; SBA = 5; MBS = 4; CMO = 6; end; { Day Count Methods } type DayCount = record const ACTUAL_360 = 2; ACTUAL_365 = 1; ACTUAL_ACTUAL = 1; d30_360 = 0; ...

Delphi 4 to Delphi 2007
Hello, I will have to port a D4 application (with source) to D2007. what kind of problem could I face ? I will have to go to customer site tommorow to analyse its source code to quote the work, what should I care of to hestimate the porting time ? Thanks John Terry wrote: > Hello, > I will have to port a D4 application (with source) to D2007. > what kind of problem could I face ? > I will have to go to customer site tommorow to analyse its source code > to quote the work, what should I care of to hestimate the porting time ? You can probably do it by just changi...

Missing library file when opening Excel in Vista64 with Delphi? [Edit]
Hello everyone, This is my first post here, I hope I have it in the correct place. I have just moved across to a new machine running vista64. Delphi 6 Pro installed fine, and runs fine. I tried to run (from within delphi) an app I wrote on a WinXP system, which is very simple, it opens an Excel 97 Spreadsheet and puts some numbers in it. When I click on the button to actually open the spreadsheet I get this error: "First chance exception at $76EEF328. Exception class EOleException with message 'One of your object libraries (stdole32.tlb) is missing or damaged. Plea...

MS Excel 2010, Delphi XE, Opening a tab delimited file
Hi, I am trying to open a tab delimited file with Excel 2010 using Delphi XE Starter Edition. I can open the file successfully using the Excel GUI, but when I try to automate the process with Delphi, it fails. The file opens successfully, but each line of the tab delimited text file is placed into the 1st cell of each row --the workbook only has 1 column. When I use the Excel GUI on the same file, each tab character creates a new cell to the right so I get multiple columns per row. What am I doing wrong? I also tried using Workbooks.OpenText to no avail. var xlApp : _Applicatio...

Moving from Delphi 7 to Delphi 2007
Is there any compelling reason to move (quite a large project) from Delphi 7 to Delphi 2007? Specifically, is there better Vista/Win7/Win8 integration provided by Delphi 2007? (In the project I am already using a custom manifest file for Vista/Win7 etc.. and not the std XPMan component) Does 2007 add any new bugs to the scene? Thanks Rael Rael wrote: > Is there any compelling reason to move (quite a large project) from > Delphi 7 to Delphi 2007? If you are going to upgrade, why not upgrade to something newer? > In the project I am already using a custom man...

Delphi 2010 w Delphi 2007
I have D2007 installed on my laptop (XP sp3 running on dual core Athlon). Can I install D2010 on this machine without it affecting D2007? Will D2010 affect D2007 in any way? Thanks, Randall Carpenter > {quote:title=Randall Carpenter wrote:}{quote} > I have D2007 installed on my laptop (XP sp3 running on dual core Athlon). > Can I install D2010 on this machine without it affecting D2007? Will D2010 > affect D2007 in any way? Won't hurt a thing. I have D7, RAD Studio 2007, RAD Studio 2009, and RAD Studio 2010 all on my desktop system and they coexist fine. Jus...

Delphi 2009 alongside Delphi 2007
Hi all, I am about to install Delphi 2009 on the same development system as Delphi 2007, before I embark is there anything I should be aware of so as to not break my Delphi 2007 installation and projects ? Thanks JT John Taylor wrote: > Hi all, > > I am about to install Delphi 2009 on the same development system > as Delphi 2007, before I embark is there anything I should be aware > of so as to not break my Delphi 2007 installation and projects ? As long as you install into a separate folder there is no problem with the two versions getting into each other...

Delphi 2007 RTL in Delphi 7
I read somewhere that it is possible to use Delphi 2007's (or for that matter Delphi 2006's) RTL in Delphi 7 by just recompiling the source of RTL. Is this really possible? What are the benefits that we can derive using a higher version's RTL? TIA Yogi Yang Yogi Yang wrote: > I read somewhere that it is possible to use Delphi 2007's (or for > that matter Delphi 2006's) RTL in Delphi 7 by just recompiling the > source of RTL. If it actually compiles in Delphi 7, I guess it would be possible. OTOH, if one has Delphi 2007 already, I don't s...

Delphi and Delphi Prism licensing question
When I buy Delphi and Delphi Prism, do I get a "named user licence" or a "workstation licence"? Can I install both products on two machines I use with the same licence keys? I have a Mac Pro ("Cyrus") running Vista 64 in VMware and a MacBook ("Blacky") running Vista 32 in Parallels. Can I install Delphi and Delphi Prism on both Cyrus and Blacky since I use both machines (and like to have all dev tools I use installed on both machines at all times)? Andrew Brehm wrote: > When I buy Delphi and Delphi Prism, do I get a "named user licence...

Migrate from Delphi 2007 to Delphi 2010
Hi All, Thanks in advance for your help. Below is my query, Currently I am using Delphi 2007 and i want to migrate to Delphi 2010. 1. What all things i need to take care while doing this? 2. What all third party components will get impacted? 3. Any known issues in Delphi 2010 which might impact the cause? 4. Any changes in database operation required as i am using Oracle? Hope I have post this query under correct category. If not sorry for the trouble and could you please suggest me the correct category for this? Looking forward for your response. Have a great day. Th...

Delphi 2007 to Delphi 2009 Conversion
CharArrayPtr = ^CharArray; CharArray = array[0..MaxInt-1] of Char; How to convert to Delphi 2009? Bill Bill Miller wrote: > CharArrayPtr = ^CharArray; > CharArray = array[0..MaxInt-1] of Char; > > How to convert to Delphi 2009? > > Bill it depends heavelly on how it is used fearther down in your project and what you want to convert it to. I you want to simple convert the declarations ignoring UNicode altogether then the only think you have to change is the CharArray declaratin from a Char to an AnsiChar eg CharArrayPtr = ^CharArray; CharArray =...

is there a Delphi 2007
Would be nice to have a bundle of the latest Delphi packages. Gilbert Padilla wrote: > Would be nice to have a bundle of the latest Delphi packages. > I expect Delphi 2007 will only be on sale until the full RAD Studio 2009 edition is published, including Delphi 2009.net. W ...

Web resources about - Newbie Question-How do I open excel file with Delphi 2007 - embarcadero.delphi.ole


How Question Sites Could Become Big Business - Businessweek
Q&A sites say some queries are best fielded by humans, not Google

'How to Get Away With Murder' Season 1 Episode 2 SPOILERS: Connor Questions How Wes Made the Team, Is ...
The case is starting to heat up for Professor Annalise Keating's five star student team on "How to Get Away With Murder," but there's only one ...

Missing Money? Report questions how states spent ObamaCare funds
Missing Money? Report questions how states spent ObamaCare funds

Judge calls into question how L.A. handles parking ticket challenges
A Los Angeles Superior Court judge has called into question the way L.A. handles parking tickets, saying city employees should review ...

Today Show Panel Questions How Chris Christie’s Weight Factors Into His Presidential Aspirations
The Today Show ‘s “Today’s Professionals” panel chimed in this morning on how New Jersey Gov. Chris Christie ‘s weight factors into his potential ...

How Questions About Mammography Apply To CT Scans For Lung Cancer
The 20 percent mortality reduction found for lung CT screening for heavy smokers is in the same ballpark as the probable benefit from mammograms ...

How's the market? Real estate expo convenes to consider the question.
Show me the data: That could've been the mantra of the 25th Annual Real Estate Convention and Expo, held Tuesday at the Santa Clara Convention ...

How's the off-season treating Shawn Thornton? Plus he answers your questions.
Watch How's the off-season treating Shawn Thornton? Plus he answers your questions. in the WEEI Audio

Bret Baier Panel Questions How Romney Let Obama’s Attacks Put Him On The Defense
Amid ongoing negative campaigning, Bret Baier asked his panel on Monday to weigh in on how effective some specific attacks are. While the panel ...

Resources last updated: 12/29/2015 8:42:57 PM