 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Aldwin Guest
|
Posted: Mon Jul 24, 2006 8:37 pm Post subject: Opening text file in excel using delphi |
|
|
Hi. How can I open text file with comma delimited value using excel in
delphi then transferring it to grid? I try this code below but it doesn't
give me the rigth result.
Maybe there is something lacking in my code while opening a text file.
var
Sheet, objExcel : Variant;
iMaxRow, iMaxCol : Integer;
AFilename : String;
begin
AFilename := location of the file.
objExcel := CreateOleObject('Excel.Application');
objExcel.Workbooks.OpenText(AFilename);
Sheet := objExcel.WorkSheets[1];
iMaxRow := Sheet.Usedrange.EntireRow.Count;
iMaxCol := Sheet.Usedrange.EntireColumn.Count;
end;
Thanks,
Aldwin Olanda |
|
| Back to top |
|
 |
Chris Cheney Guest
|
Posted: Mon Jul 24, 2006 9:05 pm Post subject: Re: Opening text file in excel using delphi |
|
|
"Aldwin" <hammerhead2221 (AT) hotmail (DOT) com> wrote in
news:44c4ea03 (AT) newsgroups (DOT) borland.com:
| Quote: | Hi. How can I open text file with comma delimited value using excel in
delphi then transferring it to grid? I try this code below but it
doesn't give me the rigth result.
Maybe there is something lacking in my code while opening a text file.
|
<snip>
You probably need to give Excel additional parameters to tell it something
about what you expect as the right result. The Microsoft Excel VBA help for
the opentext method should help you in this. |
|
| Back to top |
|
 |
Mike Shkolnik Guest
|
Posted: Tue Jul 25, 2006 1:15 am Post subject: Re: Opening text file in excel using delphi |
|
|
You must define the delimiter as parameter in OpenText method
--
With best regards, Mike Shkolnik
E-mail: mshkolnik (AT) scalabium (DOT) com
WEB: http://www.scalabium.com
"Aldwin" <hammerhead2221 (AT) hotmail (DOT) com> wrote in message
news:44c4ea03 (AT) newsgroups (DOT) borland.com...
| Quote: | Hi. How can I open text file with comma delimited value using excel in
delphi then transferring it to grid? I try this code below but it doesn't
give me the rigth result.
Maybe there is something lacking in my code while opening a text file.
var
Sheet, objExcel : Variant;
iMaxRow, iMaxCol : Integer;
AFilename : String;
begin
AFilename := location of the file.
objExcel := CreateOleObject('Excel.Application');
objExcel.Workbooks.OpenText(AFilename);
Sheet := objExcel.WorkSheets[1];
iMaxRow := Sheet.Usedrange.EntireRow.Count;
iMaxCol := Sheet.Usedrange.EntireColumn.Count;
end;
Thanks,
Aldwin Olanda
|
|
|
| Back to top |
|
 |
Aldwin Guest
|
Posted: Wed Jul 26, 2006 8:12 am Post subject: Re: Opening text file in excel using delphi |
|
|
When I try putting some parameters it give me error, It means it doesn't
accept any parameters only the file to be open. But what I did is I've drop
the code and get an Object ExcelApplication and supplied parameters on it
based on the MSDN. But I've encountered Ole error. Below is the code.
var
Value1, Value2,Value3,Value4, Value5 : olevariant;
AWideString : WideString;
begin
ExcelApplication1.Connect;
ExcelApplication1.Workbooks.OpenText(AWideString,xlWindows,1,xlDelimited,xlTextQualifierDoubleQuote,True,True,False,True,False,True,False,xlGeneralFormat,'
',Value2,Value3,Value4,Value5,1);
end;
Thanks,
Aldwin
"Mike Shkolnik" <mshkolnik2002 (AT) ukr (DOT) net> wrote in message
news:44c52a9a (AT) newsgroups (DOT) borland.com...
| Quote: | You must define the delimiter as parameter in OpenText method
--
With best regards, Mike Shkolnik
E-mail: mshkolnik (AT) scalabium (DOT) com
WEB: http://www.scalabium.com
"Aldwin" <hammerhead2221 (AT) hotmail (DOT) com> wrote in message
news:44c4ea03 (AT) newsgroups (DOT) borland.com...
Hi. How can I open text file with comma delimited value using excel in
delphi then transferring it to grid? I try this code below but it doesn't
give me the rigth result.
Maybe there is something lacking in my code while opening a text file.
var
Sheet, objExcel : Variant;
iMaxRow, iMaxCol : Integer;
AFilename : String;
begin
AFilename := location of the file.
objExcel := CreateOleObject('Excel.Application');
objExcel.Workbooks.OpenText(AFilename);
Sheet := objExcel.WorkSheets[1];
iMaxRow := Sheet.Usedrange.EntireRow.Count;
iMaxCol := Sheet.Usedrange.EntireColumn.Count;
end;
Thanks,
Aldwin Olanda
|
|
|
| Back to top |
|
 |
Aldwin Guest
|
Posted: Wed Jul 26, 2006 8:12 am Post subject: Re: Opening text file in excel using delphi |
|
|
Thanks for the info. I've drop the codes, I use the following instead. But
still I'm experiencing Ole error.
var
Value1, Value2,Value3,Value4, Value5 : olevariant;
AWideString : WideString;
begin
ExcelApplication1.Connect;
ExcelApplication1.Workbooks.OpenText(AWideString,xlWindows,1,xlDelimited,xlTextQualifierDoubleQuote,True,True,False,True,False,True,False,xlGeneralFormat,'
',Value2,Value3,Value4,Value5,1);
end;
Best regards,
Aldwin
"Chris Cheney" <cjc1@nospam%ucs.cam.ac.uk%no%spam%please> wrote in message
news:Xns980AADE9D4A04cjc1nospamucscamacuk (AT) 207 (DOT) 105.83.66...
| Quote: | "Aldwin" <hammerhead2221 (AT) hotmail (DOT) com> wrote in
news:44c4ea03 (AT) newsgroups (DOT) borland.com:
Hi. How can I open text file with comma delimited value using excel in
delphi then transferring it to grid? I try this code below but it
doesn't give me the rigth result.
Maybe there is something lacking in my code while opening a text file.
snip
You probably need to give Excel additional parameters to tell it something
about what you expect as the right result. The Microsoft Excel VBA help
for
the opentext method should help you in this. |
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|