Jump to content

Recommended Posts

Posted

Can I use LISP to read XCELL data or does this need to be done through vba or vb.net?

Posted

you can use lisp. search this fourm and you should find many examples. everyones needs are diffrent but the general connection is the same

Posted
Can I use LISP to read XCELL data or does this need to be done through vba or vb.net?

Give this a shot

(vl-load-com)
(defun read_excel_range (FilePath ShtNum Address / ExcelApp ExcData Sht UsdRange Wbk)
 (setq ExcelApp (vlax-get-or-create-object "Excel.Application"))
 (vla-put-visible ExcelApp :vlax-true)
 (vlax-put-property ExcelApp 'DisplayAlerts :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
    (vlax-get-property Sht 'Cells) "Range" Address)
ExcData  (vlax-safearray->list
    (vlax-variant-value
      (vlax-get-property UsdRange 'Value2)
    )
  )
 )
 (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)
(vl-catch-all-apply
  (function (lambda ()
       (progn
  (if (not (vlax-object-released-p x))
    (progn
      (vlax-release-object x)
      (setq x nil)
    )
  )
       )
     )
  )
)
     )
   )
   (list UsdRange Sht Wbk ExcelApp)
 )
 (gc)
 (gc)
 (gc)
 ExcData
)
(defun C:demo()
(if
   (setq xlpath (getfiled "* Select Excel File *"
     ""
     "xls"
     4)
  )

    (progn
     (setq excel_data (read_excel_range xlpath "Sheet1" "A1:E15"));<--change to suit
     (princ excel_data);<--debug only
     ;| work further with data here |;
     )
 )
 (princ)
 )

 

~'J'~

  • 3 weeks later...
Posted

how to use this code? Im new in lisp...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...