excel的读写问题
想通过程序对EXCEL进行简单的读写操作,但是之前没有这方面的知识,无从下手,请高手指教,给点思路或者这方面的样例,参考学习一下。 版块内大量的读写excel例子,随便找个看都可以。 mikewolf2k 发表于 2015-3-5 08:39 static/image/common/back.gif版块内大量的读写excel例子,随便找个看都可以。
找了一个,但是有问题,读取数字和一般字符都没问题,当我表格里有12:21:30这种格式时读出来是小数,这是为什么呢?
(defun readexcel ( xls / rtn xlapp xlcls xlcol xlrng xlrow xlsht xlwbk xlwbs i k lst2)
(if
(and
(setq xls (findfile xls))
(setq xlapp (vlax-get-or-create-object "excel.application"))
)
(progn
(setq rtn
(vl-catch-all-apply
'(lambda ( /lst row )
(setq xlwbs (vlax-get-propertyxlapp 'workbooks)
xlwbk (vlax-invoke-method xlwbs 'open xls)
xlsht (vlax-get-propertyxlapp 'activesheet)
xlrng (vlax-get-propertyxlsht 'usedrange)
xlcls (vlax-get-propertyxlrng 'cells)
xlrow (vlax-get-propertyxlrng 'rows)
xlcol (vlax-get-propertyxlrng 'columns)
)
(setq i 1)
(setq row (vlax-get-property xlrow 'count))
(repeat row
(setq k 1 lst nil)
(repeat 2
(setq lst
(cons
(vlax-variant-value
(vlax-get-property
(vlax-variant-value
(vlax-get-property xlcls 'item i k)
)
'value
)
)
lst
)
)
(setq k (1+ k))
)
(setq lst (reverse lst))
(if (/= nil (car lst))
(setq lst2 (append lst2 (list lst)))
)
(setq i (1+ i))
)
lst2
)
)
)
(if (= 'vla-object (type xlwbk))
(vl-catch-all-apply 'vlax-invoke-method (list xlwbk 'close :vlax-false))
)
(vl-catch-all-apply 'vlax-invoke-method (list xlapp 'quit))
(foreach obj (list xlcol xlrow xlcls xlrng xlsht xlwbk xlwbs xlapp)
(if (= 'vla-object (type obj))
(vlax-release-object obj)
)
)
(gc)
(if (vl-catch-all-error-p rtn)
(prompt (strcat "\nError: " (vl-catch-all-error-message rtn)))
rtn
)
)
(prompt "\nUnable to interface with Excel Application.")
)
)
自己解决了
学习一下 谢谢分享 谢谢分享精品!!
页:
[1]