BIGAL告诉你的是在getcells中。lsp函数可以返回一个
单元格列表(不仅仅是单个单元格。
- (defun getCells (fileName sheetName cellName / xl workbook sheet range cellValue)
- (setq xl(vlax-get-or-create-object "Excel.Application"))
- (vla-put-visible xl :vlax-false)
- (vlax-put-property xl 'DisplayAlerts :vlax-false)
- (setq workbook (vl-catch-all-apply 'vla-open (list (vlax-get-property xl "WorkBooks") fileName)))
- (setq sheet (vl-catch-all-apply 'vlax-get-property (list (vlax-get-property workbook "Sheets") "Item" sheetName)))
- (vlax-invoke-method sheet "Activate")
- (setq range (vlax-get-property (vlax-get-property sheet 'Cells) "Range" cellName))
- (setq cellValue(vlax-variant-value (vlax-get-property range 'Value2)))
- (vl-catch-all-apply 'vlax-invoke-method (list workbook "Close"))
- (vl-catch-all-apply 'vlax-invoke-method (list xl "Quit"))
- (if (not (vlax-object-released-p range))(progn(vlax-release-object range)(setq range nil)))
- (if (not (vlax-object-released-p sheet))(progn(vlax-release-object sheet)(setq sheet nil)))
- (if (not (vlax-object-released-p workbook))(progn(vlax-release-object workbook)(setq workbook nil)))
- (if (not (vlax-object-released-p xl))(progn(vlax-release-object xl)(setq xl 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
- )
- (defun c:test ()
- (vl-load-com)
- (setq fname "c:\\users\\ymg\\documents\\testgetcell.xlsx"
- shname "sheet1"
- range "B10:G10"
- )
- (setq lst (getcells fname shname range))
- )
您将在列表中获得从B10到G10的所有值 |