| View previous topic :: View next topic |
| Author |
Message |
Aldwin Guest
|
Posted: Wed Jul 26, 2006 8:12 am Post subject: Opening file in excel using OleContainer |
|
|
Hi guys. How do you open or save file using OleContainer with excel as its
object? I want to open or save file programmatically. Can you add codes in
my example.
Example:
OleContainer1.CreateObject('Excel.Sheet',True);
OleContainer1.DoVerb(ovShow);
Thanks,
Aldwin |
|
| Back to top |
|
 |
Aldwin Guest
|
Posted: Wed Jul 26, 2006 8:12 am Post subject: Re: Opening file in excel using OleContainer |
|
|
Thanks Deborah , but what i intend to do is to open a particular xls or txt
file.
Best regards,
Aldwin
"Deborah Pate (TeamB)" <d.pate (AT) blueyonder (DOT) co.not-this-bit.uk> wrote in
message news:VA.000020e0.00134ba2 (AT) blueyonder (DOT) co.not-this-bit.uk...
| Quote: | Aldwin:
How do you open or save file using OleContainer with excel
as its object? I want to open or save file
programmatically.
OleContainer1.CreateObjectFromFile('C:\Docs\Excel
sheets\Book1.xls', True);
OleContainer1.DoVerb(ovShow);
OleContainer1.SaveAsDocument('C:\My
Documents\Book1.xls');
--
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
|
|
|
| Back to top |
|
 |
Deborah Pate (TeamB) Guest
|
Posted: Wed Jul 26, 2006 8:12 am Post subject: Re: Opening file in excel using OleContainer |
|
|
<<Aldwin:
what i intend to do is to open a particular xls or txt
file.
That is what I did:
OleContainer1.CreateObjectFromFile(
'C:\Docs\Excel sheets\Book1.xls', True);
--
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 |
|
| Back to top |
|
 |
Deborah Pate (TeamB) Guest
|
Posted: Wed Jul 26, 2006 8:12 am Post subject: Re: Opening file in excel using OleContainer |
|
|
<<Aldwin:
How do you open or save file using OleContainer with excel
as its object? I want to open or save file
programmatically.
OleContainer1.CreateObjectFromFile('C:\Docs\Excel
sheets\Book1.xls', True);
OleContainer1.DoVerb(ovShow);
OleContainer1.SaveAsDocument('C:\My
Documents\Book1.xls');
--
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 |
|
| Back to top |
|
 |
Aldwin Guest
|
Posted: Wed Jul 26, 2006 6:02 pm Post subject: Re: Opening file in excel using OleContainer |
|
|
Thanks Deborah, I tried what you've inform me. But i stil have a question,
how can I use the properties or method of an excel object in a olecontainer?
Best regards,
Aldwin
"Deborah Pate (TeamB)" <d.pate (AT) blueyonder (DOT) co.not-this-bit.uk> wrote in
message news:VA.000020e1.003af93a (AT) blueyonder (DOT) co.not-this-bit.uk...
| Quote: | Aldwin:
what i intend to do is to open a particular xls or txt
file.
That is what I did:
OleContainer1.CreateObjectFromFile(
'C:\Docs\Excel sheets\Book1.xls', True);
--
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
|
|
|
| Back to top |
|
 |
Aldwin Guest
|
Posted: Wed Jul 26, 2006 7:48 pm Post subject: Re: Opening file in excel using OleContainer |
|
|
Oki doki Deborah, .. So you mean I can't open a text file in a excel
object, the only command to do that is by olecontainer.LoadFromFile()? The
reason I'm asking you about opening a file is that I wanted to open a Comma
delimited text file and import it in excel using delphi. I also used the
codes below just to import a text file to excel, but it didn't do the proper
comma delimited feature. I also used the ExcelApplication object with a
property Opentext, eventhough I've managed to put the exact parameters that
I've found in MSDN library, still luck is not on my side, co'z I've
encountered an ole error. I've also post that here with a subject Opening
Text file in excel using delphi. Thank you very much for you time.
Example A.
objExcel := CreateOleObject('Excel.Application');
objExcel.WorkBooks.Open(ExcelPath);
Sheet := objExcel.WorkSheets[iSheetIndex];
Example B.
objExcel := CreateOleObject('Excel.Application');
objExcel.WorkBooks.OpenText(ExcelPath);
Sheet := objExcel.WorkSheets[iSheetIndex];
Best regards,
Aldwin
"Deborah Pate (TeamB)" <d.pate (AT) blueyonder (DOT) co.not-this-bit.uk> wrote in
message news:VA.000020e3.0188db0b (AT) blueyonder (DOT) co.not-this-bit.uk...
| Quote: | Aldwin:
how can I use the properties or method of an excel object
in a olecontainer?
The actual Excel object in an olecontainer is a workbook.
So you can do things like this:
var
VExcel, VWB, VWS: OleVariant;
..
Olecontainer1.Doverb(ovPrimary);
VWB := Olecontainer1.Oleobject;
VExcel := VWB.Application;
VWS := VWB.ActiveSheet;
Caption := VWS.Name;
VWS.Range['A1'].Value := 'First cell';
Caption := VWS.Cells.Item[1, 2].Value;
VExcel.ActiveWindow.DisplayGridlines := False;
You can use nearly all of the automation commands that you
would use automating Excel outside of an olecontainer. The
exceptions are things like opening and saving files, which
you have to do using the olecontainer's methods (since it
needs to be in charge of those actions).
--
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
|
|
|
| Back to top |
|
 |
Deborah Pate (TeamB) Guest
|
Posted: Wed Jul 26, 2006 8:05 pm Post subject: Re: Opening file in excel using OleContainer |
|
|
<<Aldwin:
how can I use the properties or method of an excel object
in a olecontainer?
The actual Excel object in an olecontainer is a workbook.
So you can do things like this:
var
VExcel, VWB, VWS: OleVariant;
...
Olecontainer1.Doverb(ovPrimary);
VWB := Olecontainer1.Oleobject;
VExcel := VWB.Application;
VWS := VWB.ActiveSheet;
Caption := VWS.Name;
VWS.Range['A1'].Value := 'First cell';
Caption := VWS.Cells.Item[1, 2].Value;
VExcel.ActiveWindow.DisplayGridlines := False;
You can use nearly all of the automation commands that you
would use automating Excel outside of an olecontainer. The
exceptions are things like opening and saving files, which
you have to do using the olecontainer's methods (since it
needs to be in charge of those actions).
--
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 |
|
| Back to top |
|
 |
Deborah Pate (TeamB) Guest
|
Posted: Wed Jul 26, 2006 10:15 pm Post subject: Re: Opening file in excel using OleContainer |
|
|
<<Aldwin:
I wanted to open a Comma delimited text file and import it
in excel using delphi.
This works for me. If it doesn't for you, could you tell us
the exact error you get?
uses ComObj;
procedure TForm1.Button1Click(Sender: TObject);
var
objExcel, Sheet: OleVariant;
begin
objExcel := CreateOleObject('Excel.Application');
ObjExcel.Visible := True;
objExcel.WorkBooks.OpenText('C:\Docs\Test1.csv');
Sheet := objExcel.WorkSheets[1];
Caption := Sheet.Name;
end;
If you don't need to use a TOleContainer, then I'd advise
avoiding them, as they just add complications.
--
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 |
|
| Back to top |
|
 |
Aldwin Guest
|
Posted: Thu Jul 27, 2006 6:31 pm Post subject: Re: Opening file in excel using OleContainer |
|
|
Thanks Deborah. I've managed to solve the problem. I've just put additional
parameters like delimiter , format and text qualifier..
All the best,
Aldwin
"Deborah Pate (TeamB)" <d.pate (AT) blueyonder (DOT) co.not-this-bit.uk> wrote in
message news:VA.000020e4.00195faa (AT) blueyonder (DOT) co.not-this-bit.uk...
| Quote: | Aldwin:
I wanted to open a Comma delimited text file and import it
in excel using delphi.
This works for me. If it doesn't for you, could you tell us
the exact error you get?
uses ComObj;
procedure TForm1.Button1Click(Sender: TObject);
var
objExcel, Sheet: OleVariant;
begin
objExcel := CreateOleObject('Excel.Application');
ObjExcel.Visible := True;
objExcel.WorkBooks.OpenText('C:\Docs\Test1.csv');
Sheet := objExcel.WorkSheets[1];
Caption := Sheet.Name;
end;
If you don't need to use a TOleContainer, then I'd advise
avoiding them, as they just add complications.
--
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
|
|
|
| Back to top |
|
 |
|