vlisp操作Excel百万数据
本帖最后由 和尚777 于 2022-9-9 21:57 编辑vlisp操作Excel百万数据;以数组+字典 技术可以实现对数据的增删改查等;这些数据可以转换成lisp数据
;这样就可以用Excel成为你的数据库,速度还是很快的
附件中有测试文件
测试前需要先用Excel打开 hs777副本.xlsm
还附带了个vlisp批量操作Excel文件
此例是对A列去重,保留同一行的数据
(defun c:tt1(/ a e)
(vl-load-com)
(if(setq e(vlax-get-object "excel.Application"))
(tt4 e)
)
(if(setq a(vlax-get-object "ket.Application"))
(tt4 a)
)
)
; 2022-9-9 和尚777 QQ 1765102082
(defun tt4 (e / arr brr colm dic e i j k key range row sht v)
(setq time(hs-jsq))
(setq dic (vlax-get-or-create-object "scripting.dictionary"))
(setq sht(vlax-get-property e "ActiveSheet"))
(setq range(vlax-get-property sht "UsedRange"));用户已使用区域
(setq arr(vlax-variant-value (vlax-get-property range "value" nil)))
(setq row(vlax-safearray-get-u-bound arr 1))
(setq colm(vlax-safearray-get-u-bound arr 2))
(setq brr(ReDim-arr row colm))
(setq i 0 k 0)
(repeat row
(setq i (1+ i))(setq j 0)
(setq key(vlax-variant-value(vlax-safearray-get-element arr i 1)))
(if(= :vlax-false (vlax-invoke-method dic "exists" key))
(progn
(setq k(1+ k))
(vlax-invoke-method dic "add" key "1")
(repeat colm
(setq j(1+ j))
(setq v(vlax-variant-value
(vlax-safearray-get-element arr i j)))
(vlax-safearray-put-element brr k j v)
)
)
)
)
(vlax-put-property range "value2" brr)
(vlax-invoke-method dic "removeall")
(vlax-release-object dic)
(hs-jsq-end time)(princ)
)
(defun ReDim-arr(r c)
(vlax-make-safearray
vlax-vbVariant
(cons 1 (1+ r))(cons 1 (1+ c))
)
)
[*];批量操作excel文件
(defun c:tt2 (/ aw e p p1 path s w ws)
(setq e(vlax-get-object "excel.Application"))
(vlax-put-property e "DisplayAlerts" :vlax-False);关闭警告弹窗,如果程序运行中断自己想办法恢复哦
(setq ws(vlax-get-property e "workbooks"))
(setq aw(vlax-get-property e "activeworkbook"))
(setq path(vlax-get-property aw "path"))
(setq p(vlax-invoke
(vlax-create-object "scripting.filesystemobject" )
'getfolder path ))
(vlax-for x (vlax-get-property p "files")
(setq s(vlax-get-property x "name"))
(if(not(wcmatch s "*副本*"))
(progn
(setq w(vlax-invoke-method ws "open" x))
(setq p1(vlax-get-property w "name"));a1单元格写入文件名
(vlax-put-property
(vlax-get-property
(vlax-get-property
(vlax-get-property w "sheets" )
"item" 1
)
"range" "a1"
)
"value2" p1
)
(vlax-invoke-method w "close" :vlax-true)
)
)
)
(vlax-put-property e "DisplayAlerts" :vlax-true);恢复警告弹窗
)
學習了,感謝共享資料! 锋十七 发表于 2023-4-3 12:54
谢谢楼主的分享
学到了很多,也解决了我的难题
厉害 咱这小卡拉米完全看不懂 有没有人闲着蛋疼去用这个方法实现平衡二叉树和hashmap,不过怎么提供hashcode给hashmap呢? 非常好的程序,多谢分享! 感谢共享资料! 学习了,感谢共享资料! 本帖最后由 烟盒迷唇 于 2022-9-12 06:54 编辑
非常厉害了 厉害了~很有用 数组+字典, 是VBA的精华所在,被您搬到lisp来了。 感谢共享资料! 感谢分享,学习了