Open Excel file with TOleAuto() (Solved)

Open Excel file with TOleAuto() (Solved)

Postby Kleyber » Fri May 22, 2009 7:22 pm

Hi All,

I have a little doubt here... how to open an Excel file protected by a password? I tried this:

Code: Select all  Expand view

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,
Last edited by Kleyber on Sun May 24, 2009 1:28 am, edited 1 time in total.
Kleyber Derick

FWH / xHb / xDevStudio / SQLLIB
User avatar
Kleyber
 
Posts: 581
Joined: Tue Oct 11, 2005 11:28 am
Location: São Luiz, Brasil

Re: Open Excel file with TOleAuto()

Postby Kleyber » Sat May 23, 2009 12:00 am

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,
Kleyber Derick

FWH / xHb / xDevStudio / SQLLIB
User avatar
Kleyber
 
Posts: 581
Joined: Tue Oct 11, 2005 11:28 am
Location: São Luiz, Brasil

Re: Open Excel file with TOleAuto()

Postby Rick Lipkin » Sat May 23, 2009 1:33 am

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
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Open Excel file with TOleAuto()

Postby Kleyber » Sat May 23, 2009 1:43 am

Hi Rick,

Thanks for answering... the error I get is this (from my error.log):

Code: Select all  Expand view

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,
Kleyber Derick

FWH / xHb / xDevStudio / SQLLIB
User avatar
Kleyber
 
Posts: 581
Joined: Tue Oct 11, 2005 11:28 am
Location: São Luiz, Brasil

Re: Open Excel file with TOleAuto()

Postby Rick Lipkin » Sat May 23, 2009 1:49 am

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
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Open Excel file with TOleAuto()

Postby nageswaragunupudi » Sat May 23, 2009 2:27 am

This code works.
Code: Select all  Expand view

   oBook    := oExcel:WorkBooks:Open( cFile, ;
                                      OleDefaultArg(), ;
                                      OleDefaultArg(), ;
                                      OleDefaultArg(), ;
                                      OleDefaultArg(), ;
                                      '1111' )

 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10624
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Open Excel file with TOleAuto()

Postby nageswaragunupudi » Sat May 23, 2009 3:37 am

I suggest to have a general function to open excel workbooks ( you may keep it in your libaray )
Code: Select all  Expand view

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  Expand view

   oBook := xlsBookOpen( oExcel, cFile, , , , , '1111' )
 

If you are using a Class like TExcel, I suggest the following method
Code: Select all  Expand view
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
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10624
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Open Excel file with TOleAuto()

Postby Kleyber » Sat May 23, 2009 1:34 pm

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,
Kleyber Derick

FWH / xHb / xDevStudio / SQLLIB
User avatar
Kleyber
 
Posts: 581
Joined: Tue Oct 11, 2005 11:28 am
Location: São Luiz, Brasil

Re: Open Excel file with TOleAuto()

Postby Kleyber » Sat May 23, 2009 1:36 pm

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,
Kleyber Derick

FWH / xHb / xDevStudio / SQLLIB
User avatar
Kleyber
 
Posts: 581
Joined: Tue Oct 11, 2005 11:28 am
Location: São Luiz, Brasil

Re: Open Excel file with TOleAuto() (Solved)

Postby Kleyber » Sat May 23, 2009 2:30 pm

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,
Kleyber Derick

FWH / xHb / xDevStudio / SQLLIB
User avatar
Kleyber
 
Posts: 581
Joined: Tue Oct 11, 2005 11:28 am
Location: São Luiz, Brasil

Re: Open Excel file with TOleAuto() (Solved)

Postby zlatan24 » Thu Jul 02, 2009 7:02 am

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.
zlatan24
 
Posts: 5
Joined: Thu Jul 02, 2009 6:46 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 96 guests