• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Visual LISP, AutoLISP and General Customization

    Reply
    Valued Contributor
    Posts: 75
    Registered: ‎10-07-2005

    How To Open Excell File

    43 Views, 3 Replies
    05-02-2006 01:58 AM
    Hi All,
    I have some data in an excell file and I want to use it just to querry. How can I open that excell file.
    Regards
    Please use plain text.
    *Adesu

    Re: How To Open Excell File

    05-02-2006 02:07 AM in reply to: Akdogan
    To open Excell,here the simple code

    (setq file "c:/YBI/Adesu/ext.xls") ; change with your file
    (setq xlsfile (getfiled "Open Excel File" file "xls" 0))
    (startapp (strcat "\"" "c:\\program files\\microsoft
    office\\office\\Excel.exe" "\"")
    (strcat "\"" xlsfile "\""))

    wrote in message news:5160587@discussion.autodesk.com...
    Hi All,
    I have some data in an excell file and I want to use it just to querry. How
    can I open that excell file.
    Regards
    Please use plain text.
    Distinguished Contributor
    Posts: 1,986
    Registered: ‎08-02-2004

    Re: How To Open Excell File

    05-02-2006 02:30 AM in reply to: Akdogan
    Hi Kamil

    See how it will work for you

    [code]
    (defun EXD ( / ExcelApp ExcData FilePath Sht ShtNum UsdRange Wbk)

    (vl-load-com)
    (setq FilePath (getfiled "Select Excel file to read :"
    (getvar "dwgprefix")
    "xls"
    16
    )
    )
    (setq ShtNum 1)
    (setq ExcelApp (vlax-get-or-create-object "Excel.Application"))
    (vla-put-visible ExcelApp :vlax-true)
    (setq Wbk (vl-catch-all-apply 'vla-open
    (list (vlax-get-property ExcelApp "WorkBooks") FilePath)))
    (setq Sht (vl-catch-all-apply 'vlax-get-property
    (list (vlax-get-property Wbk "Sheets")
    "Item" ShtNum)))
    (vlax-invoke-method Sht "Activate")
    (setq UsdRange (vlax-get-property Sht 'UsedRange)
    ExcData (vlax-safearray->list (vlax-variant-value
    (vlax-get-property UsdRange 'Value))))
    (setq ExcData (mapcar (function (lambda (x)(mapcar 'vlax-variant-value x))) ExcData))

    (vl-catch-all-apply
    'vlax-invoke-method
    (list Wbk "Close")
    )

    (vl-catch-all-apply
    'vlax-invoke-method
    (list ExcelApp "Quit")
    )

    (mapcar
    (function (lambda (x)
    (if (not (vlax-object-released-p x))

    (vlax-release-object x)
    )
    )
    )
    (list UsdRange Sht Wbk ExcelApp)
    )
    (setq UsdRange nil
    Sht nil
    Wbk nil
    ExcelApp nil
    )
    (gc)
    (gc)
    ExcData
    ;;; or (mapcar (function (lambda (x)(mapcar 'atof x))) ExcData)
    ExcData
    )
    ; CaLL :
    (setq data (exd))
    [/code]

    Fatty

    ~'J'~
    Please use plain text.
    Valued Contributor
    Posts: 75
    Registered: ‎10-07-2005

    Re: How To Open Excell File

    05-02-2006 04:38 AM in reply to: Akdogan
    Hi Oleg,
    Thank you for the code. It worked great for a little data, but I have to try it for a huge one. I think it will work again. I will write the result to you.
    Regards...
    Please use plain text.