;从当前激活的工作表读取一行中指定数量的单元格
(defun TBxl:ReadRow (app r c n / value lst)
(repeat n
(setq value (TBxl:GetCell app r c)
lst (append lst (list value))
c (1+ c)
)
)
lst
)
;在当前激活的工作表写入一行
(defun TBxl:WriteRow (app r c values / value)
(foreach value values
(TBxl:SetCell app r c value)
(setq c (1+ c))
)
)
;读取指定单元格的内容
(defun TBxl:GetCell (app r c)
(vlax-variant-value (msxl-get-value2 (TBxl:CELL app r c)))
)
;写入内容到指定单元格
(defun TBxl:SetCell (app r c value)
(msxl-put-value2 (TBxl:CELL app r c) value)
)
;返回指定单元格对象
(defun TBxl:CELL (app r c)
(vlax-variant-value
(msxl-get-item
(msxl-get-cells app)
(vlax-make-variant r)
(vlax-make-variant c)
)
)
)
;返回当前的第一次选中的区域的相关参数
(defun TBxl:GetSelection (app / Col tmp range r rn c cn)
(defun Col (x / n y z ch)
(setq n 26
x (1- x)
y (fix (/ x n))
z (- x (* y n))
ch (chr (+ 65 z))
)
(if (< 0 y)
(strcat (Col y) ch)
ch
)
)
(setq range (msxl-get-selection app)
tmp (msxl-get-rows range)
r (msxl-get-row tmp)
rn (msxl-get-count tmp)
tmp (msxl-get-columns range)
c (msxl-get-column tmp)
cn (msxl-get-count tmp)
tmp (strcat (Col c)
(itoa r)
":"
(Col (+ c cn -1))
(itoa (+ r rn -1))
)
range (msxl-get-range app tmp)
)
(msxl-select range)
(list range r c rn cn)
)
;;;;;1、读取单个单元格excel数据函数
(defun Ljx-read-excel-data1 (vv hor sh) ;;;vv为列数直接输入字母、hor为 第几行,直接输入数字,sh为工作表对象sheet
(vlax-variant-value (vlax-get-property (vlax-get-property sh 'Range (strcat vv (itoa hor))) 'Value2))
)
;;;;;2、读取单个单元格excel数据函数输出text格式
(defun Ljx-read-excel-text1 (vv hor sh ) ;;;vv为列数直接输入字母、hor为 第几行,直接输入数字,sh为工作表对象sheet
(vl-princ-to-string (vlax-variant-value (vlax-get-property (vlax-get-property sh 'Range (strcat vv (itoa hor))) 'Value2)))
)
;;;;;3、读取单元格数据,支持区域输入,sheet-工作表对象,rangeid-单元格地址如"A1"、"A2:B5"、"A1:A100"
(defun ljx-vlxls-get-range-value1 ( sheet rangeid / range value valuelist )
(setq range (vlax-get-property sheet 'Range rangeid))
(setq value (vlax-get-property range 'Value2))
(cond
((= (vlax-variant-type value) 8204);;;为数组时,即为区域;
(setq value (vlax-safearray->list(vlax-variant-value value))
valuelist (mapcar '(lambda (x) (mapcar 'vlax-variant-value x)) value)
)
)
( T;;;;为单个单元格;
(setq valuelist (vlax-variant-value value))
)
);;;;cond
valuelist
)