Page 1 of 1
Open Excel file with TOleAuto() (Solved)
Posted: Fri May 22, 2009 7:22 pm
by Kleyber
Hi All,
I have a little doubt here... how to open an Excel file protected by a password? I tried this:
Code: Select all
oExcel := TOleAuto():New( "Excel.Application" )
if Ole2TxtError() # "S_OK"
MsgInfo("EXCEL não está instalado nesta máquina."+CRLF+"Impossível gerar planilha","ATENÇÃO")
return nil
endif
oExcel:Workbooks:Open( cDirXLS+cArquivoX, , , ,"1111" )
But it gives me an error. Where am I wrong?
TIA,
Re: Open Excel file with TOleAuto()
Posted: Sat May 23, 2009 12:00 am
by Kleyber
The sintaxis for the command is:
Open(FileName, UpdateLinks, ReadOnly, Format, Password, WriteResPassword, ;
IgnoreReadOnlyRecommended, Origin, Delimiter, Editable, Notify, Converter, AddToMRU)
So, I don't understand what is happening.
Any clue?
TIA,
Re: Open Excel file with TOleAuto()
Posted: Sat May 23, 2009 1:33 am
by Rick Lipkin
Kleyber
I am not sure what type of error you are getting and why .. when I use OLE I always trap the command like this :
try
oExcel := CREATEOBJECT( "Excel.Application" )
catch oErr
Msginfo("error in opening Excel")
end try
I can not remember the code to interogate the error object oErr .. perhaps someone else can chime in here.
Rick Lipkin
Re: Open Excel file with TOleAuto()
Posted: Sat May 23, 2009 1:43 am
by Kleyber
Hi Rick,
Thanks for answering... the error I get is this (from my error.log):
Code: Select all
Error Excel.Application:WORKBOOKS/14 DISP_E_BADPARAMCOUNT: OPEN
Argumentos :
[ 1] = C C:\Kleyber_TK\Money\Credfort\9649_4B6A716F_5782382000419_BH_19052009_CONSIGNADO.xls
[ 2] = C
[ 3] = C
[ 4] = C
[ 5] = C 1111
Regards,
Re: Open Excel file with TOleAuto()
Posted: Sat May 23, 2009 1:49 am
by Rick Lipkin
Kleyber
Found this link with the same error :
http://www.rhinocerus.net/forum/lang-xh ... -file.html
However, it does look like you are opening the file with the full path .. just a quick observation .. can you shorten the file name and see if that helps ?
Rick
Re: Open Excel file with TOleAuto()
Posted: Sat May 23, 2009 2:27 am
by nageswaragunupudi
This code works.
Code: Select all
oBook := oExcel:WorkBooks:Open( cFile, ;
OleDefaultArg(), ;
OleDefaultArg(), ;
OleDefaultArg(), ;
OleDefaultArg(), ;
'1111' )
Re: Open Excel file with TOleAuto()
Posted: Sat May 23, 2009 3:37 am
by nageswaragunupudi
I suggest to have a general function to open excel workbooks ( you may keep it in your libaray )
Code: Select all
function xlsBookOpen( ... ) // ( oExcel, cFile, < .. open params > )
local aParams := HB_AParams()
local n
local oExcel := aParams[ 1 ]
local oBook
ADel( aParams, 1, .t. )
for n := 2 to Len( aParams )
if aParams[ n ] == nil
aParams[ n ] := OleDefaultArg()
endif
next
oBook := HB_ExecFromArray( oExcel:WorkBooks, 'Open', aParams )
return oBook
Usage:
Code: Select all
oBook := xlsBookOpen( oExcel, cFile, , , , , '1111' )
If you are using a Class like TExcel, I suggest the following method
Code: Select all
method Open( ... ) class TExcel // ( cFile, < .. open params > )
local aParams := HB_AParams()
local n
local oBook
for n := 2 to Len( aParams )
if aParams[ n ] == nil
aParams[ n ] := OleDefaultArg()
endif
next
oBook := HB_ExecFromArray( ::oExcel:WorkBooks, 'Open', aParams )
return oBook
Note: OleDefaultArg() is a function from Win32Ole.Prg of XHarbour
Re: Open Excel file with TOleAuto()
Posted: Sat May 23, 2009 1:34 pm
by Kleyber
Thanks for your good answer Nagesh. As I have xHarbour 1.1.0 and FWH 8.02 it does not have the function OleDefaultArg(). Is there a similar one in my xHarbour version?
Regards,
Re: Open Excel file with TOleAuto()
Posted: Sat May 23, 2009 1:36 pm
by Kleyber
Rick Lipkin wrote:Kleyber
Found this link with the same error :
http://www.rhinocerus.net/forum/lang-xh ... -file.html
However, it does look like you are opening the file with the full path .. just a quick observation .. can you shorten the file name and see if that helps ?
Rick
Thanks Rick, but the error still persists.
Regards,
Re: Open Excel file with TOleAuto() (Solved)
Posted: Sat May 23, 2009 2:30 pm
by Kleyber
Well I solved the problem. I got the Win32Ole.prg for a newer version of xHarbour and put in my project. Now it works like a charm.
Thank you Nagesh and Rick.
Best Regards,
Re: Open Excel file with TOleAuto() (Solved)
Posted: Thu Jul 02, 2009 7:02 am
by zlatan24
At work with excel files advise to use-
xlsx corrupt,because tool helped me many times,has free status as far as I know,moreover program has many admissibilties such as can repair .xlsx even without touching your keyboard, just left click your mouse several times and all of your data will be recovered,automatically and attempts to repair xlsx corrupt, that was considered lost,recover maximum percents of your document manually, than the entire Excel workbook.