Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defun EXD (/ ExcelApp ExcData FilePath Sht ShtNum UsdRange Wbk)
- (setq FilePath (getfiled "Select Excel file to read :"
- (getvar "dwgprefix")
- "xlsx"
- 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)
- )
- )
- ) ;or 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)
- ExcData
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement