Message 1 of 17
Not applicable
01-06-2015
11:36 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
i try to extract a value of a excelfile
what i got:
(defun C:GetCells()
(vl-load-com)
(defun GetExcel (cellName / xlfilename Excel Excelfile xlSheet myRange cellValue sheetName)
(setq sheetName "Dossiergegevens")
(setq xlfilename "dossier.xlsx")
(setq Excel (vlax-get-or-create-object "Excel.Application"))
(vla-put-visible Excel :vlax-false)
(vlax-put-property Excel 'DisplayAlerts :vlax-False)
(setq Excelfile (vl-catch-all-apply 'vla-open (list (vlax-get-property Excel "WorkBooks") xlfileName)))
(setq xlSheet (vl-catch-all-apply 'vlax-get-property (list (vlax-get-property Excelfile "Sheets") "Item" sheetName)))
(vlax-invoke-method xlSheet "Activate")
;;;--- Make the selected worksheet active
(setq myRange (vlax-get-property (vlax-get-property xlSheet 'Cells) "Range" cellName))
(setq cellValue(vlax-variant-value (vlax-get-property myRange 'Value2)))
(vl-catch-all-apply 'vlax-invoke-method (list Excel 'QUIT))
(vlax-release-object Excel)
(if (not (vlax-object-released-p myRange))(progn(vlax-release-object myRange)(setq myRange nil)))
(if (not (vlax-object-released-p xlSheet))(progn(vlax-release-object xlSheet)(setq xlSheet nil)))
(if (not (vlax-object-released-p Excelfile))(progn(vlax-release-object Excelfile)(setq Excelfile nil)))
(if (not (vlax-object-released-p Excel))(progn(vlax-release-object Excel)(setq Excel nil)))
(if(= 'safearray (type cellValue))
(progn
(setq tempCellValue(vlax-safearray->list cellValue))
(setq cellValue(list))
(if(= (length tempCellValue) 1)
(progn
(foreach a tempCellValue
(if(= (type a) 'LIST)
(progn
(foreach b a
(if(= (type b) 'LIST)
(setq cellValue(append cellValue (list (vlax-variant-value (car b)))))
(setq cellValue(append cellValue (list (vlax-variant-value b))))
)
)
)
(setq cellValue(append cellValue (list (vlax-variant-value a))))
)
)
)
(progn
(foreach a tempCellValue
(setq tmpList(list))
(foreach b a
(setq tmp(vlax-variant-value b))
(setq tmpList(append tmpList (list tmp)))
)
(setq cellValue(append cellValue tmpList))
)
)
)
)
)
cellValue
)
(while(/= "" (setq cellName (getstring "\nCell address to retrieve? [ Examples: B3 or B3:B15 ]:")))
(setq cellValue(GetExcel cellName))
(princ (strcat "\n The value of address " cellName " is: "))(princ cellValue)
)
(princ)
)but i keep getting a error
Command: GETCELLS
Cell address to retrieve? [ Examples: B3 or B3:B15 ]:b10
; error: bad argument type: VLA-OBJECT #<%catch-all-apply-error%>
try to change some stuff but nothing helped. any thoughts on this?
thanks!
Solved! Go to Solution.