How to input a password into a XLS file wirh OLE

How to input a password into a XLS file wirh OLE

Postby Kleyber » Fri Oct 31, 2008 12:22 pm

As the subject, I have a XLS file and it has a password. So, how to input it in order to open it?

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: How to input a password into a XLS file wirh OLE

Postby Enrico Maria Giordano » Fri Oct 31, 2008 1:06 pm

Hint: WorkBooks:Open() method has a parameter called Password.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Kleyber » Fri Oct 31, 2008 1:07 pm

Hi Enrico,

As usual, your help is fantastic. Just one more question: How to see the order of all the ::open() parameters? Can you show me?

Thanks a lot.
Kleyber Derick

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

Postby Rochinha » Fri Oct 31, 2008 1:14 pm

Hi,

To save use the third parameter in the method SaveAs of WorkBook object

FUNCTION MAIN()
LOCAL oExcel := CREATEOBJECT( "Excel.Application" )
LOCAL oWorkbook := oExcel:Workbooks
LOCAL oSheet := oExcel:ActiveSheet
...
savefile := oWorkbook.SaveAs( fileXL, ,"YourPassWord" )
...
RETURN NIL
Rochinha
 
Posts: 310
Joined: Sun Jan 08, 2006 10:09 pm
Location: Brasil - Sao Paulo

Postby Kleyber » Fri Oct 31, 2008 1:24 pm

SET PORTUGUESE ON

Fala Rochinha,

Não é bem isso que eu preciso. Eu tenho um arquivo XLS que está protegido por senha e eu tenho essa senha. Daí eu preciso somente abrir esse arquivo usando a senha...

Valeu,

SET ENGLISH ON

Hi Rochinha,

It's not exactly this what I need. I have a XLS file which is password protected and I already have this password. So, I need just open this file using the password.

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

Postby Enrico Maria Giordano » Fri Oct 31, 2008 1:28 pm

Kleyber wrote:Hi Enrico,

As usual, your help is fantastic. Just one more question: How to see the order of all the ::open() parameters? Can you show me?

Thanks a lot.


Open(FileName, UpdateLinks, ReadOnly, Format, Password, WriteResPassword, IgnoreReadOnlyRecommended, Origin, Delimiter, Editable, Notify, Converter, AddToMRU)


Please check VBA*.CHM help files or MSDN.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Kleyber » Fri Oct 31, 2008 1:29 pm

Enrico,

Thank you!!!

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

Postby Rochinha » Sat Nov 01, 2008 6:52 am

I think it is more complex.

You must determine if the password is in the spreadsheet or folder.

Use the example to improve the test in your XLS file.

Code: Select all  Expand view
#include "fivewin.ch"

FUNCTION main( fileXL )
    LOCAL oExcel, oWorkbook, nSheets

    oExcel := TOLEAuto():New( "Excel.Application" )
    oExcel:Visible     := .t.
    oExcel:UserControl := .t.

    oWorkbook := oExcel:Workbooks

    oWorkbook:Open( fileXL )

    oActiveWorkBook   := oExcel:ActiveWorkBook

    XLSisProtected( 1, oExcel:ActiveWorkBook, "" )

    nSheets := oActiveWorkBook:Sheets:Count()

    For i = 1 To nSheets
        oWS := oActiveWorkbook:Worksheets(i)
        oWS:Activate()
        XLSisProtected( 2, oWS, oWS:Name )
    Next

    oExcel:End()
    //oWorkbook:Open( fileXL,,,, "xlstest" )

    RETURN NIL

*
* *
* FUNCTION: Test if XLS file is protect
* *
*
FUNCTION XLSisProtected(n,oOBJ,sName)
    LOCAL isP := .t.
    If n==1
       isP := oOBJ:ProtectWindows
       isP := oOBJ:ProtectStructure
       If isP
          MsgStop( "IS Protected", "WorkBook Protection" )
       Else
          MsgStop( "IS NOT Protected", "WorkBook Protection" )
       EndIf
    Else
       isP := oOBJ:ProtectContents
       isP := oOBJ:ProtectDrawingObjects
       isP := oOBJ:ProtectScenarios
       If isP
          MsgStop( "IS Protected", "WorkBook "+sName+" Protection" )
       Else
          MsgStop( "IS NOT Protected", "WorkBook "+sName+" Protection" )
       EndIf
    EndIf
    Return(isP)
Rochinha
 
Posts: 310
Joined: Sun Jan 08, 2006 10:09 pm
Location: Brasil - Sao Paulo


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 85 guests