再贴一个我用的函数,一般读取excel数据基本够用了啊:
取得exce表指定单元格数据:
- ;;;;;;Ljx-vlxls-get-range-value
- ;;;;;;取得单元格数据,支持区域输入
- ;;;;;;参数:sheet当前工作表,rangeid:区域id,如"A1","A1:F10", "A1:A100","A1:EE1"
- ;;;;;;示例:(Ljx-vlxls-get-range-value *sheet* "E5")输出:-25.10,
- ;;;;;; (Ljx-vlxls-get-range-value *sheet* "E5:F5"")输出:((-25.10 "张三"))
- ;;;;;; (Ljx-vlxls-get-range-value *sheet* "E5:E6"")输出:((-25.10)(26.85))
- ;;;;; (Ljx-vlxls-get-range-value *sheet* "E5:F6"")输出:((-25.10 "张三")(26.85 "李四")
- (defun Ljx-vlxls-get-range-value (sheet rangeid / range value value1 valuelist index_i)
- (setq range (msxl-get-range sheet rangeid))
- (setq value (MSXL-GET-VALUE2 range ))
- (cond
- ((=(vlax-variant-type value) 8204);;;为数组时,即为区域
- (progn
- (setq value (vlax-safearray->list(vlax-variant-value value)))
- (setq valuelist '()
- index_i 0
- )
- (repeat (length value)
- (setq value1 (nth index_i value))
- (setq valuelist (cons (mapcar
- '(lambda (x)(vlax-variant-value x))
- value1
- )
- valuelist
- )
- )
- (setq index_i (1+ index_i))
- );;;;repeat
- (setq valuelist (reverse valuelist))
- )
- )
- (T;;;;为单个单元格
- (setq valuelist (vlax-variant-value value))
- )
- );;;;cond
- valuelist
- );;;;defun
|