2007年7月26日 星期四
2007年7月24日 星期二
Alisp 簡介
LISP是 LISt Processing(表處理)的縮寫。LISP是最早和最重要的符號處理編程語言之一,它於1958年由美國的J. McCarthy提出,並於1960年發表了他的第一篇關於LISP的論文。之後,LISP很快受到人工智能工作者的歡迎,獲得廣泛應用,尤其是專家系統領域。
20世紀80年代,LISP語言及其應用迅速發展,如今大約有十多種LISP語言。1984年,推出的Common LISP包括了各種重要的LISP語言的優點,具有豐富的功能,成為LISP語言的事實上的標準語言。在PC機上使用的GCLISP是Common LISP的子集;在PC機上使用的XLISP也是Common LISP的子集,並擴展了面向對象的成分。
在AutoCAD 中的AutoLISP是Common LISP的一個子集。
Lisp語言具有以下幾個基本特點:
(1)、函數性
函數性語言的基本特點是用函數定義和函數調用構成程序。程序員用函數定義和函數調用組成的表達式來描述求解問題的方法,表達式的值就是問題的解。
用FORRAN、PASCAL或者C等傳統程序設計語言編寫的程序是按一定順序執行的命令序列,執行結果就是問題的解。用這些語言編程時,程序員要規定求解的順序,既要描述控制流。Lisp語言的編程不考慮程序執行順序的細節,是更加面向用戶的語言。它只確定函數之間的調用,把函數執行的細節交給lisp系統來解決,從而減輕了用戶編程的負擔。
(2)、遞歸性
遞歸函數是指:在函數的定義中調用了這個函數本身。所有的可計算函數已被證明都可以用遞歸函數的形式來定義。
由於lisp的主要數據結構是表,而且表是遞歸方法定義的,既表中的一個元素也可以定義為一個表。因此,程序員用lisp提供的自定義函數來定義用戶自己的函數時,可以採用遞歸函數的形式。自定義的遞歸函數能夠很方便地對遞歸定義的表進行操作。遞歸定義的方法使程序簡明、優美。
(3)、數據與程序的一致性
Lisp的一段程序是用戶的一個自定義函數,這個函數可以被其它函數調用,或者說,一段程序被其它程序調用。函數執行後的輸出數據成為這個函數的返回值。一個函數被其它函數調用,就是調用了這個函數的返回值。在lisp中,函數與這個函數的返回值是一致的。這一特點使得lisp的編程就是定義一個宏函數;也使得lisp語言的擴充 比較容易。可以根據應用領域的需要,使用lisp提供的基本函數擴充若乾麵向專門應用領域的宏函數。
(4)、自動進行存儲分配
用lisp語言編程時,程序員完全不必考慮存儲分配的問題。程序中定義的函數、數據和表等都能在程序運行時,由lisp自動提供。對不再需要的數據,lisp自動釋放其佔用的存儲區。
(5)、語法簡單
Lisp的語法極其簡單,對變量和數據不需要事先定義和說明類型。Lisp語言的基本語法是函數定義和函數調用。因此,lisp語言的程序 便於修改、調試和糾錯,可以邊試驗邊設計,通過不斷修改和增加用戶自定義函數來構成複雜的系統。
2、ALISP的變量沒有明確的類型。LISP變量的類型是在賦值時動態確定的,因而不需要像C或Pascal那樣要預先聲明變量,也不需要像BASIC那樣需要特殊的標識命名習慣和DIM語句。
3、ALISP不需要預先聲明變量或函數(大多數語言需要這樣做,其主要目的是檢查參數的類型以及確定結果的類型)。由於ALISP變量是動態確定類型,因而沒有必要對參數和結果作類型檢查。ALISP程序可以用LISP函數隨時確定變量的類型。
4、 與C/C++、BASIC、Pascal等語言不一樣,LISP沒有語句、關鍵詞以及運算符。它是函數定位語言,其所有運算都由函數調用完成。
2007年7月15日 星期日
[轉貼]:如何手動更新卡巴斯基病毒資料庫
[轉貼]:如何手動更新卡巴斯基病毒資料庫
下載病毒資料庫檔案連結位置
ftp://ftp.kaspersky.com/zips/av-i386-cumul.zip
ftp://ftp.kaspersky.com/zips/av-i386-daily.zip
----------------------------------------------
方法一:
1.開啟卡巴斯基主程式,進入「服務」>「設定」>「防護」,關閉「啟用自我防護」。
2.點選此連結 ftp://ftp.kaspersky.com/bases/av/avc/i386/ ,
將此連結目錄下的所有檔案複製,到第3步驟的資料夾。
3.再來請開啟以下路徑,放置病毒資料庫的資料夾,將第2步驟所複製的檔案,
全部覆蓋貼上至此[Bases]資料夾中。
C:\Documents and Settings\All Users\Application Data\Kaspersky Lab\AVP6\Bases
4.將工作列右小角卡巴斯基圖示,按右鍵點離開,再從程式集裡,重新點開啟動卡巴斯基主程式。
5.進入「服務」>「設定」>「防護」,開啟「啟用自我防護」,即可。
1.開啟卡巴斯基主程式,進入「服務」>「設定」>「防護」,關閉「啟用自我防護」。
2.點選下面連結,下載av-i386-cumul.zip和av-i386-daily.zip這兩個檔案,
解壓縮到第3步驟的資料夾裡
av-i386-cumul.zip:這是包含到上禮拜天為止的更新資料庫(從最早以前到上禮拜天)
av-i386-daily.zip:這是最近的一個禮拜的更新資料庫(從上禮拜天算起到今天)
然後請依照新舊順序解壓縮到同一個資料夾,舊的先,新的後,
解壓縮覆蓋貼上至此[Bases]資料夾中。
C:\Documents and Settings\All Users\Application Data\Kaspersky Lab\AVP6\Bases
5.進入「服務」>「設定」>「防護」,開啟「啟用自我防護」,即可。
2007年7月13日 星期五
LISP 圖塊中心點連線
(prompt "\n **<日期:2007-07-14.TSK001>**")
(prompt "\n **<用途:圖塊中心點連線>**")
(command "undo" "be")
;;;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(PRINT "選取連線圖塊...")
(SETQ S1 (SSGET (LIST (CONS 2 "12")) )) ;;圖塊名稱請自行命名設定
(SETQ I 0)
(setq PT_S1 nil)
(REPEAT (SSLENGTH S1)
(SETQ EN (SSNAME S1 I))
(SETQ VLA_EN (vlax-ename->vla-object EN))
(SETQ PT_S1 (append PT_S1 (LIST (vlax-get VLA_EN 'insertionpoint) )))
(SETQ I (1+ I))
)
;;;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(PRINT "選取連線基準圖塊...")
(SETQ S2 (SSGET (LIST (CONS 2 "12")) )) ;;圖塊名稱請自行命名設定
(SETQ I 0)
(setq PT_S2 nil)
(REPEAT (SSLENGTH S2)
(SETQ EN (SSNAME S2 I))
(SETQ VLA_EN (vlax-ename->vla-object EN))
(SETQ PT_S2 (append PT_S2 (LIST (vlax-get VLA_EN 'insertionpoint) )))
(SETQ I (1+ I))
)
(SETQ PT_S1 (SORT_TYPE8_PT_LIST PT_S1)) ;E配A
(SETQ PT_S2 (SORT_TYPE8_PT_LIST PT_S2))
(REPEAT (1- (length PT_S2))
(SETQ PT_S2-X (NTH E PT_S2)
PT_S2-Y (NTH (1+ E) PT_S2)
) ;_ 結束SETQ
(COMMAND "_LINE" PT_S2-X PT_S2-Y "")
(SETQ E (1+ E))
)
(REPEAT (LENGTH PT_S2)
(SETQ PT_XT (NTH I PT_S2))
(SETQ PT_X PT_XT)
(SETQ PT_XL (LAST PT_S2))
(SETQ PT_XL (NTH (1+ I) PT_S2))
)
(SETQ Q 0) ;while關鍵
(WHILE Q
(SETQ PT_Y (CAR PT_S1))
(COND
((= PT_S1 NIL) ;;判斷串列是否為空
(SETQ Q NIL)
)
((EQUAL PT_XT PT_Y) ;;判斷座標是否相同
(SETQ Q 0)
(SETQ PT_S1 (cdr PT_S1))
)
((EQUAL PT_XL PT_Y)
(SETQ PT_S1 (cdr PT_S1))
(SETQ Q NIL)
)
(T
(COMMAND "_LINE" PT_X PT_Y "")
(SETQ PT_X PT_Y)
(SETQ Q 0)
(SETQ PT_S1 (cdr PT_S1))
)
)
)
(SETQ I (1+ I))
)
;;;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(command "undo" "e")
(prin1))
(defun sort-x-min-li (lst)
(vl-sort lst '(lambda (x y) (< (car x)(car y) ) ))
) ;X左->右
(defun sort-x-max-li (lst)
(vl-sort lst '(lambda (x y) (> (car x)(car y) ) ))
) ;X右->左
(defun sort-y-min-li (lst)
(vl-sort lst '(lambda (x y) (< (cadr x)(cadr y) ) ))
) ;Y下->上
(defun sort-y-max-li (lst)
(vl-sort lst '(lambda (x y) (> (cadr x)(cadr y) ) ))
) ;Y上->下
(DEFUN SORT_TYPE8_PT_LIST ( lst / )
(princ "\n 排序方式:")
(princ "\n <Y方向>")
(princ "\n (A)左->右&上->下_(B)左->右&下->上_(C)右->左&上->下_(D)右->左&下->上")
(princ "\n <X方向>")
(princ "\n (E)上->下&左->右_(F)上->下&右->左_(G)下->上&左->右_(H)下->上&右->左")
(princ ".....<<")(princ "預設為A") (princ ">>:")
(initget "a b c d e f g h")
(setq sf1 (getkword))
(if (= sf1 nil)(setq sf1 A))
((= sf1 "a")(progn
(setq lstnew (sort-y-max-li lst))
(setq lstnew2 (sort-x-min-li lstnew))
)) ;;_(A)左->右&上->下
(setq lstnew (sort-y-min-li lst))
(setq lstnew2 (sort-x-min-li lstnew))
)) ;;_(B)左->右&下->上
(setq lstnew (sort-y-max-li lst))
(setq lstnew2 (sort-x-max-li lstnew))
)) ;;_(C)右->左&上->下
(setq lstnew (sort-y-min-li lst))
(setq lstnew2 (sort-x-max-li lstnew))
)) ;;_(D)右->左&下->上
(setq lstnew (sort-x-min-li lst))
(setq lstnew2 (sort-y-max-li lstnew))
)) ;;_(E)上->下&左->右
(setq lstnew (sort-x-max-li lst))
(setq lstnew2 (sort-y-max-li lstnew))
)) ;;_(F)上->下&右->左
(setq lstnew (sort-x-min-li lst))
(setq lstnew2 (sort-y-min-li lstnew))
)) ;;_(G)下->上&左->右
(setq lstnew (sort-x-max-li lst))
(setq lstnew2 (sort-y-min-li lstnew))
)) ;;_(H)下->上&右->左
)
)
(prompt "\n **<命令:TSK001>**")
2007年7月7日 星期六
自由車手一天要消耗多少體能?
將選集物件做連接
(DEFUN C:JTHWA392 ( / enh ent i p ss st)
(prompt "\n**<日期:2007-07-08,[JTHWA392>**")
(prompt "\n**<用途:將選集物件做連接.1>**")
;;;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(PRINT "BY JTHWA")
(PRINT "FOR AutoCAD 2006")
(SETQ ST (SSGET)) ;建立選集
(SETQ ENH (SSNAME ST 0)) ;線頭
(SETQ SS (SSDEL ENH ST )) ;由選集刪除線頭物件
(SETQ I 0)
(WHILE (> (SSLENGTH SS) 0) ;選集大於0,成立
(SETQ P 0)
(REPEAT (SSLENGTH SS)
(SETQ ENT (SSNAME SS P)) ;線尾
(vl-cmdf ".JOIN" ENH ENT "") ;結合線頭線尾
(IF (OR
(/= ENT NIL) ;對象不可為 NIL
(NOT (vlax-erased-p ENT)) ;對象是否被刪除
)
(SETQ P (1+ P))
(SETQ P (1+ P) SS (SSDEL ENT SS))
)
)
(SETQ ENH (SSNAME SS 0)) ;取出選集0物件
(SETQ SS (SSDEL ENH SS )) ;由選集刪除線頭物件
)
)
;;;*********************************
(prin1))
[轉貼]:KozMos VLXLS Project
KozMos VLXLS Project
Copyright(C) 1994-2007 by KozMos Inc.
Permission to use, copy, modify, and distribute this software for any purpose and without fee is hereby granted, provided that the above copyright notice appears in all copies and that both that copyright notice and the limited warranty and restricted rights notice below appear in all supporting documentation.
KOZMOS PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS. KOZMOS SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. KOZMOS INC. DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE UNINTERRUPTED OR ERROR FREE.
You can directly save this HTML file or download the source LSP file at download center.
Public Function | |||
Name | (vlxls-variant->list VariantValue) | ||
Usage | Convert a variant into normal Visual LISP LIST data, nested Variant and safearray will also be converted. | ||
Input | VARIANT | Input Variant | |
RetVal | True | LIST | Valid Visual LISP variable value |
Fail | STR | "" | |
(Defun vlxls-variant->list (VarX / Run Item Rtn) (setq Run T) (while Run (cond ((= (type VarX) 'SAFEARRAY) (setq VarX (vlax-safearray->list VarX)) ) ((= (type VarX) 'VARIANT) (if (member (vlax-variant-type VarX) (list 5 4 3 2)) (setq VarX (vlax-variant-change-type Varx vlax-vbString)) ) (setq VarX (vlax-variant-value VarX)) ) (t (setq Run nil)) ) ) (cond ((= (type VarX) 'LIST) (foreach Item VarX (setq Item (vlxls-variant->list Item) Rtn (append Rtn (list Item)) ) ) ) ((= VarX nil) (setq Rtn "")) (t (setq Rtn VarX)) ) Rtn ) | |||
Examples: NONE |
Color Transfer Function | |||
Name | (vlxls-color-eci->truecolor ExcelColorIndexNumber) | ||
Usage | Convert Excel ColorIndex number into most matched AutoCAD2004+ truecolor number (stored by DXF420). | ||
Input | INT | Excel ColorIndex integer (0 to 56) | |
RetVal | True | INT | Valid AutoCAD 2004+ truecolor number |
Fail | INT | 16711935 for None | |
(Defun vlxls-color-ECI->truecolor (Color / Rtn) (if (setq Rtn (cdr (assoc Color *xls-color*))) (setq Rtn (nth 1 Rtn)) ) (if (null Rtn) (setq Rtn 16711935) ) Rtn ) | |||
Examples: (vlxls-color-eci->truecolor 0) è16711935 (vlxls-color-eci->truecolor 1)è 0 (vlxls-color-eci->truecolor 12)è 8355584 (vlxls-color-eci->truecolor 120) è16711935 |
Color Transfer Function | |||
Name | (vlxls-color-eci->aci ExcelColorIndexNumber) | ||
Usage | Convert Excel ColorIndex number into most matched AutoCAD ACI Integer number. | ||
Input | INT | Excel ColorIndex integer (0 to 56) | |
RetVal | True | INT | Valid AutoCAD ACI Integer number (0 to 256) |
Fail | INT | 256 for BYLAYER | |
(Defun vlxls-color-eci->aci (Color / Rtn) (if (null (setq Rtn (cdr (assoc Color *xls-color*)))) (setq Rtn 256) (setq Rtn (nth 0 Rtn)) ) Rtn ) | |||
Examples: (vlxls-color-eci->aci 0) è256 (vlxls-color-eci->aci 1)è 18 (vlxls-color-eci->aci 12)è 56 (vlxls-color-eci->aci 120) è256 |
Color Transfer Function | |||
Name | (vlxls-color-aci->eci AutoCADColorIndexNumber) | ||
Usage | Convert AutoCAD ColorIndex number into Excel ColorIndex . | ||
Input | INT | AutoCAD ColorIndex integer (0 to 256) | |
RetVal | True | INT | Valid Excel ColorIndex number (from 1 to 56) |
Fail | INT | 0 for NONE | |
(Defun vlxls-color-aci->eci (Color / Item Rtn) (foreach Item *xls-color* (if (= (nth 1 Item) Color) (setq Rtn (car Item)) ) ) (if (null Rtn) (setq Rtn 0) ) Rtn ) | |||
Examples: (vlxls-color-aci->eci 0) è0 (vlxls-color-aci->eci 1)è 3 (vlxls-color-aci->eci 12)è 0 (vlxls-color-aci->eci 120) è0 |
Color Transfer Function | |||
Name | (vlxls-color-aci->truecolor AutoCADColorIndexNumber) | ||
Usage | Convert AutoCAD ColorIndex number into most matched AutoCAD2004+ true color number (using Excel ColorIndex as intermediary, provided for use in AutoCAD2002. In AutoCAD2004+, this can be done directly by AutoCAD. | ||
Input | INT | AutoCAD ColorIndex integer (0 to 256) | |
RetVal | True | INT | Valid AutoCAD2004+ truecolor number |
Fail | INT | 16711935 for None | |
(Defun vlxls-color-aci->truecolor (aci) (vlxls-color-eci->truecolor (vlxls-color-aci->eci aci)) ) | |||
Examples: (vlxls-color-aci-> truecolor 0) è 16711935 (vlxls-color-aci->truecolor 1)è 16711680 (vlxls-color-aci-> truecolor 12)è 16711935 (vlxls-color-aci-> truecolor 120) è 16711935 |
Excel Application Session Progress Function | |||
Name | (vlxls-app-init) | ||
Usage | Import Microsoft Excel Type Library, set prefix of "msxl-" for all of the :methods-prefix; :properties-prefix & :constants-prefix. This function can detect Excel's installation path automatically from Windows registry so that it can run smoothly on any language platform of Windows and Office. | ||
Input | NONE | No Arguments | |
RetVal | True | BOOLEAN | msxl-xl24HourClock |
Fail | BOOLEAN | NIL | |
(Defun vlxls-app-Init (/ OSVar GGG Olb8 Olb9 Olb10 TLB Out msg msg1 msg2) (if *Chinese* (setq msg "\n 初始化微软Excel " msg1 "\042初始化Excel错误\042" msg2 (strcat "\042 警告" "\n ====" "\n 无法在您的计算机上检测到微软Excel软件" "\n 如果您确认已经安装Excel, 请发送电子邮" "\n 件到kozmosovia@hotmail.com获取更多的解决方案\042" ) ) (setq msg "\n Initializing Microsoft Excel " msg1 "\042Initialization Error\042" msg2 (strcat "\042 WARNING" "\n =======" "\n Can NOT detect Excel97/200X/XP in your computer" "\n If you already have Excel installed, please email" "\n us to get more solution via kozmosovia@hotmail.com\042") ) ) (if (null msxl-xl24HourClock) (progn (if (and (setq GGG (vl-registry-read "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\Excel.EXE" "Path" ) ) (setq GGG (strcase (strcat GGG "Excel.EXE"))) ) (progn (foreach OSVar (list "SYSTEMROOT" "WINDIR" "WINBOOTDIR" "SYSTEMDRIVE" "USERNAME" "COMPUTERNAME" "HOMEDRIVE" "HOMEPATH" "PROGRAMFILES" ) (if (vl-string-search (strcat "%" OSVar "%") GGG) (setq GGG (vl-string-subst (strcase (getenv OSVar)) (strcat "%" OSVar "%") GGG ) ) ) ) (setq Olb8 (findfile (vl-string-subst "EXCEL8.OLB" "EXCEL.EXE" GGG)) Olb9 (findfile (vl-string-subst "EXCEL9.OLB" "EXCEL.EXE" GGG)) Olb10 (findfile (vl-string-subst "EXCEL10.OLB" "EXCEL.EXE" GGG)) ) (cond ((= (vl-filename-base (vl-filename-directory GGG)) "OFFICE11" ) (setq TLB GGG Out "2003" ) ) ((= (vl-filename-base (vl-filename-directory GGG)) "OFFICE10" ) (setq TLB GGG Out "XP" ) ) (Olb9 (setq TLB Olb9 Out "2000" ) ) (Olb8 (setq TLB Olb8 Out "97" ) ) (t (setq Out "Version Unknown")) ) (if TLB (progn (princ (strcat MSG Out "...")) (vlax-import-type-library :tlb-filename TLB :methods-prefix "msxl-" :properties-prefix "msxl-" :constants-prefix "msxl-" ) ) ) ) (progn (if vldcl-msgbox (vldcl-msgbox "x" msg1 msg2) (alert (read msg2)) ) (exit) ) ) ) ) msxl-xl24HourClock ) | |||
Examples: (vlxls-app-init)è 33 |
Excel Application Session Progress Function | |||
Name | (vlxls-app-new ShowExcelFlag) | ||
Usage | Open a new Excel session and start a new workbook. | ||
Input | BOOLEAN | T for display, nil for hide | |
RetVal | True | VLOBJ | Excel Session vla-object |
Fail | BOOLEAN | NIL | |
(Defun vlxls-app-New (UnHide / Rtn) (if (vlxls-app-init) (progn (if *Chinese* (princ "\n 新建微软Excel工作表...") (princ "\n Creating new Excel Spreadsheet file...") ) (if (setq Rtn (vlax-get-or-create-object "Excel.Application")) (progn (vlax-invoke-method (vlax-get-property Rtn 'WorkBooks) 'Add ) (if UnHide (vla-put-visible Rtn 1) (vla-put-visible Rtn 0) ) ) ) ) ) Rtn ) | |||
Examples: (setq *xlapp* (vlxls-app-new T)) è #<VLA-OBJECT _Application 001db27c> |
Excel Application Session Progress Function | |||
Name | (vlxls-app-open XLSfilename ShowExcelFlag) | ||
Usage | Open a new Excel session to start existing XLS file. | ||
Input | STR | XLS file name with full path, ".XLS" not needed. | |
BOOLEAN | T for display, nil for hide | ||
RetVal | True | VLOBJ | Excel Session vla-object |
Fail | BOOLEAN | NIL | |
(Defun vlxls-app-open (XLSFile UnHide / ExcelApp WorkSheet Sheets ActiveSheet Rtn) (setq XLSFile (strcase XLSFile)) (if (null (wcmatch XLSFile "*.XLS")) (setq XLSFile (strcat XLSFile ".XLS")) ) (if (and (findfile XLSFile) (setq Rtn (vlax-get-or-create-object "Excel.Application")) ) (progn (vlax-invoke-method (vlax-get-property Rtn 'WorkBooks) 'Open XLSFile ) (if UnHide (vla-put-visible Rtn 1) (vla-put-visible Rtn 0) ) ) ) Rtn ) | |||
Examples: (setq *xlapp* (vlxls-app-open "C:/test.XLS" T)) è #<VLA-OBJECT _Application 001efd2c> |
Excel Application Session Progress Function | |||
Name | (vlxls-app-save ExcelSessionVLA-OBJECT) | ||
Usage | Perform save operation in Excel. | ||
Input | VLOBJ | Excel session vla-object | |
RetVal | True | BOOLEAN | T |
Fail | BOOLEAN | NIL | |
(Defun vlxls-app-save (xlapp) (equal (vlax-invoke-method (vlax-get-property Xlapp "ActiveWorkbook") "Save" ) :vlax-true ) ) | |||
Examples: (vlxls-app-save *xlapp*) è T |
Excel Application Session Progress Function | |||
Name | (vlxls-app-saveas ExcelSessionVLA-OBJECT SavedFileName) | ||
Usage | Perform saveas operation in Excel. | ||
Input | VLOBJ | Excel session vla-object | |
STR | Saved XLS file name with full path NIL for a temporary "XLS.XLS" file in current drawing path. | ||
RetVal | True | STRING | XLS file name with full path |
Fail | BOOLEAN | NIL | |
(Defun vlxls-app-saveas (xlapp Filename / Rtn) (if (null filename) (setq filename (strcat (getvar "dwgprefix") "XLS.XLS")) ) (if (null (wcmatch (setq filename (strcase Filename)) "*`.XLS")) (setq filename (strcat filename ".XLS")) ) (if (findfile Filename) (vl-file-delete (findfile Filename)) ) (vlax-invoke-method (vlax-get-property Xlapp "ActiveWorkbook") "SaveAs" Filename msxl-xlNormal "" "" :vlax-False :vlax-False nil ) (findfile Filename) ) | |||
Examples: (vlxls-app-saveas *xlapp* nil) è "C:/Temp-Folder/XLS.XLS" (vlxls-app-saveas *xlapp* "C:/Temp-Folder/XLS.XLS") è "C:/Temp-Folder/XLS.XLS" (vlxls-app-saveas *xlapp* nil) è NIL |
Excel Application Session Progress Function | |||
Name | (vlxls-app-quit ExcelSessionVLA-OBJECT SavedFlag) | ||
Usage | Quit active workbook of Excel session and release Excel application. | ||
Input | VLOBJ | Excel session vla-object | |
BOOLEAN | Save Excel active workwook flag, T for save, NIL for unsave | ||
RetVal | True | BOOLEAN | NIL |
Fail | BOOLEAN | NIL | |
(Defun vlxls-app-quit (ExlObj SaveYN) (if SaveYN (vlax-invoke-method (vlax-get-property ExlObj "ActiveWorkbook") 'Close ) (vlax-invoke-method (vlax-get-property ExlObj "ActiveWorkbook") 'Close :vlax-False ) ) (vlax-invoke-method ExlObj 'QUIT) (vlax-release-object ExlObj) (setq ExlObj nil) (gc) ) | |||
Examples: (vlxls-app-quit *xlapp* nil) è nil |
Excel Application Session Progress Function | |||
Name | (vlxls-app-kill) | ||
Usage | Close all active Excel workbooks. | ||
Input | NONE | No Arguments | |
RetVal | True | BOOLEAN | NIL |
Fail | BOOLEAN | NIL | |
(Defun vlxls-app-kill (SaveYN / ExlObj) (while (setq ExlObj (vlax-get-object "Excel.Application")) (vlxls-app-quit ExlObj SaveYN) ) ) | |||
Examples: (vlxls-app-kill T) è nil |
Excel Application Session Progress Function | |||
Name | (vlxls-app-autofit ExcelSessionVLA-OBJECT) | ||
Usage | Autofit the column width of all Excel session used ranges. | ||
Input | VLOBJ | Excel session vla-object | |
RetVal | True | Variant | T |
Fail | BOOLEAN | NIL | |
(Defun vlxls-app-autofit (xlapp / sh act Rtn) (setq act (vlxls-Sheet-Get-Active xlapp)) (foreach sh (append (vl-remove act (vlxls-sheet-get-all Xlapp)) (list act) ) (setq Rtn (variant-value (msxl-autofit (msxl-get-columns (msxl-get-Cells (vlxls-sheet-get-usedrange xlapp sh) ) ) ) ) ) ) (equal Rtn :vlax-true) ) | |||
Examples: (vlxls-app-autofit *xlapp*) è T (vlxls-app-autofit *xlapp*) è NIL |
Excel Sheet Progress Function | |||
Name | (vlxls-sheet-get-all ExcelSessionVLA-OBJECT) | ||
Usage | Get name list of all sheets. | ||
Input | VLOBJ | Excel session vla-object | |
RetVal | True | LIST | List contain all sheets' name |
Fail | BOOLEAN | NIL | |
(Defun vlxls-sheet-get-all (xlapp / SH Rtn) (vlax-for SH (vlax-get-property Xlapp "sheets") (setq Rtn (cons (vlax-get-property sh "Name") Rtn)) ) (reverse Rtn) ) | |||
Examples: (vlxls-sheet-get-all *xlapp*) è ("Sheet1" "Sheet2" "Sheet3") |
Excel Sheet Progress Function | |||
Name | (vlxls-sheet-get-active ExcelSessionVLA-OBJECT) | ||
Usage | Get active sheet name. | ||
Input | VLOBJ | Excel session vla-object | |
RetVal | True | STRING | Active sheet's name string |
Fail | BOOLEAN | NIL | |
(Defun vlxls-Sheet-Get-Active (xlapp) (vlax-get-property (msxl-get-ActiveSheet Xlapp) 'name) ) | |||
Examples: (vlxls-sheet-get-active *xlapp*) è "Sheet2" |
Excel Sheet Progress Function | |||
Name | (vlxls-sheet-delete ExcelSessionVLA-OBJECT DeleteSheetName) | ||
Usage | Delete certain sheet by name. | ||
Input | VLOBJ | Excel session vla-object | |
| STRING | Sheet name to delete | |
RetVal | True | BOOLEAN | T |
Fail | BOOLEAN | NIL | |
(Defun vlxls-sheet-delete (xlapp Name / sh Rtn) (setq Rtn (vlxls-sheet-get-all Xlapp)) (vlax-for sh (vlax-get-property Xlapp "sheets") (if (= (vlax-get-property sh "Name") Name) (vlax-invoke-method sh "Delete") ) ) (not (equal Rtn (vlxls-sheet-get-all Xlapp))) ) | |||
Examples: (vlxls-sheet-delete *xlapp* "Sheet1") è T (vlxls-sheet-delete *xlapp* "UnExistingSheet") è NIL |
Excel Sheet Progress Function | |||
Name | (vlxls-sheet-rename NewSheetName OldSheetName ExcelSessionVLA-OBJECT) | ||
Usage | Rename certain sheet by name. | ||
Input | STRING | New sheet name string | |
STRING | Old sheet name string | ||
VLOBJ | Excel session vla-object | ||
RetVal | True | BOOLEAN | T |
Fail | BOOLEAN | NIL | |
(Defun vlxls-sheet-rename (New Old Xlapp / sh Rtn) (if (null old) (setq old (msxl-get-name (msxl-get-activesheet Xlapp))) ) (if (member New (vlxls-sheet-get-all Xlapp)) (setq Rtn nil) (progn (vlax-for sh (vlax-get-property Xlapp "sheets") (if (= (msxl-get-name sh) Old) (msxl-put-name sh New) ) ) (setq Rtn (equal New (vlax-get-property (msxl-get-ActiveSheet Xlapp) 'name) ) ) ) ) Rtn ) | |||
Examples: (vlxls-sheet-rename "New" "Sheet1" *xlapp*) è T (vlxls-sheet-rename "New" NIL *xlapp*) è T (vlxls-sheet-rename "Sheet3" NIL *xlapp*) è NIL (vlxls-sheet-rename "Sheet2" "Sheet1" *xlapp*) è NIL (vlxls-sheet-rename "Sheet2" "UnExistSheet" *xlapp*) è NIL |
Excel Sheet Progress Function | |||
Name | (vlxls-sheet-add ExcelSessionVLA-OBJECT NewSheetName) | ||
Usage | New sheet name. If sheet name exist, return NIL | ||
Input | VLOBJ | Excel session vla-object | |
STRING | New added sheet name string | ||
RetVal | True | BOOLEAN | T |
Fail | BOOLEAN | NIL | |
(Defun vlxls-sheet-add (xlapp Name / Rtn) (if (member name (vlxls-sheet-get-all xlapp)) (setq Rtn nil) (progn (vlax-put-property (vlax-invoke-method (vlax-get-property Xlapp "sheets") "Add" ) "name" Name ) (setq Rtn (equal (vlxls-sheet-get-active xlapp) name)) ) ) Rtn ) | |||
Examples: (vlxls-sheet-add *xlapp* "Sheet1") èT (vlxls-sheet-add *xlapp* NIL) èT (vlxls-sheet-add *xlapp* "NewSheet") è NIL |
Excel Sheet Progress Function | |||
Name | (vlxls-sheet-put-active ExcelSessionVLA-OBJECT ActiveSheetName) | ||
Usage | Put certain sheet as active sheet. If sheet name not exist, create automatically. | ||
Input | VLOBJ | Excel session vla-object | |
STRING | New active sheet name string | ||
RetVal | True | BOOLEAN | T |
Fail | BOOLEAN | NIL | |
(Defun vlxls-sheet-put-active (xlapp Name / sh) (if (null (vlxls-sheet-add xlapp name)) (vlax-for sh (vlax-get-property Xlapp "sheets") (if (= (vlax-get-property sh "Name") Name) (vlax-invoke-method sh "Activate") ) ) ) (equal (vlxls-sheet-get-active xlapp) name) ) | |||
Examples: (vlxls-sheet-put-active *xlapp* "Sheet1") è T (vlxls-sheet-put-active *xlapp* "NewSheet") è T |
Excel Sheet Progress Function | |||
Name | (vlxls-sheet-get-usedrange ExcelSessionVLA-OBJECT SheetName) | ||
Usage | Get all used range of certain Excel sheet. If sheet name not exist, return NIL. | ||
Input | VLOBJ | Excel session vla-object | |
STRING | Excel sheet name string, NIL for current active sheet. | ||
RetVal | True | VLOBJ | |
Fail | BOOLEAN | NIL | |
(Defun vlxls-sheet-get-UsedRange (xlapp Name / sh Rtn) (if (null Name) (setq Name (vlax-get-property (msxl-get-ActiveSheet Xlapp) 'Name)) ) (vlax-for sh (vlax-get-property Xlapp "sheets") (if (= (vlax-get-property sh "Name") Name) (setq Rtn (vlax-get-property sh "UsedRange")) ) ) Rtn ) | |||
Examples: (vlxls-sheet-get-usedrange *xlapp* "Sheet1") è T (vlxls-sheet- get-usedrange *xlapp* "NewSheet") è T |
Excel Cell and Range Progress Function | |||
Name | (vlxls-cellid CellIDStringOrList) | ||
Usage | Divide complex Excel Cell ID into a two-string-item list, contain the Left-Upper and Right-Lower Cell ID. | ||
Input | STR/LIST | Complex Excel Cell ID string or simple Cell ID string/list. | |
RetVal | True | LIST | List of Left-Upper and Right-Lower Cell ID |
Fail | BOOLEAN | NIL | |
(Defun vlxls-cellid (id / xx id1 id2 Rtn) (if (= (type id) 'list) (setq id (vlxls-rangeid id)) ) (setq id (strcase id)) (if (null (setq xx (vl-string-search ":" id))) (setq Rtn (list id "")) (setq id1 (substr id 1 xx) id2 (substr id (+ xx 2)) id1 (vlxls-rangeid id1) id2 (vlxls-rangeid id2) Rtn (list (vlxls-rangeid (list (min (car id1) (car id2)) (min (cadr id1) (cadr id2)) ) ) (vlxls-rangeid (list (max (car id1) (car id2)) (max (cadr id1) (cadr id2)) ) ) ) ) ) Rtn ) | |||
Examples: (vlxls-cellid '(3 14)) è ("C14" "") (vlxls-cellid "D23") è ("D23" "") (vlxls-cellid "C12:F3") è ("C3" "F12") (vlxls-cellid "F15:G22") è ("F15" "G22") |
Excel Cell and Range Progress Function | |||
Name | (vlxls-rangeid CellIDStringOrList) | ||
Usage | VLXLS treats Excel Cell ID in two types: AutoCAD LIST and Excel simple Cell ID String. This function is used to convert Cell ID between the two types. | ||
Input | STR/LIST | The Cell ID list or string | |
RetVal | True | STR/LIST | Cell ID value in another VLXLS ID type |
Fail | BOOLEAN | NIL | |
(Defun vlxls-rangeid (id / str->list list->str xid->str Rtn) (Defun str->list (str / ii xk xv rr pos x y) (setq rr (strlen str)) (foreach ii '("0" "1" "2" "3" "4" "5" "6" "7" "8" "9") (if (setq pos (vl-string-search ii str)) (setq rr (min pos rr)) ) ) (setq x (substr str 1 rr) y (substr str (1+ rr)) ) (if (= (strlen x) 2) (setq xk (- (ascii (substr x 1 1)) 64) xv (- (ascii (substr x 2)) 64) ) (setq xk 0 xv (- (ascii x) 64) ) ) (list (+ (* xk 26) xv) (read y)) ) (Defun xid->str (IntNum / PosNum Nm-One) (setq Nm-One (1- IntNum) PosNum (/ Nm-One 26) ) (if (= PosNum 0) (chr (+ 65 (rem Nm-One 26))) (strcat (chr (+ 64 PosNum)) (chr (+ 65 (rem Nm-One 26)))) ) ) (Defun list->str (idr / x y) (setq x (car idr) y (cadr idr) x (xid->str x) y (itoa y) ) (strcat x y) ) (cond ((= (type id) 'str) (setq Rtn (str->list id))) ((= (type id) 'list) (setq Rtn (list->str id))) ) Rtn ) | |||
Examples: (vlxls-rangeid '(3 14)) è "C14" (vlxls-rangeid "D23") è (4 23) (vlxls-rangeid "DD23") è (108 23) |
Excel Cell and Range Progress Function | |||
Name | (vlxls-range-autofit RangeVLA_OBJECT) | ||
Usage | Autofit the column width of a certain range object. | ||
Input | VLOBJ | The | |
RetVal | True | BOOLEAN | T |
Fail | BOOLEAN | NIL | |
(Defun vlxls-range-autofit (range) (equal (vlax-variant-value (msxl-autofit (msxl-get-columns (msxl-get-Cells range)) ) ) :vlax-true ) ) | |||
Examples: (vlxls-range-autofit (msxl-get-range *xlapp* "C12:F15")) è T (vlxls-range-autofit RangeObject) è NIL |
Excel Cell and Range Progress Function | |||
Name | (vlxls-cell-put-active ExcelSessionVLA-OBJECT CellIDStringOrList) | ||
Usage | Select to certain Cell ID and activate it. | ||
Input | VLOBJ | The Excel Session vla-object | |
STR/LIST | The Cell ID list or string | ||
RetVal | True | VLOBJ | |
Fail | BOOLEAN | NIL | |
(Defun vlxls-cell-put-active (xl id / Rtn) (if (= (type id) 'list) (setq id (vlxls-rangeid id)) ) (msxl-activate (setq Rtn (msxl-get-range xl id))) Rtn ) | |||
Examples: (vlxls-cell-put-active *xlapp* "C12:F15") è #< (vlxls-cell-put-active *xlapp* "F12") è #< |
Excel Cell and Range Progress Function | |||
Name | (vlxls-cell-get-value ExcelSessionVLA-OBJECT CellIDStringOrList) | ||
Usage | Get value of certain Cell ID. | ||
Input | VLOBJ | The Excel Session vla-object | |
STR/LIST | The Cell ID list or string | ||
RetVal | True | STR/LIST | String for one cell, a 2 dimension list for multiple cells or merged cell |
Fail | BOOLEAN | NIL | |
(Defun vlxls-cell-get-value (xl id) (if (= (type id) 'list) (setq id (vlxls-rangeid id)) ) (vlxls-variant->list (msxl-get-value2 (msxl-get-range xl id)) ) ) | |||
Examples: (vlxls-cell-get-value *xlapp* "C12") è "g" (vlxls-cell-get-value *xlapp* "C12:C12") è "g" (vlxls-cell-get-value *xlapp* "C12:C15") è (("g") ("") ("") ("")) (vlxls-cell-get-value *xlapp* "C12:F12") è (("g" "ds" "" "")) (vlxls-cell-get-value *xlapp* "C12:F15") è (("g" "ds" "" "") ("" "" "g" "") ("" "" "" "") ("" "" "" "")) |
Excel Cell and Range Progress Function | |||
Name | (vlxls-cell-put-value ExcelSessionVLA-OBJECT CellIDStringOrList DataList) | ||
Usage | Pass a 1 dimension or a 2 dimension string list into Excel, started at certain Cell ID. | ||
Input | VLOBJ | The Excel Session vla-object | |
STR/LIST | The start Cell ID [Left-Upper] list or string | ||
STR/LIST | If this argument is a string, VLXLS will fill same string to all cells. Or the argument should be a 1 dimension list or a 2 dimension list to fill in Excel. If the data list can NOT match the given cell ID, VLXLS will only fill first cell, fill to other cells will be ignored. | ||
RetVal | True | VLOBJ | All |
Fail | BOOLEAN | NIL | |
(Defun vlxls-cell-put-value (xl id Data / vllist-explode idx xx yy ary Rtn) (Defun vllist-explode (lst) (cond ((not lst) nil) ((atom lst) (list lst)) ((append (vllist-explode (car lst)) (vllist-explode (cdr lst)) ) ) ) ) (if (null id) (setq id "A1") ) (if (= (type id) 'list) (setq id (vlxls-rangeid id)) ) (if (= (type (car Data)) 'LIST) (setq ARY (vlax-make-safearray vlax-vbstring (cons 0 (1- (length Data))) (cons 1 (length (car Data))) ) XX (1- (length (car Data))) YY (1- (length Data)) ) (setq ARY (vlax-make-safearray vlax-vbstring (cons 0 1) (cons 1 (length Data)) ) XX (1- (length Data)) YY 0 ) ) (if (= xx yy 0) (msxl-put-value2 (setq Rtn (msxl-get-range xl id)) (car (vllist-explode data)) ) (progn (setq id (vlxls-cellid-calc id xx yy)) (msxl-put-value2 (setq Rtn (msxl-get-range xl id)) (vlax-safearray-fill ary data) ) ) ) Rtn ) | |||
Examples: (vlxls-cell-put-value *xlapp* "C12" "xx") è #< (vlxls-cell-put-value *xlapp* "C12:F3" "xx") è #< (vlxls-cell-put-value *xlapp* "C12:D13" '(("zz" "xx")("xx" "zz"))) è #< |
Excel Cell and Range Progress Function | |||
Name | (vlxls-cellid-calc BaseCellId XOffset YOffset) | ||
Usage | Calculate a new Cell ID for given delta X and Y from base Cell ID. | ||
Input | STR/LIST | Base Cell ID string or list | |
INT | X offset integer of Cell ID | ||
INT | Y offset integer of Cell ID | ||
RetVal | True | STRING | An Excel Complex Cell ID format contain the base Cell ID and target Cell ID. |
Fail | BOOLEAN | NIL | |
(Defun vlxls-cellid-calc (id x y / idx) (setq id (car (vlxls-cellid id)) idx (vlxls-rangeid id) x (+ x (car idx)) x (if (< x 1) 1 x ) y (+ y (cadr idx)) y (if (< y 1) 1 y ) idx (vlxls-rangeid (list x y)) id (vlxls-cellid (strcat id ":" idx)) id (strcat (car id) ":" (cadr id)) ) id ) | |||
Examples: (vlxls-cellid-calc "C12" 2 20) è "C12:E32" (vlxls-cellid-calc '(2 23) 2 -120) è "B1:D23" |
Excel Cell and Range Progress Function | |||
Name | (vlxls-get-row-value ExcelSessionVLA-OBJECT StartCellIDStringOrList RowCellNumber) | ||
Usage | Get values of certain row. | ||
Input | VLOBJ | The Excel Session vla-object | |
STR/LIST | The Start Cell ID list or string | ||
INT | Number of cells in row to read. | ||
RetVal | True | LIST | A list contain cells' value in row |
Fail | BOOLEAN | NIL | |
(Defun vlxls-get-row-value (xl id len / vllist-explode Rtn) (Defun vllist-explode (lst) (cond ((not lst) nil) ((atom lst) (list lst)) ((append (vllist-explode (car lst)) (vllist-explode (cdr lst)) ) ) ) ) (if (> len 0) (setq id (vlxls-cellid-calc id (1- len) 0)) (setq id (vlxls-cellid-calc id (1+ len) 0)) ) (setq Rtn (vllist-explode (vlxls-cell-get-value xl id))) Rtn ) | |||
Examples: (vlxls-get-row-value *xlapp* "C12" 2) è ("zz" "xxx") (vlxls-get-row-value *xlapp* "C12" -20) è ("" "" "zz") |
Excel Cell and Range Progress Function | |||
Name | (vlxls-put-row-value ExcelSessionVLA-OBJECT StartCellIDStringOrList StringList) | ||
Usage | Put a string list into Excel row started by certain cell. | ||
Input | VLOBJ | The Excel Session vla-object | |
STR/LIST | The Start Cell ID list or string | ||
STR/LIST | A string to fill in one cell or a 1 dimension string list to fill in row cells. | ||
RetVal | True | VLOBJ | Filled |
Fail | BOOLEAN | NIL | |
(Defun vlxls-put-row-value (xl id data / Rtn) (if (= (type data) 'str) (setq data (list data)) ) (setq id (car (vlxls-cellid id)) id (vlxls-cellid-calc id (1- (length data)) 0) ) (vlxls-range-autofit (setq Rtn (vlxls-cell-put-value xl id (list data))) ) Rtn ) | |||
Examples: (vlxls-put-row-value *xlapp* "C12" "abc") è#< (vlxls-put-row-value *xlapp* '(12 3) "abc") è#< (vlxls-put-row-value *xlapp* "C12" '("zz" "xxx")) è#< (vlxls-put-row-value *xlapp* '(12 3) '("zz" "xxx")) è#< |
Excel Cell and Range Progress Function | |||
Name | (vlxls-get-column-value ExcelSessionVLA-OBJECT StartCellIDStringOrList ColumnCellNumber) | ||
Usage | Get values of certain column. | ||
Input | VLOBJ | The Excel Session vla-object | |
STR/LIST | The Start Cell ID list or string | ||
INT | Number of cells in column to read. | ||
RetVal | True | LIST | A list contain cells' value in column |
Fail | BOOLEAN | NIL | |
(Defun vlxls-get-column-value (xl id len / vllist-explode Rtn) (Defun vllist-explode (lst) (cond ((not lst) nil) ((atom lst) (list lst)) ((append (vllist-explode (car lst)) (vllist-explode (cdr lst)) ) ) ) ) (setq id (car (vlxls-cellid id))) (if (> len 0) (setq id (vlxls-cellid-calc id 0 (1- len))) (setq id (vlxls-cellid-calc id 0 (1+ len))) ) (setq Rtn (vllist-explode (vlxls-cell-get-value xl id))) Rtn ) | |||
Examples: (vlxls-get-column-value *xlapp* "C12" 2) è ("zz" "sdfsdf") (vlxls-get-column-value *xlapp* "C12" -20) è ("" "" "xxx" "xxx" "xxx" "xxx" "xxx" "xxx" "xxx" "xxx" "xxx" "zz") |
Excel Cell and Range Progress Function | |||
Name | (vlxls-put-column-value ExcelSessionVLA-OBJECT StartCellIDStringOrList StringList) | ||
Usage | Put a string list into Excel column started by certain cell. | ||
Input | VLOBJ | The Excel Session vla-object | |
STR/LIST | The Start Cell ID list or string | ||
STR/LIST | A string to fill in one cell or a 1 dimension string list to fill in column cells. | ||
RetVal | True | VLOBJ | Filled |
Fail | BOOLEAN | NIL | |
(Defun vlxls-put-column-value (xl id data / item Rtn) (if (= (type data) 'str) (setq data (list data)) ) (setq id (car (vlxls-cellid id)) id (vlxls-cellid-calc id 0 (1- (length data))) ) (foreach item data (setq Rtn (cons (list item) Rtn)) ) (vlxls-range-autofit (setq Rtn (vlxls-cell-put-value xl id (reverse Rtn))) ) Rtn ) | |||
Examples: (vlxls-put-column-value *xlapp* "C12" "abc") è#< (vlxls-put-column-value *xlapp* '(12 3) "abc") è#< (vlxls-put-column-value *xlapp* "C12" '("zz" "xxx")) è#< (vlxls-put-column-value *xlapp* '(12 3) '("zz" "xxx")) è#< |
Excel Cell and Range Progress Function | |||
Name | (vlxls-cell-get-aci ExcelSessionVLA-OBJECT CellIDStringOrList) | ||
Usage | Get the background color (In AutoCAD ColorIndex mode) of certain Excel cell, Multiple color will return 256. | ||
Input | VLOBJ | The Excel Session vla-object | |
STR/LIST | The Cell ID list or string | ||
RetVal | True | INT | Valid ACI Integer number (0 to 256) |
Fail | BOOLEAN | NIL | |
(Defun vlxls-cell-get-aci (xl id) (vlxls-color-eci->aci (vlax-variant-value (msxl-get-colorindex (msxl-get-interior (msxl-get-range xl id)) ) ) ) ) | |||
Examples: (vlxls-cell-get-aci *xlapp* "C12") è256 (vlxls-cell-get-aci *xlapp* '(12 3)) è15 |
Excel Cell and Range Progress Function | |||
Name | (vlxls-cell-put-aci ExcelSessionVLA-OBJECT CellIDStringOrList ACINumber) | ||
Usage | Put or clear the background color (In AutoCAD ColorIndex mode) of certain Excel cells. | ||
Input | VLOBJ | The Excel Session vla-object | |
STR/LIST | The Cell ID list or string | ||
INT | ACI Integer number, NIL for remove background color | ||
RetVal | True | VLOBJ | Modified |
Fail | BOOLEAN | NIL | |
(Defun vlxls-cell-put-aci (xl id aci / Rtn) (if (null aci) (msxl-put-colorindex (msxl-get-interior (setq Rtn (msxl-get-range xl id))) (vlax-make-variant -4142) ) (msxl-put-colorindex (msxl-get-interior (setq Rtn (msxl-get-range xl id))) (vlxls-color-aci->eci aci) ) ) Rtn ) | |||
Examples: (vlxls-cell-put-aci *xlapp* "C12" 6) è#< (vlxls-cell-put-aci *xlapp* "C12" nil) è#< |
Excel Cell and Range Progress Function | |||
Name | (vlxls-text-get-aci ExcelSessionVLA-OBJECT CellIDStringOrList) | ||
Usage | Get the text color (In AutoCAD ColorIndex mode) of certain Excel cells. | ||
Input | VLOBJ | The Excel Session vla-object | |
STR/LIST | The Cell ID list or string | ||
RetVal | True | INT | Valid ACI Integer number (0 to 256) |
Fail | BOOLEAN | NIL | |
(Defun vlxls-text-get-aci (xl id) (vlxls-color-eci->aci (vlax-variant-value (msxl-get-colorindex (msxl-get-font (msxl-get-range xl id)) ) ) ) Rtn ) | |||
Examples: (vlxls-text-get-aci *xlapp* "C12") è256 (vlxls-text-get-aci *xlapp* '(12 3)) è15 |
Excel Cell and Range Progress Function | |||
Name | (vlxls-text-put-aci ExcelSessionVLA-OBJECT CellIDStringOrList ACINumber) | ||
Usage | Put or clear the content color (In AutoCAD ColorIndex mode) of certain Excel cells. | ||
Input | VLOBJ | The Excel Session vla-object | |
STR/LIST | The Cell ID list or string | ||
INT | ACI Integer number, NIL for remove background color | ||
RetVal | True | VLOBJ | Modified |
Fail | BOOLEAN | NIL | |
(Defun vlxls-text-put-aci (xl id aci / Rtn) (if (null aci) (msxl-put-colorindex (msxl-get-font (setq Rtn (msxl-get-range xl id))) (vlax-make-variant -4105) ) (msxl-put-colorindex (msxl-get-font (setq Rtn (msxl-get-range xl id))) (vlxls-color-aci->eci aci) ) ) Rtn ) | |||
Examples: (vlxls-text-put-aci *xlapp* "C12" 6) è#< (vlxls-text-put-aci *xlapp* "C12" nil) è#< |
Excel Cell and Range Progress Function | |||
Name | (vlxls-text-get-prop ExcelSessionVLA-OBJECT CellIDStringOrList) | ||
Usage | Get the properties of content of certain Excel cells. Multiple cells will only record the Left-Upper cell. | ||
Input | VLOBJ | The Excel Session vla-object | |
STR/LIST | The Cell ID list or string | ||
RetVal | True | LIST | A dot-paired list contain text properties. Syntax is as following: ((0 . LeftUpperCellID)(7 . FontStyle)(40 . FontSize)(62 . TextACIColor)(72 . TextAlignment)(420 . TextTrueColor)) FontStyle will be recorded as Windows TTF font name displayed in Excel VLXLS only support horizontal for TextAlignment: 9=Left, 10=Center, 11=Right |
Fail | BOOLEAN | NIL | |
(Defun vlxls-text-get-prop (xl id / Cell Font DXF1 DXF7 DXF40 DXF72 DXF62 DXF420 Rtn) (setq id (car (vlxls-cellid id)) cell (msxl-get-range xl id) font (msxl-get-font cell) DXF7 (vlax-variant-value (msxl-get-name Font)) DXF40 (vlax-variant-value (msxl-get-size Font)) DXF72 (vlax-variant-value (msxl-get-HorizontalAlignment Cell) ) DXF72 (cond ((= DXF72 -4152) 11) ((= DXF72 -4108) 10) (t 9) ) DXF62 (vlxls-color-eci->aci (vlax-variant-value (msxl-get-colorIndex Font)) ) DXF420 (vlxls-color-eci->truecolor (vlax-variant-value (msxl-get-colorIndex Font)) ) Rtn (list (cons 0 (strcase id)) (cons 7 DXF7) (cons 40 DXF40) (cons 62 DXF62) (cons 72 DXF72) (cons 420 DXF420) ) ) Rtn ) | |||
Examples: (vlxls-text-get-prop *xlapp* "C12") è((0 . "C12") (7 . "Arial") (40 . 12.0) (62 . 256) (72 . 9) (420 . 16711935)) (vlxls-text-get-prop *xlapp* '(2 10)) è((0 . "B10") (7 . "Arial") (40 . 12.0) (62 . 256) (72 . 11) (420 . 16711935)) |
Excel Cell and Range Progress Function | |||
Name | (vlxls-cell-get-prop ExcelSessionVLA-OBJECT CellIDString) | ||
Usage | Get the properties of certain Excel cells. | ||
Input | VLOBJ | The Excel Session vla-object | |
STR | The Cell ID string | ||
RetVal | True | LIST | A dot-paired list contain cell properties. Syntax is as following: ((0 . CellIDString)(1 . CellValueList) (10 . LeftUpperLocation_of_LeftUpperCell) (41 . TotalColumnWidth) (42 . TotalRowHeight) (-1 . ReturnValue_of_vlxls-text-get-prop)) If only one cell, CellValueList can be a string, or it will be a 2 dimension list. LeftUpperLocation_of_LeftUpperCell is in Excel units and Cell "A1" will be original. TotalRowHeight and TotalColumnWidth are both in Excel units |
Fail | BOOLEAN | NIL | |
(Defun vlxls-cell-get-prop (xl id / range left top width height dxf10 Rtn) (if (vlxls-cell-merge-p xl id) (setq id (vlxls-cell-get-mergeid xl id)) ) (setq range (msxl-get-range xl id) left (vlax-variant-value (msxl-get-left Range)) top (vlax-variant-value (msxl-get-top Range)) width (vlax-variant-value (msxl-get-width Range)) height (vlax-variant-value (msxl-get-height Range)) dxf10 (list left top) Rtn (list (cons 0 (strcase id)) (cons 1 (vlxls-cell-get-value xl id)) (cons 10 dxf10) (cons 41 width) (cons 42 height) (cons -1 (vlxls-text-get-prop xl id)) ) ) Rtn ) | |||
Examples: (vlxls-cell-get-prop *xlapp* "C12:F14") è((0 . "C12:F14") (1 ("zz" "xxx" "xxx" "xxx") ("sdfsdf" "sdfsdf" "sdfsdf" "sdfsdf") ("sdfsdf" "sdfsdf" "sdfsdf" "sdfsdf")) (10 108.0 156.75) (41 . 156.0) (42 . 42.75) (-1 (0 . "C12") (7 . "Arial") (40 . 12.0) (62 . 256) (72 . 9) (420 . 16711935))) (vlxls-cell-get-prop *xlapp* "B8") è((0 . "B8") (1 . "sdg") (10 54.0 99.75) (41 . 54.0) (42 . 14.25) (-1 (0 . "B8") (7 . "Arial") (40 . 12.0) (62 . 256) (72 . 10) (420 . 16711935))) |
Excel Cell and Range Progress Function | |||
Name | (vlxls-cell-border ExcelSessionVLA-OBJECT CellIDString) | ||
Usage | Force to draw or hide 4 slim border to certain Excel cells. | ||
Input | VLOBJ | The Excel Session vla-object | |
STR/LIST | The Cell ID list or string | ||
BOOLEAN | Flag to draw border line or NOT, T for draw, NIL for disable | ||
RetVal | True | BOOLEAN | NIL |
Fail | BOOLEAN | NIL | |
(Defun vlxls-cell-border (xl id flg / bdr) (if flg (msxl-put-value (msxl-get-borders (msxl-get-range xl id) ) 1 ) (msxl-put-value (msxl-get-borders (msxl-get-range xl id) ) 'linestyle msxl-xlnone ) ) ) | |||
Examples: (vlxls-cell-border *xlapp* "C12:F14" T) èNIL (vlxls-cell-border *xlapp* "B8" NIL) èNIL |
Excel Cell and Range Progress Function | |||
Name | (vlxls-cell-merge ExcelSessionVLA-OBJECT CellIDString) | ||
Usage | Run cell merge in Excel. Only 1st un-empty value will be left in merged cell. | ||
Input | VLOBJ | The Excel Session vla-object | |
STR/LIST | The Cell ID list or string | ||
RetVal | True | VLOBJ | New merged cell range vla-object |
Fail | BOOLEAN | NIL | |
(Defun vlxls-cell-merge (xl id / vllist-explode Val Rtn) (Defun vllist-explode (lst) (cond ((not lst) nil) ((atom lst) (list lst)) ((append (vllist-explode (car lst)) (vllist-explode (cdr lst)) ) ) ) ) (setq val (vllist-explode (vlxls-cell-get-value xl id))) (while (vl-position "" val) (setq val (vl-remove "" val)) ) (setq val (car val) Rtn (msxl-get-range xl id) ) (msxl-clear Rtn) (msxl-merge Rtn nil) (msxl-put-value2 Rtn Val) (msxl-put-HorizontalAlignment Rtn -4108) Rtn ) | |||
Examples: (vlxls-cell-merge *xlapp* "C12:F14") è#< |
Excel Cell and Range Progress Function | |||
Name | (vlxls-cell-unmerge ExcelSessionVLA-OBJECT CellIDString) | ||
Usage | Run cell unmerge in Excel. merged value will be placed into the left upper cell, others will be empty. If given Cell ID is not a valid merged cell, return NIL | ||
Input | VLOBJ | The Excel Session vla-object | |
STR/LIST | The Cell ID list or string | ||
RetVal | True | VLOBJ | All unmerged cells range vla-object |
Fail | BOOLEAN | NIL | |
(Defun vlxls-cell-unmerge (xl id / Rtn) (if (vlxls-cell-merge-p xl id) (progn (vlax-invoke-method (msxl-get-range xl id) 'unmerge) (setq Rtn (msxl-get-range xl id)) ) ) Rtn ) | |||
Examples: (vlxls-cell-unmerge *xlapp* "C12:F14") è#< (vlxls-cell-unmerge *xlapp* "E14") è#< |
Excel Cell and Range Progress Function | |||
Name | (vlxls-cell-merge-p ExcelSessionVLA-OBJECT CellIDString) | ||
Usage | Check if the certain Excel cell is merged | ||
Input | VLOBJ | The Excel Session vla-object | |
STR/LIST | The Cell ID list or string | ||
RetVal | True | BOOLEAN | T |
Fail | BOOLEAN | NIL | |
(Defun vlxls-cell-merge-p (xl id) (equal (vlax-variant-value (msxl-get-mergecells (msxl-get-range xl id)) ) :vlax-true ) ) | |||
Examples: (vlxls-cell-merge-p *xlapp* "C12:F14") èT (vlxls-cell-merge-p *xlapp* "E14") èNIL |
Excel Cell and Range Progress Function | |||
Name | (vlxls-cell-get-mergeid ExcelSessionVLA-OBJECT CellIDString) | ||
Usage | Get the Left-Upper and Right-Lower Cell ID of a merged cell. | ||
Input | VLOBJ | The Excel Session vla-object | |
STR/LIST | Any Cell ID list or string of a merged cell | ||
RetVal | True | STRING | A string contain Left-Upper and Right-Lower cells' ID |
Fail | BOOLEAN | NIL | |
(Defun vlxls-cell-get-mergeid (XL ID / Rtn) (if (vlxls-cell-merge-p xl id) (progn (msxl-select (msxl-get-range xl id)) (setq Rtn (vlxls-range-getid (msxl-get-selection xl))) ) ) Rtn ) | |||
Examples: (vlxls-cell-get-mergeid *xlapp* "C12:F14") è"B9:G19" (vlxls-cell-get-mergeid *xlapp* "E14") è"A11:G19" |
Excel Cell and Range Progress Function | |||
Name | (vlxls-range-getid RangeObject) | ||
Usage | Get the Left-Upper and Right-Lower Cell ID of a range object. | ||
Input | VLOBJ | The | |
RetVal | True | STRING | A string contain Left-Upper and Right-Lower cells' ID |
Fail | BOOLEAN | NIL | |
(Defun vlxls-range-getID (range / str col row dx dy) (if (equal (vlxls-get-property range range "mergecells") :vlax-true) (setq str "MergeArea.") (setq str "") ) (setq dx (vlxls-get-property range (strcat str "Rows.Count")) dy (vlxls-get-property range (strcat str "Columns.Count")) row (vlxls-get-property range (strcat str "Row")) col (vlxls-get-property range (strcat str "Column")) ) (strcat (vlxls-rangeid (list col row)) ":" (vlxls-rangeid (list (1- (+ col dy)) (1- (+ row dx)))) ) ) | |||
Examples: (vlxls-range-getid RangeObject) è"C12:G19" (vlxls-range-getid RangeObject) è"B16:B16" |
Excel Cell and Range Progress Function | |||
Name | (vlxls-range-size RangeObject) | ||
Usage | Get the column width and row height list of a range object. | ||
Input | VLOBJ | The | |
RetVal | True | STRING | A list contain two sub-list, each sub-list contain real number of columns' width and rows' height. Syuntax: ((Column1Width Column2Width…)(Row1Height Row2Height…)) |
Fail | BOOLEAN | NIL | |
(Defun vlxls-range-size (range / xl row col rrr ccc xxx yyy) (setq xl (msxl-get-parent range) Row (msxl-get-count (msxl-get-rows Range)) RRR (1- (msxl-get-row Range)) CCC (msxl-get-column Range) ) (repeat Row (setq yyy (cons (vlax-variant-value (msxl-get-height (msxl-get-range xl (vlxls-rangeid (list CCC (setq RRR (1+ RRR)))) ) ) ) yyy ) ) ) (setq RRR (msxl-get-row Range) CCC (1- (msxl-get-column Range)) ) (repeat (setq xxx (cons (vlax-variant-value (msxl-get-width (msxl-get-range xl (vlxls-rangeid (list (setq CCC (1+ CCC)) RRR)) ) ) ) xxx ) ) ) (list (reverse xxx) (reverse yyy)) ) | |||
Examples: (vlxls-range-size RangeObject) è ((27.0 27.0 110.25 51.0 69.75) (14.25 14.25 14.25 14.25 14.25 57.0 14.25)) |
Excel Cell and Range Progress Function | |||
Name | (vlxls-rangevalue->safearray RangeValueList) | ||
Usage | Convert a Range-Value-List into safearray list so that they can be passed into Excel directly. VLXLS defined a Range-Value-List as a dot-paired list contain two elements: 1st for Cell ID, 2nd for the cell content. Example for Range-Value-List may be '(("A1" . "aaa")("A2" . "SDA")...("C12" . "ccc")) Because Range-Value-List may NOT cover all Cell IDs, this function will automatically fill the undefined cells with "" so that the return variant can be send to Excel directly. | ||
Input | VLOBJ | The Excel Range vla-object | |
RetVal | True | STRING | A safearray variant contain all given Range-Value-List |
Fail | BOOLEAN | NIL | |
(Defun vlxls-Rangevalue->SafeArray (Data / XSub_GetXY XSub_GetMinMaxID xsub-MergeID->List MinID MaxID ID ID1 ID2 IDN X minid xy Y Rtn Item ) (Defun xsub-MergeID->List (ID / KK ID1 ID2 IDX IDY Rtn) (Setq ID (strcase ID)) (if (setq KK (vl-string-search ":" ID)) (setq ID1 (substr ID 1 KK) ID2 (substr ID (+ 2 KK)) ) (setq ID1 ID ID2 ID ) ) (setq ID1 (vlxls-rangeid ID1) ID2 (vlxls-rangeid ID2) IDX (vlxls-rangeid (list (min (nth 0 ID1) (nth 0 ID2)) (min (nth 1 ID1) (nth 1 ID2)) ) ) IDY (vlxls-rangeid (list (max (nth 0 ID1) (nth 0 ID2)) (max (nth 1 ID1) (nth 1 ID2)) ) ) Rtn (list IDX IDY) ) Rtn ) (Defun XSub_GetXY (ID SID / S10 S11 DX DY Rtn) (setq S10 (nth 0 MinID) S11 (nth 1 MinID) ID (vlxls-rangeid ID) DX (- (nth 0 ID) S10) DY (- (nth 1 ID) S11) Rtn (list DX DY) ) Rtn ) (Defun XSub_GetMinMaxID (ID1 ID MinorMax / X Y X1 Y1 Rtn) (if (null ID) (setq Rtn ID1) (progn (setq ID1 (vlxls-rangeid ID1) ID (vlxls-rangeid ID) X1 (nth 0 ID1) Y1 (nth 1 ID1) X (nth 0 ID) Y (nth 1 ID) ) (if (null MinorMax) (setq Rtn (vlxls-rangeid (list (min X X1) (min Y Y1)))) (setq Rtn (vlxls-rangeid (list (max X X1) (max Y Y1)))) ) ) ) Rtn ) (foreach Item Data (setq ID (strcase (car Item))) (if (vl-string-search ":" ID) (setq IDN (xsub-MergeID->List ID)) (setq IDN (list ID)) ) (foreach ID IDN (setq MinID (XSub_GetMinMaxID ID MinID nil) MaxID (XSub_GetMinMaxID ID MaxID T) ) ) ) (setq MinID (vlxls-rangeid MinID) MaxID (vlxls-rangeid MaxID) X (- (nth 0 MaxID) (nth 0 MinID)) Y (- (nth 1 MaxID) (nth 1 MinID)) Rtn (vlax-make-safearray vlax-vbstring (cons 0 Y) (cons 1 (1+ X)) ) ) (foreach Item Data (setq ID (strcase (car Item))) (if (vl-string-search ":" ID) (setq IDN (xsub-MergeID->List ID)) (setq IDN (list ID)) ) (foreach ID IDN (setq XY (XSub_GetXY ID MinID)) (vlax-safearray-put-element Rtn (nth 1 XY) (1+ (nth 0 XY)) (cdr Item) ) ) ) Rtn ) | |||
Examples: (vlxls-rangevalue->safearray '(("A1" . "aaa")("B4" . "ccc"))) è#<safearray...> (vlxls-variant->list (vlxls-rangevalue->safearray '(("A1" . "aaa")("B4" . "ccc"))))è(("aaa" "") ("" "") ("" "") ("" "ccc")) |
Public Function | |||
Name | (vlxls-get-property TopVLAObject NestPropertyString) | ||
Usage | Get the property of a nested VLA-Object from the main top vla-object. Use same property indicator as VBA. | ||
Input | VLOBJ | The Top vla-object | |
STRING | The Property combination string, divided with ".", ordered from top to inner. | ||
RetVal | True | ANY | The value of the most nested property. |
Fail | BOOLEAN | NIL | |
(Defun vlxls-get-property (top prop / vlstring->list item Rtn) (Defun vlstring->list (str st / lst e) (setq str (strcat str st)) (while (vl-string-search st str) (setq lst (append lst (list (substr str 1 (vl-string-search st str)))) ) (setq str (substr str (+ (1+ (strlen st)) (vl-string-search st str))) ) ) (if lst (mapcar '(lambda (e) (vl-string-trim " " e)) lst) ) ) (cond ((= (type prop) 'sym) (setq Rtn (vlax-get-property top prop)) ) ((= (type prop) 'str) (if (null (vl-string-search "." prop)) (setq Rtn (vlax-get-property top prop)) (foreach item (vlstring->list prop ".") (if (null Rtn) (setq Rtn (vlax-get-property top item)) (setq Rtn (vlax-get-property Rtn item)) ) ) ) ) ) (cond ((= (type Rtn) 'variant) (setq Rtn (vlax-variant-value Rtn)) ) ((= (type Rtn) 'safearray) (setq Rtn (vlxls-variant->list Rtn)) ) ) Rtn ) | |||
Examples: (vlxls-get-property RangeObject "Application.ActiveSheet.Name") è"Sheet1" (vlxls-get-property RangeObject "MergeArea.Columns.Count") è3 |
Following is the pre-define part of VLXLS project, VLXLS need a global variable named as *xls-color* to contain all color matching list. Syntax as (ECI ACI TrueColor), sorted as ECI number.
As VLXLS support two languages: English as international and Simplified Chinese as local. In Default, VLXLS will go to seek if global variable *Chinese* is true, if so, VLXLS will prompt Chinese, or VLXLS will display English as default.
(setq *xls-color* (list (list 1 18 0) (list 2 7 1677215) (list 3 1 16711680) (list 4 3 65280) (list 5 5 255) (list 6 2 16776960) (list 7 6 16711935) (list 8 4 65535) (list 9 16 8323072) (list 10 96 32512) (list 11 176 127) (list 12 56 8355584) (list 13 216 8323199) (list 14 136 32639) (list 15 9 12566463) (list 16 8 8355711) (list 17 161 9476095) (list 18 237 9449568) (list 19 7 1677167) (list 20 254 12648447) (list 21 218 6291552) (list 22 11 16744319) (list 23 152 24768) (list 24 254 13617407) (list 25 176 127) (list 26 6 16711935) (list 27 2 16776960) (list 28 4 65535) (list 29 216 8323199) (list 30 16 8323072) (list 31 136 32639) (list 32 5 255) (list 33 140 51455) (list 34 254 12648447) (list 35 254 13631439) (list 36 51 16777104) (list 37 151 9488639) (list 38 221 16750799) (list 39 191 13605119) (list 40 31 16763024) (list 41 150 3105023) (list 42 132 3131584) (list 43 62 9488384) (list 44 40 16762880) (list 45 30 16750336) (list 46 30 16738048) (list 47 165 6317968) (list 48 252 9475984) (list 49 148 12384) (list 50 105 3184736) (list 51 98 12032) (list 52 48 3158016) (list 53 24 9449472) (list 54 237 9449311) (list 55 177 3158160) (list 56 250 3092527) ) *Chinese* nil ) (if vl-load-com (vl-load-com) ) (if vl-arx-import (foreach item '(ACAD_COLORDLG ACAD_truecolordlg ACAD_STRLSORT INITDIA ACAD-POP-DBMOD ACAD-PUSH-DBMOD STARTAPP layoutlist ) (vl-arx-import item) ) ) (setq item nil *xls-ver* "3.5.61231 [Build: TRINNOLOV1]" ) (princ (strcat "\n KozMos VLXLS Project (Version " *xls-ver* ")") ) (princ "\n Copyright(C) 1994-2007 KozMos Inc. All rights reserved" ) (princ) |
VLXLS document version 3.5.61231
Copyright© 1994-2007 by KozMos Inc. All rights reserved
Documented by Koz Jono Yeoh, KozMos Inc.
Beijing, PRC
2007/01/08