| |
2009-04-26, 06:19 PM | #1 |
高级会员
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
|
哪位高手指点一下下边lisp的怎么用
哪位高手指点一下下边lisp的怎么用
www.dimcax.com 哪位高手指点一下下边lisp的怎么用 ;|copyright(c) 1994-2005 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. 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; roperties-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 件到获取更多的解决方案\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 \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-" roperties-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 excel range vla-object 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. if only one cell id is provided, set the right-lower cell id to “”. 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 excel range vla-object 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 active range vla-object 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”) è #<vla-object range 09d1998c> (vlxls-cell-put-active *xlapp* “f12”) è #<vla-object range 06c389a2> 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 excel range vla-object that just be filled in by given data list 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”) è #<vla-object range 093a7764> (vlxls-cell-put-value *xlapp* “c12:f3” “xx”) è #<vla-object range 43c5ac64> (vlxls-cell-put-value *xlapp* “c12:d13” ‘((“zz” “xx”)(“xx” “zz”))) è #<vla-object range 1b8f2a64> 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 excel range vla-object 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”) è#<vla-object range 2a621cac> (vlxls-put-row-value *xlapp* ‘(12 3) “abc”) è#<vla-object range 7a36c491> (vlxls-put-row-value *xlapp* “c12” ‘("zz" "xxx")) è#<vla-object range 09d1da1c> (vlxls-put-row-value *xlapp* ‘(12 3) ‘("zz" "xxx")) è#<vla-object range 0a26c4f3> 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 excel range vla-object 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”) è#<vla-object range 049c521b> (vlxls-put-column-value *xlapp* ‘(12 3) “abc”) è#<vla-object range 0235cba1> (vlxls-put-column-value *xlapp* “c12” ‘("zz" "xxx")) è#<vla-object range 09d1da1c> (vlxls-put-column-value *xlapp* ‘(12 3) ‘("zz" "xxx")) è#<vla-object range 0a26c4f3> 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 excel range vla-object 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) è#<vla-object range 09d1369c> (vlxls-cell-put-aci *xlapp* “c12” nil) è#<vla-object range 09d1369c> 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 excel range vla-object 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) è#<vla-object range 09d1369c> (vlxls-text-put-aci *xlapp* “c12” nil) è#<vla-object range 09d1369c> 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) (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”) è#<vla-object range 0023ab7c> 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”) è#<vla-object range 0023ab7c> (vlxls-cell-unmerge *xlapp* “e14”) è#<vla-object range 09ce72e4> 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 excel range vla-object retval true string a string contain left-upper and right-lower cells’ id fail boolean nil |; (defun vlxls-range-getid (range / col row dx dy) (setq dx (vlxls-get-property range "mergearea.rows.count") dy (vlxls-get-property range "mergearea.columns.count") row (vlxls-get-property range "mergearea.row") col (vlxls-get-property range "mergearea.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 excel range vla-object 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)) col (msxl-get-count (msxl-get-columns 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 col (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* t ) (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* "1.2.50331" ) ;|(princ (strcat "\n vlae:vlxls freebie api version " *xls-ver*) ) (princ "\n copyright(c) 1994-2005 kozmos inc. all rights reserved" ) |; ;(princ) ;;;;;;;;;;;;;;;;; (defun vlxls-screenupdating-off (*xlapp*) (vlax-put-property *xlapp* 'screenupdating 0)) (defun vlxls-screenupdating-on (*xlapp*) (vlax-put-property *xlapp* 'screenupdating -1)) ;;************************************************************************* ;;; 模塊: vlxls-excel-columnwidth ;;; 描述: 調整寬度col為width ;;; 參數: sheet (object) ;;; 示例: (vlxls-excel-columnwidth xlapp 2 12);;調整b欄寬為12 ;;;************************************************************************* (defun vlxls-columnwidth(xlapp col width / sheet cell) (setq sheet (vlax-get-property xlapp "activesheet")) (vlax-put-property (setq cell (vlxls-get-cell sheet 1 col)) "columnwidth" width) ) ;;;************************************************************************* ;;; 模塊: msx-excel-rowheight ;;; 描述: 調整列高row為height ;;; 參數: sheet (object) ;;; 示例: (msx-excel-columnwidth xlapp 3 15);;調整3列高為15 ;;;************************************************************************* (defun vlxls-rowheight(xlapp row height / sheet cell) (setq sheet (vlax-get-property xlapp "activesheet")) (vlax-put-property (setq cell (vlxls-get-cell sheet row 1)) "rowheight" height) ) (defun vlxls-get-cell (obj row col / item cells) (setq item (vlax-get-property (setq cells (vlax-get-property obj "cells")) "item" (vlax-make-variant row) (vlax-make-variant col))) (vlax-release-object cells) (vlax-variant-value item)) (defun vlxls-put-pagesetup(xlapp top bot lef rig hea fot flh flv);;設置版面 (setq sheet (vlax-get-property xlapp "activesheet")) (setq page (vlax-get-property sheet "pagesetup")) (vlax-put-property page "footermargin" (* fot 28.3465)) (vlax-put-property page "headermargin" (* hea 28.3465)) (vlax-put-property page "leftmargin" (* lef 28.3465)) (vlax-put-property page "rightmargin" (* 28.3465 rig)) (vlax-put-property page "topmargin" (* top 28.3465)) (vlax-put-property page "bottommargin" (* bot 28.3465)) (vlax-put-property page "centerhorizontally" (* 28.3465 flh)) (vlax-put-property page "centervertically" (* flv 28.3465)) ) ;;;************************************************************************* ;;; 模塊: vlxls-excel-cellfontname ;;; 描述: 更改單元格字體 ;;; 參數: row col name ;;; 示例: (vlxls-excel-cellfontname 2 3 "新細明體");;更改單元格c2字體為"新細明體" ;;;************************************************************************* (defun vlxls-excel-cellfontname(xlapp row col name / sheet cell) (setq sheet (vlax-get-property xlapp "activesheet")) (vlax-put-property(vlax-get-property (setq cell (msx-get-cell sheet row col)) "font" ) "name" name )) ;;;************************************************************************* ;;; 模塊: vlxls-excel-cellcolor ;;; 描述: 更改單元格顏色 ;;; 參數: row col color ;;; 示例: (vlxls-excel-cellcolor2 3 14);;更改單元格c2為14號色 ;;;************************************************************************* (defun vlxls-excel-cellcolor(xlapp row col color / sheet cell) (setq sheet (vlax-get-property xlapp "activesheet")) (setq cell (vlxls-get-cell sheet row col)) (msxl-put-colorindex (msxl-get-interior cell) color)) ;;;************************************************************************* ;;; 模塊: vlxls-excel-textcolor ;;; 描述: 更改單元格文字顏色 ;;; 參數: row col color ;;; 示例: (vlxls-excel-textcolor 2 3 14);;更改單元格c2文字為14號色 ;;;************************************************************************* (defun vlxls-excel-textcolor(xlapp row col color / sheet cell) (setq sheet (vlax-get-property xlapp "activesheet")) (setq cell (vlxls-get-cell sheet row col)) (vlax-put-property (vlax-get-property cell "font") "colorindex" color)) ;;;************************************************************************* ;;; 模塊: vlxls-excel-textsize ;;; 描述: 更改單元格文字大小 ;;; 參數: row col size ;;; 示例: (vlxls-excel-textsize 2 3 18);;更改單元格c2文字為18號字大小 ;;;************************************************************************* (defun vlxls-excel-textsize(xlapp row col size / sheet cell) (setq sheet (vlax-get-property xlapp "activesheet")) (setq cell (vlxls-get-cell sheet row col)) (vlax-put-property (vlax-get-property cell "font") "size" size)) ;;;************************************************************************* ;;; 模塊: vlxls-excel-textunderline ;;; 描述: 更改單元格文字下畫線 ;;; 參數: row col size ;;; 示例: (vlxls-excel-textunderline 2 3 1);;更改單元格c2文字無下划線 ;;;************************************************************************* (defun vlxls-excel-textunderline(xlapp row col underline / sheet cell) (setq sheet (vlax-get-property xlapp "activesheet")) (setq cell (vlxls-get-cell sheet row col)) (vlax-put-property (vlax-get-property cell "font") "underline" underline)) ;;;;;注: underline 1---------無下划線 ;;;;; 2---------單線 ;;;;; 3---------雙線 ;;;;; 4---------會計用單線 ;;;;; 5---------會計用雙線 ;;;************************************************************************* ;;; 模塊: vlxls-excel-fontstyle ;;; 描述: 更改單元格文字形式 ;;; 參數: row col color ;;; 示例: (vlxls-excel-fontstyle 2 3 "粗體");;更改單元格c2文字為14粗體 ;;;************************************************************************* (defun vlxls-excel-fontstyle(xlapp row col style / sheet cell) (setq sheet (vlax-get-property xlapp "activesheet")) (setq cell (vlxls-get-cell sheet row col)) (vlax-put-property (vlax-get-property cell "font") "fontstyle" style)) ;;;************************************************************************* ;;; 模塊: vlxls-excel-fontspecial ;;; 描述: 更改單元格文字特殊效果 ;;; 參數: row col color ;;; 示例: (vlxls-excel-fontspecial 2 3 "strikethrough" item);;更改單元格c2文字特殊效果為刪線 ;;; "superscript"為上標 "subscript" 為下標 (item設置為0則停用,-1為啟用) ;;;************************************************************************* (defun vlxls-excel-fontspecial(xlapp row col special item / sheet cell) (setq sheet (vlax-get-property xlapp "activesheet")) (setq cell (vlxls-get-cell sheet row col)) (vlax-put-property (vlax-get-property cell "font") special item)) ;;;************************************************************************* ;;; 模塊: vlxls-excel-textalignment ;;; 描述: 更改單元格文字對齊方式 ;;; 參數: row col color hal val ;;; 示例: (vlxls-excel-textalignment 2 3 1 -4108);;更改單元格c2文字對齊方式水平方向一般﹐垂直置中 ;;;************************************************************************* (defun vlxls-excel-textalignment (xlapp row col hal val / sheet cell) (setq sheet (vlax-get-property xlapp "activesheet")) (setq cell (vlxls-get-cell sheet row col)) (vlax-put-property cell "horizontalalignment" hal) (vlax-put-property cell "verticalalignment" val)) ;;;注:水平方式 1 ----------一般 ;;;;;;;;; -4131----------左縮排 ;;;;或2 ;;;;;;;;; -4108----------置中對齊 ;;或3 ;;;;;;;;; -4152----------靠右對齊 ;;或4 ;;;;;;;;; 5 ----------填滿 ;;或5 ;;;;;;;;; -4130----------水平對齊 ;;或6 ;;;;;;;;; 7----------跨欄置中 ;;;;;;;;; -4117----------分散對齊 ;;或8 ;;;注:垂直方式 -4160 ----------靠上 或1 ;;;;;;;;; -4108----------置中對齊 或2 ;;;;;;;;; -4107----------靠下 或3 ;;;;;;;;; -4130----------垂直對齊 或4 ;;;;;;;;; -4117 ----------分散對齊 或5 ;;;页面设置 ;;;(vlxls-excel-pagesetup *xlapp* ".leftfooter" "&p") ;;;具体设置参考如下 ;| activewindow.selectedsheets.hpagebreaks.add before:=activecell 插入分页符 with activesheet.pagesetup .printtitlerows = "$1:$3" 工作表 .printtitlecolumns = "" 工作表左端标题列 end with activesheet.pagesetup.printarea = "$c$1:$h$255" 工作表打印区域 with activesheet.pagesetup .leftheader = "" 左页眉 .centerheader = "" 中页眉 .rightheader = "" 右页眉 .leftfooter = "&p" 左页脚 .centerfooter = "&n" 中页脚 .rightfooter = "aaaaaaaaa" 右页脚 .leftmargin = application.inchestopoints(0.62) 左边距 .rightmargin = application.inchestopoints(0.748031496062992) 右边距 .topmargin = application.inchestopoints(0.984251968503937) .bottommargin = application.inchestopoints(0.393700787401575) .headermargin = application.inchestopoints(0.511811023622047) .footermargin = application.inchestopoints(0.511811023622047) .printheadings = false .printgridlines = false .printcomments = xlprintnocomments .centerhorizontally = false .centervertically = false .orientation = xlportrait .draft = false .papersize = xlpapera4 .firstpagenumber = xlautomatic 打印起始页 .order = xldownthenover .blackandwhite = false .zoom = 100 .printerrors = xlprinterrorsdisplayed end with end sub |; (defun vlxls-excel-pagesetup (xlapp key var / sheet pagesetup) (setq sheet (vlax-get-property xlapp "activesheet")) (setq pagesetup (vlax-get-property sheet "pagesetup")) (vlax-put-property pagesetup key var) ) ;;; activewindow.selectedsheets.hpagebreaks.add before:=activecell ;;;在单元格id 之前插入分页符 (defun vlxls-excel-inserthpagebreaks (xlapp id / sheet hpagebreaks hpagebreaks) (setq sheet (vlax-get-property xlapp "activesheet")) (setq hpagebreaks (vlax-get-property sheet "hpagebreaks")) (vlxls-cell-put-active xlapp id) (vlax-invoke-method hpagebreaks 'add (vlax-get-property xlapp "activecell")) ) |
GDT自动化论坛(仅游客可见) |