找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 5347|回复: 17

[LISP程序]:VLISP操作EXCEL函数库大全..

[复制链接]
发表于 2005-3-26 16:08:10 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×

  1. ;;;;;;;;此為經整理過后一些VLISP調用EXCEL常用公共函數;;;;;;;;;;;;
  2. ;;;;;;;;此為私人函數未經許可請勿...............................
  3. ;;;;;;;;開發:朱衛星 2005/02/22 rev01............................
  4. ;;;;;;;;it's the first!ok!used in acad at least rev. 2000;;;;;;;
  5. (Defun vlxls-variant->list (VarX / Run Item Rtn)
  6.   (setq Run T)
  7.   (while Run
  8.     (cond ((= (type VarX) 'SAFEARRAY)
  9.     (setq VarX (vlax-safearray->list VarX)))
  10.     ((= (type VarX) 'VARIANT)
  11.      (if    (member (vlax-variant-type VarX) (list 5 4 3 2))
  12.      (setq VarX (vlax-variant-change-type Varx vlax-vbString)))
  13.      (setq VarX (vlax-variant-value VarX)))
  14.           (t (setq Run nil)))
  15.     )
  16.    (cond  ((= (type VarX) 'LIST)
  17.            (foreach Item VarX
  18.              (setq Item (vlxls-variant->list Item) Rtn  (append Rtn (list Item))
  19.                    )
  20.              )
  21.            )
  22.       ((= VarX nil) (setq Rtn ""))
  23.       (t (setq Rtn VarX)))
  24.   Rtn)


  25. (Defun vlxls-color-ECI->truecolor (Color / Rtn)
  26.   (if (setq Rtn (cdr (assoc Color *xls-color*)))
  27.   (setq Rtn (nth 1 Rtn)))
  28.   (if (null Rtn)
  29.   (setq Rtn 16711935)
  30.   )Rtn
  31.   )
  32. ;;;EXAMPLE:
  33. ;;;(vlxls-color-eci->truecolor 0)return: 16711935
  34. ;;;(vlxls-color-eci->truecolor 1)return: 0
  35. ;;;(vlxls-color-eci->truecolor 12)return: 8355584
  36. ;;;(vlxls-color-eci->truecolor 120)return: 16711935


  37. (Defun vlxls-color-eci->aci (Color / Rtn)
  38. (if (null (setq Rtn (cdr (assoc Color *xls-color*))))
  39. (setq Rtn 256)
  40. (setq Rtn (nth 0 Rtn))
  41. )
  42. Rtn)
  43. ;;;EXAMPLE:
  44. ;;;(vlxls-color-eci->aci 0)return: 256
  45. ;;;(vlxls-color-eci->aci 1)return: 18
  46. ;;;(vlxls-color-eci->aci 12)return: 56
  47. ;;;(vlxls-color-eci->aci 120)return: 256


  48. (Defun vlxls-color-aci->eci (Color / Item Rtn)
  49.   (foreach Item    *xls-color*
  50.     (if    (= (nth 1 Item) Color)
  51.     (setq Rtn (car Item)))
  52.    )
  53.   (if (null Rtn)
  54.   (setq Rtn 0))
  55.   Rtn
  56.   )
  57. ;;;Examples:
  58. ;;;(vlxls-color-aci->eci 0)return: 0
  59. ;;;(vlxls-color-aci->eci 1)return: 3
  60. ;;;(vlxls-color-aci->eci 12)return: 0
  61. ;;;(vlxls-color-aci->eci 120)return: 0

  62. (Defun vlxls-color-aci->truecolor (aci)
  63. (vlxls-color-eci->truecolor (vlxls-color-aci->eci aci))
  64.   )
  65. ;;;Examples:
  66. ;;;(vlxls-color-aci-> truecolor 0) return: 16711935
  67. ;;;(vlxls-color-aci->truecolor 1)  return: 16711680
  68. ;;;(vlxls-color-aci-> truecolor 12)return: 16711935
  69. ;;;(vlxls-color-aci-> truecolor 120)return: 16711935

  70. ;;;OK!NOW LET'S GO! START EXCEL.APPLICATION!!............
  71. ;;;before use these program you should install "Microsoft Excel" in your computer!!
  72. ;;;if not,you will recicieve an error messege!!
  73. ;;;such as "warning:........."! ZWX 2005/02/22 COPYRIGHT .....
  74. (Defun vlxls-app-Init (/ OSVar GGG Olb8 Olb9 Olb10 TLB Out msg msg1 msg2)
  75.   ;;;;;;;;;;該程序實現了初始化EXCEL應用程序!
  76.   (if *Chinese*
  77.   (setq msg  "\n 初始化微軟Excel "
  78.         msg1 "\042初始化Excel失敗\042"
  79.         msg2 (strcat "\042 警告""\n ====""\n 無法在您的計算机上檢測到微軟Excel軟件"
  80.               "\n 如果您确認已經安裝Excel, 請發送電子郵"
  81.               "\n 件到yota@ikozmos.com獲取更多的解決方案\042"))
  82.   (setq msg  "\n Initializing Microsoft Excel "
  83.         msg1 "\042Initialization Error\042"
  84.         msg2 (strcat "\042 WARNING""\n ======="
  85.                      "\n Can NOT detect Excel97/200X/XP in your computer"
  86.                      "\n If you already have Excel installed, please email"
  87.                      "\n us to get more solution via [email]yota@ikozmos.com[/email]\042"))
  88.     )
  89. (if (null msxl-xl24HourClock)
  90. (progn (if (and (setq GGG (vl-registry-read
  91.         "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\Excel.EXE"
  92.         "Path"))
  93. (setq GGG (strcase (strcat GGG "Excel.EXE"))))
  94. (progn (foreach OSVar (list "SYSTEMROOT" "WINDIR""WINBOOTDIR" "SYSTEMDRIVE"
  95.            "USERNAME"  "COMPUTERNAME" "HOMEDRIVE" "HOMEPATH" "PROGRAMFILES")
  96.    (if    (vl-string-search (strcat "%" OSVar "%") GGG)
  97.           (setq GGG (vl-string-subst (strcase (getenv OSVar))
  98.                       (strcat "%" OSVar "%")GGG)))
  99.          )
  100. (setq   Olb8  (findfile (vl-string-subst "EXCEL8.OLB" "EXCEL.EXE" GGG))
  101.          Olb9  (findfile (vl-string-subst "EXCEL9.OLB" "EXCEL.EXE" GGG))
  102.          Olb10 (findfile (vl-string-subst "EXCEL10.OLB" "EXCEL.EXE" GGG)))
  103. (cond  ((= (vl-filename-base (vl-filename-directory GGG))"OFFICE11")
  104.          (setq TLB GGG Out "2003"))
  105.         ((= (vl-filename-base (vl-filename-directory GGG))
  106.             "OFFICE10")
  107.          (setq TLB GGG Out "XP"))
  108.          (Olb9 (setq TLB Olb9 Out "2000"))
  109.          (Olb8 (setq TLB Olb8 Out "97"))
  110.          (t (setq Out "Version Unknown"))
  111.         )
  112.   (if TLB (progn (princ (strcat MSG Out "..."))
  113.                  (vlax-import-type-library
  114.                     :tlb-filename TLB
  115.                     :methods-prefix "msxl-"
  116.                     :properties-prefix "msxl-"
  117.                     :constants-prefix "msxl-"))
  118.     )
  119.   )(progn (if vldcl-msgbox
  120.              (vldcl-msgbox "x" msg1 msg2)
  121.              (alert (read msg2)))
  122.           (exit)))
  123.   )
  124.   )
  125.   msxl-xl24HourClock
  126.   )
  127. ;;;Examples:
  128. ;;;(vlxls-app-init) return: 33

  129. (Defun vlxls-app-New (UnHide / Rtn)
  130.   ;;;; 該程序實現功能:新建一個excel格
  131.   ;;;;;;;;;; THIS PROGRAM CAN BUILD A NEW EXCELFILE
  132.   (if (vlxls-app-init)
  133.       (progn
  134.       (if *Chinese* (princ "\n 新建微軟Excel工作表...")
  135.                     (princ "\n Creating new Excel Spreadsheet file..."))
  136.       (if (setq Rtn (vlax-get-or-create-object "Excel.Application"))
  137.       (progn (vlax-invoke-method
  138.              (vlax-get-property Rtn 'WorkBooks)
  139.              'Add)
  140.         (if UnHide (vla-put-visible Rtn 1)
  141.           (vla-put-visible Rtn 0))
  142.     )
  143.     )
  144.       )
  145.     )
  146.   Rtn
  147.   )
  148. ;;;Examples:
  149. ;;;(setq *xlapp* (vlxls-app-new T)) return: #<VLA-OBJECT _Application 001db27c>

  150. (Defun vlxls-app-open(XLSFile UnHide / ExcelApp WorkSheet Sheets ActiveSheet Rtn)
  151.   ;;;function: this program can open an excelfile
  152.   (setq XLSFile (strcase XLSFile))
  153.   (if (null (wcmatch XLSFile "*.XLS"))
  154.   (setq XLSFile (strcat XLSFile ".XLS")))
  155.   (if (and (findfile XLSFile)
  156.        (setq Rtn (vlax-get-or-create-object "Excel.Application")))
  157.     (progn (vlax-invoke-method (vlax-get-property Rtn 'WorkBooks)
  158.         'Open XLSFile)
  159. (if UnHide
  160.     (vla-put-visible Rtn 1)
  161.     (vla-put-visible Rtn 0))))
  162.   Rtn)

  163. ;;;Examples:
  164. ;;;(setq *xlapp* (vlxls-app-open “C:/test.XLS” T)) e #<VLA-OBJECT _Application 001efd2c>

  165. (Defun vlxls-app-save (xlapp)
  166.   ;;;;保存文件
  167.   (equal (vlax-invoke-method
  168.          (vlax-get-property Xlapp "ActiveWorkbook")"Save")
  169.          :vlax-true)
  170.   )
  171. ;;;Examples:
  172. ;;;(vlxls-app-save *xlapp*) return: T

  173. (Defun vlxls-app-saveas (xlapp Filename / Rtn);;;另存文件
  174.    (if (null filename)
  175.     (setq filename (strcat (getvar "dwgprefix") "XLS.XLS")))
  176.    (if (null (wcmatch (setq filename (strcase Filename)) "*.XLS"))
  177.    (setq filename (strcat filename ".XLS")))
  178.    (if (findfile Filename)
  179.     (vl-file-delete (findfile Filename))
  180.     )
  181.    (vlax-invoke-method
  182.      (vlax-get-property Xlapp "ActiveWorkbook")
  183.      "SaveAs"
  184.      Filename
  185.      msxl-xlNormal
  186.      ""
  187.      ""
  188.      :vlax-False
  189.      :vlax-False
  190.      nil
  191.      )
  192.   (findfile Filename)
  193.   )

  194. ;;;Examples:
  195. ;;;(vlxls-app-saveas *xlapp* nil) return: “C:/Temp-Folder/XLS.XLS”
  196. ;;;(vlxls-app-saveas *xlapp* “C:/Temp-Folder/XLS.XLS”) return: “C:/Temp-Folder/XLS.XLS”
  197. ;;;(vlxls-app-saveas *xlapp* nil) return: NIL

  198. (Defun vlxls-app-quit (ExlObj SaveYN);;退出應用程序
  199.   (if SaveYN
  200.      (vlax-invoke-method
  201.        (vlax-get-property ExlObj "ActiveWorkbook")
  202.        'Close
  203.        )
  204.     (vlax-invoke-method
  205.       (vlax-get-property ExlObj "ActiveWorkbook")
  206.       'Close
  207.         :vlax-False
  208.       )
  209.     )
  210.   (vlax-invoke-method ExlObj 'QUIT)
  211.   (vlax-release-object ExlObj)
  212.   (setq ExlObj nil)
  213.   (gc)
  214.   )
  215. ;;;Examples:
  216. ;;;(vlxls-app-quit *xlapp* nil) return: nil

  217. (Defun vlxls-app-kill (SaveYN / ExlObj);;;強行清除所有EXCEL應用程序
  218.   (while (setq ExlObj (vlax-get-object "Excel.Application"))
  219.     (vlxls-app-quit ExlObj SaveYN))
  220.   )
  221. ;;;Examples:
  222. ;;;(vlxls-app-kill T) return: nil

  223. (Defun vlxls-app-autofit (xlapp / sh act Rtn);;;存儲格自動調整大小
  224.   (setq act (vlxls-Sheet-Get-Active xlapp))
  225.   (foreach sh (append (vl-remove act (vlxls-sheet-get-all Xlapp))
  226.             (list act))
  227.   (setq Rtn (variant-value (msxl-autofit
  228.                              (msxl-get-columns
  229.                                (msxl-get-Cells
  230.               (vlxls-sheet-get-usedrange xlapp sh))))))
  231.     )
  232.   (equal Rtn :vlax-true)
  233.   )
  234. ;;;Examples:
  235. ;;;(vlxls-app-autofit *xlapp*) return: T
  236. ;;;(vlxls-app-autofit *xlapp*) return: NIL

  237. (Defun vlxls-sheet-get-all (xlapp / SH Rtn);;;;取得所有應用的頁
  238.   (vlax-for SH (vlax-get-property Xlapp "sheets")
  239.   (setq Rtn (cons (vlax-get-property sh "Name") Rtn))
  240.   )(reverse Rtn)
  241.   )
  242. ;;;Examples:
  243. ;;;(vlxls-sheet-get-all *xlapp*) e ("Sheet1" "Sheet2" "Sheet3")

  244. (Defun vlxls-Sheet-Get-Active (xlapp);;;;返回當前應用的頁
  245.   (vlax-get-property (msxl-get-ActiveSheet Xlapp) 'name)
  246.   )
  247. ;;;Examples:
  248. ;;;(vlxls-sheet-get-active *xlapp*) return: "Sheet2"

  249. (Defun vlxls-sheet-delete (xlapp Name / sh Rtn);;;刪除頁
  250.   (setq Rtn (vlxls-sheet-get-all Xlapp))
  251.   (vlax-for sh (vlax-get-property Xlapp "sheets")
  252.    (if    (= (vlax-get-property sh "Name") Name)
  253.     (vlax-invoke-method sh "Delete"))
  254.     )
  255.   (not (equal Rtn (vlxls-sheet-get-all Xlapp)))
  256.   )
  257. ;;;Examples:
  258. ;;;(vlxls-sheet-delete *xlapp* “Sheet1”) return: T
  259. ;;;(vlxls-sheet-delete *xlapp* “UnExistingSheet”) return: NIL

  260. (Defun vlxls-sheet-rename (New Old Xlapp / sh Rtn);;;給頁重新命名
  261.   (if (null old)
  262.     (setq old (msxl-get-name (msxl-get-activesheet Xlapp))))
  263.   (if (member New (vlxls-sheet-get-all Xlapp))
  264.    (setq Rtn nil)
  265.     (progn (vlax-for sh (vlax-get-property Xlapp "sheets")
  266.           (if (= (msxl-get-name sh) Old)
  267.            (msxl-put-name sh New)))
  268.       (setq Rtn (equal New (vlax-get-property (msxl-get-ActiveSheet Xlapp) 'name)))
  269.       )
  270.     )
  271.   Rtn
  272.   )
  273. ;;;Examples:
  274. ;;;(vlxls-sheet-rename “New” “Sheet1” *xlapp*) return: T
  275. ;;;(vlxls-sheet-rename “New” NIL *xlapp*) return: T
  276. ;;;(vlxls-sheet-rename “Sheet3” NIL *xlapp*) return: NIL
  277. ;;;(vlxls-sheet-rename “Sheet2” “Sheet1” *xlapp*) return: NIL
  278. ;;;(vlxls-sheet-rename “Sheet2” “UnExistSheet” *xlapp*) return: NIL

  279. (Defun vlxls-sheet-add (xlapp Name / Rtn);;;增加頁
  280.   (if (member name (vlxls-sheet-get-all xlapp))
  281.       (setq Rtn nil)
  282.    (progn (vlax-put-property
  283.           (vlax-invoke-method
  284.             (vlax-get-property Xlapp "sheets") "Add")
  285.        "name" Name)
  286. (setq Rtn (equal (vlxls-sheet-get-active xlapp) name))
  287.   ))
  288.   Rtn
  289.   )
  290. ;;;Examples:
  291. ;;;(vlxls-sheet-add *xlapp* “Sheet1”) return: T
  292. ;;;(vlxls-sheet-add *xlapp* NIL) return: T
  293. ;;;(vlxls-sheet-add *xlapp* “NewSheet”) return: NIL

  294. (Defun vlxls-sheet-put-active (xlapp Name / sh);;;設置當前使用頁
  295.   (if (null (vlxls-sheet-add xlapp name))
  296.     (vlax-for sh    (vlax-get-property Xlapp "sheets")
  297.       (if (= (vlax-get-property sh "Name") Name)
  298.         (vlax-invoke-method sh "Activate")
  299.         )
  300.       )
  301.     )
  302.   (equal (vlxls-sheet-get-active xlapp) name)
  303.   )
  304. ;;;Examples:
  305. ;;;(vlxls-sheet-put-active *xlapp* “Sheet1”) return: T
  306. ;;;(vlxls-sheet-put-active *xlapp* “NewSheet”) return: T

  307. (Defun vlxls-sheet-get-UsedRange (xlapp Name / sh Rtn);;;取得使用頁的使用范圍
  308.   (if (null Name)
  309.      (setq Name (vlax-get-property (msxl-get-ActiveSheet Xlapp) 'Name))
  310.     )
  311. (vlax-for sh (vlax-get-property Xlapp "sheets")
  312.    (if   (= (vlax-get-property sh "Name") Name)
  313.      (setq Rtn (vlax-get-property sh "UsedRange")))
  314.    )
  315.   Rtn
  316.   )
  317. ;;;Examples:
  318. ;;;(vlxls-sheet-get-usedrange *xlapp* “Sheet1”) return: T
  319. ;;;(vlxls-sheet- get-usedrange *xlapp* “NewSheet”) return: T

  320. (Defun vlxls-cellid (id / xx id1 id2 Rtn) ;;;;cell id 轉換
  321.   (if (= (type id) 'list)
  322.     (setq id (vlxls-rangeid id))
  323.     )
  324.   (setq id (strcase id))
  325.   (if (null (setq xx (vl-string-search ":" id)))
  326.   (setq Rtn (list id ""))
  327.   (setq id1 (substr id 1 xx)
  328.         id2 (substr id (+ xx 2))
  329.         id1 (vlxls-rangeid id1)
  330.         id2 (vlxls-rangeid id2)
  331.         Rtn (list (vlxls-rangeid (list (min (car id1) (car id2))
  332.    (min (cadr id1) (cadr id2))))
  333.                   (vlxls-rangeid (list (max (car id1) (car id2))
  334.                                        (max (cadr id1) (cadr id2)))))
  335.         )
  336.     )
  337.   Rtn
  338.   )
  339. ;;;Examples:
  340. ;;;(vlxls-cellid ‘(3 14)) return: ("C14" "")
  341. ;;;(vlxls-cellid “D23”) return: ("D23" "")
  342. ;;;(vlxls-cellid “C12:F3”) return: ("C3" "F12")
  343. ;;;(vlxls-cellid “F15:G22”) return: ("F15" "G22")

  344. (Defun vlxls-rangeid (id / str->list list->str xid->str Rtn) ;;;;range id 轉換
  345.   (Defun str->list1 (str / ii xk xv rr pos x y)
  346.    (setq rr (strlen str))
  347.     (foreach ii     '("0" "1" "2" "3" "4" "5" "6" "7" "8" "9")
  348.      (if (setq pos (vl-string-search ii str))
  349.        (setq rr (min pos rr))
  350.        )
  351.       )
  352.     (setq x (substr str 1 rr)
  353.           y (substr str (1+ rr))
  354.           )
  355.     (if    (= (strlen x) 2)
  356.       (setq xk (- (ascii (substr x 1 1)) 64)
  357.             xv (- (ascii (substr x 2)) 64)
  358.             )
  359.       (setq xk 0
  360.             xv (- (ascii x) 64)
  361.             )
  362.       )
  363.     (list (+ (* xk 26) xv) (read y))
  364.     )
  365.   (Defun xid->str (IntNum / PosNum Nm-One)
  366.     (setq Nm-One (1- IntNum)
  367.           PosNum (/ Nm-One 26)
  368.           )
  369.     (if    (= PosNum 0)
  370.       (chr (+ 65 (rem Nm-One 26)))
  371.       (strcat (chr (+ 64 PosNum)) (chr (+ 65 (rem Nm-One 26))))
  372.       )
  373.     )
  374. (Defun list->str1 (idr / x y)
  375.   (setq x (car idr)
  376.         y (cadr idr)
  377.         x (xid->str x)
  378.         y (itoa y)
  379.         )
  380.   (strcat x y)
  381.   )
  382. (cond  ((= (type id) 'str) (setq Rtn (str->list1 id)))
  383.        ((= (type id) 'list) (setq Rtn (list->str1 id)))
  384.        )
  385.   Rtn
  386.   )
  387. ;;;Examples:
  388. ;;;(vlxls-rangeid ‘(3 14)) return: "C14"
  389. ;;;(vlxls-rangeid “D23”) return: (4 23)
  390. ;;;(vlxls-rangeid “DD23”) return: (108 23)

  391. (Defun vlxls-range-autofit (range);;自動調整范圍內存儲格
  392.       (equal (vlax-variant-value
  393.                (msxl-autofit
  394.                  (msxl-get-columns (msxl-get-Cells range))
  395.                  )
  396.                )
  397.              :vlax-true
  398.              )
  399.   )
  400. ;;;Examples:
  401. ;;;(vlxls-range-autofit (msxl-get-range *xlapp* “C12:F15”)) return: T
  402. ;;;(vlxls-range-autofit RangeObject) return: NIL

  403. (Defun vlxls-cell-put-active (xl id / Rtn);;范圍內激活
  404.   (if (= (type id) 'list)
  405.     (setq id (vlxls-rangeid id))
  406.     )
  407.   (msxl-activate (setq Rtn (msxl-get-range xl id)))
  408.   Rtn
  409.   )
  410. ;;;Examples:
  411. ;;;(vlxls-cell-put-active *xlapp* “C12:F15”) return: #<VLA-OBJECT Range 09d1998c>
  412. ;;;(vlxls-cell-put-active *xlapp* “F12”) return: #<VLA-OBJECT Range 06c389a2>

  413. (Defun vlxls-cell-get-value (xl id);;取得范圍內值并列表
  414.   (if (= (type id) 'list)
  415.     (setq id (vlxls-rangeid id))
  416.     )
  417.   (vlxls-variant->list
  418.     (msxl-get-value2 (msxl-get-range xl id))
  419.     )
  420.   )
  421. ;;;Examples:
  422. ;;;(vlxls-cell-get-value *xlapp* “C12”) return: “g”
  423. ;;;(vlxls-cell-get-value *xlapp* “C12:C12”) return: “g”
  424. ;;;(vlxls-cell-get-value *xlapp* “C12:C15”) return: (("g") ("") ("") (""))
  425. ;;;(vlxls-cell-get-value *xlapp* “C12:F12”) return: (("g" "ds" "" ""))
  426. ;;;(vlxls-cell-get-value *xlapp* “C12:F15”) return: (("g" "ds" "" "") ("" "" "g" "") ("" "" "" "") ("" "" "" ""))

  427. (Defun vlxls-cell-put-value (xl id Data / vllist-explode idx xx yy ary Rtn)
  428.   ;;;;;將信息輸入區域內
  429.   (Defun vllist-explode1 (lst)
  430.     (cond ((not lst) nil)
  431.           ((atom lst) (list lst))
  432.           ((append (vllist-explode1 (car lst))
  433.                    (vllist-explode1 (cdr lst))
  434.                    )))
  435.     )
  436.   (if (null id)
  437.     (setq id "A1")
  438.     )
  439.   (if (= (type id) 'list)
  440.     (setq id (vlxls-rangeid id))
  441.     )
  442.   (if (= (type (car Data)) 'LIST)
  443.     (setq ARY (vlax-make-safearray
  444.                 vlax-vbstring(cons 0 (1- (length Data)))
  445.                 (cons 1 (length (car Data)))
  446.                 )
  447.           XX  (1- (length (car Data)))
  448.           YY  (1- (length Data))
  449.           )
  450.     (setq ARY (vlax-make-safearray
  451.                 vlax-vbstring
  452.                 (cons 0 1)
  453.                 (cons 1 (length Data))
  454.                 )
  455.           XX  (1- (length Data))
  456.           YY  0)
  457.     )
  458.   (if (= xx yy 0)
  459.     (msxl-put-value2
  460.       (setq Rtn (msxl-get-range xl id))
  461.       (car (vllist-explode1 data))
  462.       )
  463.     (progn
  464.       (setq id (vlxls-cellid-calc id xx yy))
  465.       (msxl-put-value2
  466.         (setq Rtn (msxl-get-range xl id))
  467.         (vlax-safearray-fill ary data)
  468.         )
  469.       )
  470.     )
  471.   Rtn
  472.   )
  473. ;;;Examples:
  474. ;;;(vlxls-cell-put-value *xlapp* “C12” “xx”) return: #<VLA-OBJECT Range 093a7764>
  475. ;;;(vlxls-cell-put-value *xlapp* “C12:F3” “xx”) return: #<VLA-OBJECT Range 43c5ac64>
  476. ;;;(vlxls-cell-put-value *xlapp* “C12:D13” ‘((“zz” “xx”)(“xx” “zz”))) ereturn:

  477. (Defun vlxls-cellid-calc (id x y / idx) ;;;計算范圍
  478.   (setq   id  (car (vlxls-cellid id))
  479.           idx (vlxls-rangeid id)
  480.           x   (+ x (car idx))
  481.           x   (if    (< x 1)
  482.                 1
  483.                 x)
  484.           y   (+ y (cadr idx))
  485.           y   (if    (< y 1)
  486.                 1
  487.                 y)
  488.           idx (vlxls-rangeid (list x y))
  489.           id  (vlxls-cellid (strcat id ":" idx))
  490.           id  (strcat (car id) ":" (cadr id))
  491.           )
  492.   id
  493.   )
  494. ;;;Examples:
  495. ;;;(vlxls-cellid-calc “C12” 2 20) return: "C12:E32"
  496. ;;;(vlxls-cellid-calc ‘(2 23) 2 -120) return: "B1:D23"

  497. (Defun vlxls-get-row-value (xl id len / vllist-explode Rtn);;取出單列的內容
  498.   (Defun vllist-explode4  (lst)
  499.     (cond ((not lst) nil)
  500.           ((atom lst) (list lst))
  501.           ((append (vllist-explode4 (car lst))
  502.                    (vllist-explode4 (cdr lst))
  503.                    )
  504.            )
  505.           )
  506.     )
  507.   (if (> len 0)
  508.     (setq id (vlxls-cellid-calc id (1- len) 0))
  509.     (setq id (vlxls-cellid-calc id (1+ len) 0))
  510.     )
  511.   (setq Rtn (vllist-explode4 (vlxls-cell-get-value xl id)))
  512.   Rtn
  513.   )
  514. ;;;Examples:
  515. ;;;(vlxls-get-row-value *xlapp* “C12” 2) return: ("zz" "xxx")
  516. ;;;(vlxls-get-row-value *xlapp* “C12” -20) return: ("" "" "zz")

  517. (Defun vlxls-put-row-value (xl id data flg / Rtn);;;單列輸入信息并且flg為t則自動調整尺寸
  518.   (if (= (type data) 'str)
  519.     (setq data (list data))
  520.     )
  521.   (setq   id (car (vlxls-cellid id))
  522.           id (vlxls-cellid-calc id (1- (length data)) 0)
  523.           )
  524.   (setq Rtn (vlxls-cell-put-value xl id (list data)))
  525.   (if flag
  526.   (vlxls-range-autofit
  527.     rtn
  528.     ))
  529.   Rtn
  530.   )
  531. ;;;Examples:
  532. ;;;(vlxls-put-row-value *xlapp* “C12” “abc”) return:#<VLA-OBJECT Range 2a621cac>
  533. ;;;(vlxls-put-row-value *xlapp* ‘(12 3) “abc”) return:#<VLA-OBJECT Range 7a36c491>
  534. ;;;(vlxls-put-row-value *xlapp* “C12” ‘("zz" "xxx")) return:#<VLA-OBJECT Range 09d1da1c>
  535. ;;;(vlxls-put-row-value *xlapp* ‘(12 3) ‘("zz" "xxx")) return:#<VLA-OBJECT Range 0a26c4f3>

  536. (Defun vlxls-get-column-value (xl id len / vllist-explode Rtn);;取出單欄信息
  537.   (Defun vllist-explode3       (lst)
  538.     (cond ((not lst) nil)
  539.           ((atom lst) (list lst))
  540.           ((append (vllist-explode3 (car lst))
  541.                    (vllist-explode3 (cdr lst))
  542.                    )
  543.            )
  544.           )
  545.     )
  546.   (setq id (car (vlxls-cellid id)))
  547.   (if (> len 0)
  548.     (setq id (vlxls-cellid-calc id 0 (1- len)))
  549.     (setq id (vlxls-cellid-calc id 0 (1+ len)))
  550.     )
  551.   (setq Rtn (vllist-explode3 (vlxls-cell-get-value xl id)))
  552.   Rtn
  553.   )
  554. ;;;Examples:
  555. ;;;(vlxls-get-column-value *xlapp* “C12” 2) return: ("zz" "sdfsdf")
  556. ;;;(vlxls-get-column-value *xlapp* “C12” -20) return: ("" "" "xxx" "xxx" "xxx" "xxx" "xxx" "xxx" "xxx" "xxx" "xxx" "zz")

  557. (Defun vlxls-put-column-value (xl id data flg / item Rtn);;;單欄輸入信息并且flg為t則自動調整尺寸
  558.   (if (= (type data) 'str)
  559.     (setq data (list data))
  560.     )
  561.   (setq   id (car (vlxls-cellid id))
  562.           id (vlxls-cellid-calc id 0 (1- (length data)))
  563.           )
  564. (foreach item    data
  565.    (setq Rtn (cons (list item) Rtn)))
  566.   (setq Rtn (vlxls-cell-put-value xl id (reverse Rtn)))
  567. (if flg
  568.    (vlxls-range-autofit
  569.     rtn
  570.    ))
  571.   Rtn
  572.   )
  573. ;;;Examples:
  574. ;;;(vlxls-put-column-value *xlapp* “C12” “abc”) return: #<VLA-OBJECT Range 049c521b>
  575. ;;;(vlxls-put-column-value *xlapp* ‘(12 3) “abc”) return: #<VLA-OBJECT Range 0235cba1>
  576. ;;;(vlxls-put-column-value *xlapp* “C12” ‘("zz" "xxx")) return: #<VLA-OBJECT Range 09d1da1c>
  577. ;;;(vlxls-put-column-value *xlapp* ‘(12 3) ‘("zz" "xxx")) return: #<VLA-OBJECT Range 0a26c4f3>

  578. (Defun vlxls-cell-get-aci (xl id)
  579.   (vlxls-color-eci->aci
  580.     (vlax-variant-value
  581.       (msxl-get-colorindex
  582.         (msxl-get-interior (msxl-get-range xl id))
  583.         )
  584.       )
  585.     )
  586.   )
  587. ;;;Examples:
  588. ;;;(vlxls-cell-get-aci *xlapp* “C12”) return:256
  589. ;;;(vlxls-cell-get-aci *xlapp* ‘(12 3)) return:15

  590. (Defun vlxls-cell-put-aci (xl id aci / Rtn)
  591.   (if (null aci)
  592.     (msxl-put-colorindex
  593.       (msxl-get-interior (setq Rtn (msxl-get-range xl id)))
  594.       (vlax-make-variant -4142)
  595.       )
  596.     (msxl-put-colorindex
  597.       (msxl-get-interior (setq Rtn (msxl-get-range xl id)))
  598.       (vlxls-color-aci->eci aci)
  599.       )
  600.     )
  601.   Rtn
  602.   )
  603. ;;;Examples:
  604. ;;;(vlxls-cell-put-aci *xlapp* “C12” 6) return: #<VLA-OBJECT Range 09d1369c>
  605. ;;;(vlxls-cell-put-aci *xlapp* “C12” nil) return: #<VLA-OBJECT Range 09d1369c>

  606. (Defun vlxls-text-get-aci (xl id)
  607.   (vlxls-color-eci->aci
  608.     (vlax-variant-value
  609.       (msxl-get-colorindex
  610.         (msxl-get-font (msxl-get-range xl id))
  611.         )
  612.       )
  613.     )
  614.   Rtn
  615.   )
  616. ;;;Examples:
  617. ;;;(vlxls-text-get-aci *xlapp* “C12”) return: 256
  618. ;;;(vlxls-text-get-aci *xlapp* ‘(12 3)) return: 15

  619. (Defun vlxls-text-put-aci (xl id aci / Rtn)
  620.    (if (null aci)
  621.      (msxl-put-colorindex
  622.        (msxl-get-font (setq Rtn (msxl-get-range xl id)))
  623.        (vlax-make-variant -4105)
  624.        )
  625.      (msxl-put-colorindex
  626.        (msxl-get-font (setq Rtn (msxl-get-range xl id)))
  627.        (vlxls-color-aci->eci aci)
  628.        )
  629.      )
  630.   Rtn
  631.   )
  632. ;;;Examples:
  633. ;;;(vlxls-text-put-aci *xlapp* “C12” 6) return: #<VLA-OBJECT Range 09d1369c>
  634. ;;;(vlxls-text-put-aci *xlapp* “C12” nil) return: #<VLA-OBJECT Range 09d1369c>

  635. (Defun vlxls-text-get-prop(xl id / Cell Font DXF1 DXF7 DXF40 DXF72 DXF62 DXF420 Rtn)
  636.   ;;;;取得單元格文字相關信息
  637.   (setq   id     (car (vlxls-cellid id))
  638.           cell   (msxl-get-range xl id)
  639.           font   (msxl-get-font cell)
  640.           DXF7   (vlax-variant-value (msxl-get-name Font))
  641.           DXF40  (vlax-variant-value (msxl-get-size Font))
  642.           DXF72  (vlax-variant-value (msxl-get-HorizontalAlignment Cell)
  643.                    )
  644.           DXF72  (cond ((= DXF72 -4152) 11)
  645.                        ((= DXF72 -4108) 10)
  646.                        (t 9)
  647.                        )
  648.           DXF62  (vlxls-color-eci->aci
  649.                    (vlax-variant-value (msxl-get-colorIndex Font))
  650.                    )
  651.           DXF420 (vlxls-color-eci->truecolor
  652.                    (vlax-variant-value (msxl-get-colorIndex Font)))
  653.           Rtn    (list (cons 0 (strcase id))
  654.                        (cons 7 DXF7)(cons 40 DXF40)(cons 62 DXF62)
  655.                        (cons 72 DXF72)(cons 420 DXF420)))
  656.   Rtn
  657.   )
  658. ;;;Examples:
  659. ;;;(vlxls-text-get-prop *xlapp* “C12”) return:((0 . "C12") (7 . "Arial") (40 . 12.0) (62 . 256) (72 . 9) (420 . 16711935))
  660. ;;;(vlxls-text-get-prop *xlapp* ‘(2 10)) return:((0 . "B10") (7 . "Arial") (40 . 12.0) (62 . 256) (72 . 11) (420 . 16711935))

  661. (Defun vlxls-cell-get-prop(xl id / range left top width height dxf10 Rtn)
  662.   ;;;;取得單元格信息
  663.   (if (vlxls-cell-merge-p xl id)
  664.      (setq id (vlxls-cell-get-mergeid xl id))
  665.     )
  666.   (setq   range  (msxl-get-range xl id)
  667.           left   (vlax-variant-value (msxl-get-left Range))
  668.           top    (vlax-variant-value (msxl-get-top Range))
  669.           width  (vlax-variant-value (msxl-get-width Range))
  670.           height (vlax-variant-value (msxl-get-height Range))
  671.           dxf10  (list left top)
  672.           Rtn    (list (cons 0 (strcase id))
  673.                        (cons 1 (vlxls-cell-get-value xl id))
  674.                        (cons 10 dxf10)
  675.                        (cons 41 width)
  676.                        (cons 42 height)
  677.                        (cons -1 (vlxls-text-get-prop xl id))
  678.                        )
  679.           )
  680.   Rtn
  681.   )
  682. ;;;Examples:
  683. ;;;(vlxls-cell-get-prop *xlapp* “C12:F14”) return:((0 . "C12:F14") (1 ("zz" "xxx" "xxx" "xxx") ("sdfsdf" "sdfsdf" "sdfsdf" "sdfsdf")
  684. ;;;          ("sdfsdf" "sdfsdf" "sdfsdf" "sdfsdf")) (10 108.0 156.75) (41 . 156.0) (42 . 42.75) (-1 (0 . "C12") (7 . "Arial")
  685. ;;;          (40 . 12.0) (62 . 256) (72 . 9) (420 . 16711935)))
  686. ;;;(vlxls-cell-get-prop *xlapp* “B8”) return: ((0 . "B8") (1 . "sdg") (10 54.0 99.75) (41 . 54.0) (42 . 14.25) (-1 (0 . "B8")
  687. ;;;    (7 . "Arial") (40 . 12.0) (62 . 256) (72 . 10) (420 . 16711935)))

  688. (Defun vlxls-cell-border (xl id flg / bdr);;;外框線
  689.   (if flg
  690.     (msxl-put-value
  691.       (msxl-get-borders
  692.         (msxl-get-range xl id)
  693.         )
  694.       1
  695.       )
  696.     (msxl-put-value
  697.       (msxl-get-borders
  698.         (msxl-get-range xl id)
  699.         )
  700.       'linestyle
  701.         msxl-xlnone
  702.       )
  703.     )
  704.   )
  705. ;;;Examples:
  706. ;;;(vlxls-cell-border *xlapp* “C12:F14” T) return:NIL
  707. ;;;(vlxls-cell-border *xlapp* “B8” NIL) return:NIL

  708. (Defun vlxls-cell-merge      (xl id / vllist-explode Val Rtn)
  709.   ;;;;;;;;;合并單元格
  710.   (Defun vllist-explode2       (lst)
  711.     (cond ((not lst) nil)
  712.           ((atom lst) (list lst))
  713.           ((append (vllist-explode2 (car lst))
  714.                    (vllist-explode2 (cdr lst))
  715.                    )
  716.            )
  717.           )
  718.     )
  719.   (setq val (vllist-explode2 (vlxls-cell-get-value xl id)))
  720.   (while (vl-position "" val)
  721.     (setq val (vl-remove "" val))
  722.     )
  723.   (setq   val (car val)
  724.           Rtn (msxl-get-range xl id)
  725.           )
  726.   (msxl-clear Rtn)
  727.   (msxl-merge Rtn nil)
  728.   (msxl-put-value2 Rtn Val)
  729.   (msxl-put-HorizontalAlignment Rtn -4108)
  730.   Rtn
  731.   )
  732. ;;;Examples:
  733. ;;;(vlxls-cell-merge *xlapp* “C12:F14”) return: #<VLA-OBJECT Range 0023ab7c>

  734. (Defun vlxls-cell-unmerge (xl id / Rtn);;;取消合并單元格
  735.   (if (vlxls-cell-merge-p xl id)
  736.     (progn
  737.       (vlax-invoke-method (msxl-get-range xl id) 'unmerge)
  738.       (setq Rtn (msxl-get-range xl id))
  739.       )
  740.     )
  741.   Rtn
  742.   )
  743. ;;;Examples:
  744. ;;;(vlxls-cell-unmerge *xlapp* “C12:F14”) return:#<VLA-OBJECT Range 0023ab7c>
  745. ;;;(vlxls-cell-unmerge *xlapp* “E14”) return:#<VLA-OBJECT Range 09ce72e4>

  746. (Defun vlxls-cell-merge-p (xl id);;;判斷單元格是否合并
  747.   (equal (vlax-variant-value
  748.            (msxl-get-mergecells (msxl-get-range xl id))
  749.            )
  750.          :vlax-true
  751.          )
  752.   )
  753. ;;;Examples:
  754. ;;;(vlxls-cell-merge-p *xlapp* “C12:F14”) return:T
  755. ;;;(vlxls-cell-merge-p *xlapp* “E14”) return:NIL

  756. (Defun vlxls-cell-get-mergeid (XL ID / Rtn);;;取得單元格合并的范圍
  757.   (if (vlxls-cell-merge-p xl id)
  758.     (progn
  759.       (msxl-select (msxl-get-range xl id))
  760.       (setq Rtn (vlxls-range-getid (msxl-get-selection xl)))
  761.       )
  762.     )
  763.   Rtn
  764.   )
  765. ;;;Examples:
  766. ;;;(vlxls-cell-get-mergeid *xlapp* “C12:F14”) return: "B9:G19”
  767. ;;;(vlxls-cell-get-mergeid *xlapp* “E14”) return: "A11:G19

  768. (Defun vlxls-range-getID (range / col row dx dy);;;取得單元格地址
  769.   (setq   dx  (vlxls-get-property range "MergeArea.Rows.Count")
  770.           dy  (vlxls-get-property range "MergeArea.Columns.Count")
  771.           row (vlxls-get-property range "MergeArea.Row")
  772.           col (vlxls-get-property range "MergeArea.Column")
  773.           )
  774.   (strcat (vlxls-rangeid (list col row))
  775.           ":"
  776.           (vlxls-rangeid (list (1- (+ col dy)) (1- (+ row dx)))))
  777. )
  778. ;;;Examples:
  779. ;;;(vlxls-range-getid RangeObject) return: ”C12:G19”
  780. ;;;(vlxls-range-getid RangeObject) return: ”B16:B16”

  781. (Defun vlxls-range-size      (range / xl row col rrr ccc xxx yyy);;;;取得單元范圍尺寸
  782.   (setq   xl  (msxl-get-parent range)
  783.           Row (msxl-get-count (msxl-get-rows Range))
  784.           Col (msxl-get-count (msxl-get-columns Range))
  785.           RRR (1- (msxl-get-row Range))
  786.           CCC (msxl-get-column Range)
  787.           )
  788.   (repeat Row
  789.     (setq yyy (cons   (vlax-variant-value
  790.                         (msxl-get-height
  791.                           (msxl-get-range
  792.                             xl
  793.                             (vlxls-rangeid (list CCC (setq RRR (1+ RRR))))
  794.                             )
  795.                           )
  796.                         )
  797.                       yyy
  798.                       )
  799.           )
  800.     )
  801.   (setq   RRR (msxl-get-row Range)
  802.           CCC (1- (msxl-get-column Range))
  803.           )
  804.   (repeat Col
  805.     (setq xxx (cons   (vlax-variant-value
  806.                         (msxl-get-width
  807.                           (msxl-get-range
  808.                             xl
  809.                             (vlxls-rangeid (list (setq CCC (1+ CCC)) RRR))
  810.                             )
  811.                           )
  812.                         )
  813.                       xxx
  814.                       )
  815.           )
  816.     )
  817.   (list (reverse xxx) (reverse yyy))
  818.   )
  819. ;;;Examples:
  820. ;;;(vlxls-range-size RangeObject) return: ((27.0 27.0 110.25 51.0 69.75) (14.25 14.25 14.25 14.25 14.25 57.0 14.25))

  821. (Defun vlxls-Rangevalue->SafeArray (Data / XSub_GetXY XSub_GetMinMaxID xsub-MergeID->List
  822.                                     MinID MaxID ID ID1 ID2 IDN X minid xy Y Rtn Item)
  823.   ;;;;;;;;;;;;;安全數組
  824.   (Defun xsub-MergeID->List1 (ID / KK ID1 ID2 IDX IDY Rtn)
  825.     (Setq ID (strcase ID))
  826.     (if    (setq KK (vl-string-search ":" ID))
  827.       (setq ID1   (substr ID 1 KK)
  828.             ID2  (substr ID (+ 2 KK))
  829.             )
  830.       (setq ID1   ID
  831.             ID2  ID)
  832.       )
  833.     (setq ID1 (vlxls-rangeid ID1)
  834.           ID2 (vlxls-rangeid ID2)
  835.           IDX (vlxls-rangeid
  836.                 (list (min (nth 0 ID1) (nth 0 ID2))
  837.                       (min (nth 1 ID1) (nth 1 ID2))
  838.                       )
  839.                 )
  840.           IDY
  841.            (vlxls-rangeid
  842.              (list (max (nth 0 ID1) (nth 0 ID2))
  843.                    (max (nth 1 ID1) (nth 1 ID2))
  844.                    )
  845.              )
  846.           Rtn (list IDX IDY)
  847.           )
  848.     Rtn
  849.     )
  850.   (Defun XSub_GetXY1 (ID SID / S10 S11 DX DY Rtn)
  851.     (setq S10 (nth 0 MinID)
  852.           S11 (nth 1 MinID)
  853.           ID  (vlxls-rangeid ID)
  854.           DX  (- (nth 0 ID) S10)
  855.           DY  (- (nth 1 ID) S11)
  856.           Rtn (list DX DY)
  857.           )
  858.     Rtn
  859.     )
  860.   (Defun XSub_GetMinMaxID1 (ID1 ID MinorMax / X Y X1 Y1 Rtn)
  861.     (if    (null ID)
  862.       (setq Rtn ID1)
  863.       (progn
  864.         (setq ID1 (vlxls-rangeid ID1)
  865.               ID  (vlxls-rangeid ID)
  866.               X1  (nth 0 ID1)
  867.               Y1  (nth 1 ID1)
  868.               X    (nth 0 ID)
  869.               Y   (nth 1 ID)
  870.               )
  871.         (if (null MinorMax)
  872.           (setq Rtn (vlxls-rangeid (list (min X X1) (min Y Y1))))
  873.           (setq Rtn (vlxls-rangeid (list (max X X1) (max Y Y1))))
  874.           )
  875.         )
  876.       )
  877.     Rtn
  878.     )
  879.   (foreach Item    Data
  880.     (setq ID (strcase (car Item)))
  881.     (if    (vl-string-search ":" ID)
  882.       (setq IDN (xsub-MergeID->List1 ID))
  883.       (setq IDN (list ID))
  884.       )
  885.     (foreach ID    IDN
  886.       (setq MinID (XSub_GetMinMaxID1 ID MinID nil)
  887.             MaxID (XSub_GetMinMaxID1 ID MaxID T)
  888.            )
  889.       )
  890.     )
  891.   (setq   MinID (vlxls-rangeid MinID)
  892.           MaxID (vlxls-rangeid MaxID)
  893.           X     (- (nth 0 MaxID) (nth 0 MinID))
  894.           Y     (- (nth 1 MaxID) (nth 1 MinID))
  895.           Rtn   (vlax-make-safearray
  896.                   vlax-vbstring
  897.                   (cons 0 Y)
  898.                   (cons 1 (1+ X))
  899.                   )
  900.           )
  901.   (foreach Item    Data
  902.     (setq ID (strcase (car Item)))
  903.     (if    (vl-string-search ":" ID)
  904.       (setq IDN (xsub-MergeID->List1 ID))
  905.       (setq IDN (list ID))
  906.       )
  907.     (foreach ID    IDN
  908.       (setq XY (XSub_GetXY1 ID MinID))
  909.       (vlax-safearray-put-element
  910.         Rtn
  911.         (nth 1 XY)
  912.         (1+ (nth 0 XY))
  913.         (cdr Item)
  914.         )
  915.       )
  916.     )
  917.   Rtn
  918.   )
  919. ;;;Examples:
  920. ;;;(vlxls-rangevalue->safearray ‘((“A1” . “aaa”)(“B4” . “ccc”))) return: #<safearray...>
  921. ;;;(vlxls-variant->list (vlxls-rangevalue->safearray '(("A1" . "aaa")("B4" . "ccc")))) return: (("aaa" "") ("" "") ("" "") ("" "ccc"))

  922. (Defun vlxls-get-property (top prop / item Rtn);vlstring->list
  923.   ;;;;取得多重屬性
  924.   (Defun vlstring->list (str st / lst e)
  925.     (setq str (strcat str st))
  926.     (while (vl-string-search st str)
  927.       (setq
  928.         lst
  929.          (append lst (list (substr str 1 (vl-string-search st str))))
  930.         )
  931.       (setq
  932.         str
  933.          (substr str (+ (1+ (strlen st)) (vl-string-search st str)))
  934.         )
  935.       )
  936.     (if    lst
  937.       (mapcar '(lambda (e) (vl-string-trim " " e)) lst)
  938.       )
  939.     )
  940.   (cond  ((= (type prop) 'sym)
  941.           (setq Rtn (vlax-get-property top prop))
  942.           )
  943.          ((= (type prop) 'str)
  944.           (if (null (vl-string-search "." prop))
  945.             (setq Rtn (vlax-get-property top prop))
  946.             (foreach item (vlstring->list prop ".")
  947.               (if (null Rtn)
  948.                 (setq Rtn (vlax-get-property top item))
  949.                 (setq Rtn (vlax-get-property Rtn item))
  950.                 ))))
  951.          )
  952.   (cond  ((= (type Rtn) 'variant)
  953.           (setq Rtn (vlax-variant-value Rtn))
  954.           )
  955.          ((= (type Rtn) 'safearray)
  956.           (setq Rtn (vlxls-variant->list Rtn))
  957.           )
  958.          )
  959.   Rtn
  960.   )
  961. ;;;Examples:
  962. ;;;(vlxls-get-property RangeObject “Application.ActiveSheet.Name”) return: ”Sheet1”
  963. ;;;(vlxls-get-property RangeObject “MergeArea.Columns.Count”) return: 3

  964. (setq *xls-color*
  965.        (list (list 1 18 0)
  966.              (list 2 7 1677215)
  967.              (list 3 1 16711680)
  968.              (list 4 3 65280)
  969.              (list 5 5 255)
  970.              (list 6 2 16776960)
  971.              (list 7 6 16711935)
  972.              (list 8 4 65535)
  973.              (list 9 16 8323072)
  974.              (list 10 96 32512)
  975.              (list 11 176 127)
  976.              (list 12 56 8355584)
  977.              (list 13 216 8323199)
  978.              (list 14 136 32639)
  979.              (list 15 9 12566463)
  980.              (list 16 8 8355711)
  981.              (list 17 161 9476095)
  982.              (list 18 237 9449568)
  983.              (list 19 7 1677167)
  984.              (list 20 254 12648447)
  985.              (list 21 218 6291552)
  986.              (list 22 11 16744319)
  987.              (list 23 152 24768)
  988.              (list 24 254 13617407)
  989.              (list 25 176 127)
  990.              (list 26 6 16711935)
  991.              (list 27 2 16776960)
  992.              (list 28 4 65535)
  993.              (list 29 216 8323199)
  994.              (list 30 16 8323072)
  995.              (list 31 136 32639)
  996.              (list 32 5 255)
  997.              (list 33 140 51455)
  998.              (list 34 254 12648447)
  999.              (list 35 254 13631439)
  1000.              (list 36 51 16777104)
  1001.              (list 37 151 9488639)
  1002.              (list 38 221 16750799)
  1003.              (list 39 191 13605119)
  1004.              (list 40 31 16763024)
  1005.              (list 41 150 3105023)
  1006.              (list 42 132 3131584)
  1007.              (list 43 62 9488384)
  1008.              (list 44 40 16762880)
  1009.              (list 45 30 16750336)
  1010.              (list 46 30 16738048)
  1011.              (list 47 165 6317968)
  1012.              (list 48 252 9475984)
  1013.              (list 49 148 12384)
  1014.              (list 50 105 3184736)
  1015.              (list 51 98 12032)
  1016.              (list 52 48 3158016)
  1017.              (list 53 24 9449472)
  1018.              (list 54 237 9449311)
  1019.              (list 55 177 3158160)
  1020.              (list 56 250 3092527)
  1021.              )
  1022.       *Chinese* t
  1023.       )
  1024. (if vl-load-com
  1025.   (vl-load-com))
  1026. (if vl-arx-import
  1027.   (foreach item    '(ACAD_COLORDLG       ACAD_truecolordlg
  1028.                      ACAD_STRLSORT      INITDIA
  1029.                      ACAD-POP-DBMOD     ACAD-PUSH-DBMOD
  1030.                      STARTAPP            layoutlist
  1031.                      )
  1032.     (vl-arx-import item)
  1033.     )
  1034.   )
  1035. (setq item   nil
  1036.       *xls-ver*     "1.1.40715"
  1037.       )
  1038. (princ
  1039.   (strcat "\n VLAE:VLXLS Freebie API Version " *xls-ver*)
  1040.   )
  1041. (princ
  1042.   "\n Copyright(C) 1994-2005 KozMos Inc. All rights reserved"
  1043.   )
  1044. (princ)

  1045. (defun vlxls-ScreenUpdating-Off  (*xlapp*)
  1046.   (vlax-put-property *xlapp* 'ScreenUpdating 0))
  1047. (defun vlxls-ScreenUpdating-On  (*xlapp*)
  1048.   (vlax-put-property *xlapp* 'ScreenUpdating -1))

  1049. ;;*************************************************************************
  1050. ;;; 模塊: vlxls-Excel-ColumnWidth
  1051. ;;; 描述: 調整寬度col為width
  1052. ;;; 參數: sheet (object)
  1053. ;;; 示例: (vlxls-Excel-ColumnWidth xlapp 2 12);;調整B欄寬為12
  1054. ;;;*************************************************************************

  1055. (defun vlxls-ColumnWidth(xlapp col width / sheet cell)
  1056.   (setq sheet (vlax-get-property xlapp "ActiveSheet"))
  1057.   (vlax-put-property (setq cell (vlxls-get-cell sheet 1 col)) "ColumnWidth"
  1058. width)
  1059.   )

  1060. ;;;*************************************************************************
  1061. ;;; 模塊: mSX-Excel-RowHeight
  1062. ;;; 描述: 調整列高row為height
  1063. ;;; 參數: sheet (object)
  1064. ;;; 示例: (mSX-Excel-ColumnWidth xlapp 3 15);;調整3列高為15
  1065. ;;;*************************************************************************

  1066. (defun vlxls-RowHeight(xlapp row height / sheet cell)
  1067.   (setq sheet (vlax-get-property xlapp "ActiveSheet"))
  1068.   (vlax-put-property (setq cell (vlxls-get-cell sheet row 1)) "RowHeight"
  1069. height)
  1070.   )

  1071. (defun vlxls-get-cell  (obj row col / item cells)
  1072.   (setq item (vlax-get-property
  1073.     (setq cells (vlax-get-property obj "Cells"))
  1074.     "Item"
  1075.     (vlax-make-variant row)
  1076.     (vlax-make-variant col)))
  1077.   (vlax-release-object cells)
  1078.   (vlax-variant-value item))

  1079. (defun vlxls-put-pagesetup(xlapp top bot lef rig hea fot flh flv);;設置版面
  1080.   (setq sheet (vlax-get-property xlapp "ActiveSheet"))
  1081.   (setq page (vlax-get-property sheet "pagesetup"))
  1082.   (vlax-put-property page "footermargin" (* fot 28.3465))
  1083.   (vlax-put-property page "headermargin" (* hea 28.3465))
  1084.   (vlax-put-property page "leftmargin" (* lef 28.3465))
  1085.   (vlax-put-property page "rightmargin" (* 28.3465 rig))
  1086.   (vlax-put-property page "topmargin" (* top 28.3465))
  1087.   (vlax-put-property page "bottommargin" (* bot 28.3465))
  1088.   (vlax-put-property page "CenterHorizontally" (* 28.3465 flh))
  1089.   (vlax-put-property page "CenterVertically" (* flv 28.3465))
  1090.   )

  1091. ;;;*************************************************************************
  1092. ;;; 模塊: vlxls-Excel-cellfontname
  1093. ;;; 描述: 更改單元格字體
  1094. ;;; 參數: row col name
  1095. ;;; 示例: (vlxls-Excel-cellfontname 2 3 "新細明體");;更改單元格C2字體為"新細明體"
  1096. ;;;*************************************************************************

  1097. (defun vlxls-Excel-cellfontname(xlapp row col name / sheet cell)
  1098.   (setq sheet (vlax-get-property xlapp "ActiveSheet"))
  1099.   (vlax-put-property(vlax-get-property (setq cell (msx-get-cell sheet row col)) "font"
  1100. ) "name" name
  1101.   ))
  1102. ;;;*************************************************************************
  1103. ;;; 模塊: vlxls-Excel-cellcolor
  1104. ;;; 描述: 更改單元格顏色
  1105. ;;; 參數: row col color
  1106. ;;; 示例: (vlxls-Excel-cellcolor2 3 14);;更改單元格C2為14號色
  1107. ;;;*************************************************************************

  1108. (defun vlxls-Excel-cellcolor(xlapp row col color / sheet cell)
  1109.   (setq sheet (vlax-get-property xlapp  "ActiveSheet"))
  1110.   (setq cell (vlxls-get-cell sheet row col))
  1111.   (msxl-put-ColorIndex (msxl-get-Interior cell) color))

  1112. ;;;*************************************************************************
  1113. ;;; 模塊: vlxls-Excel-textcolor
  1114. ;;; 描述: 更改單元格文字顏色
  1115. ;;; 參數: row col color
  1116. ;;; 示例: (vlxls-Excel-textcolor 2 3 14);;更改單元格C2文字為14號色
  1117. ;;;*************************************************************************

  1118. (defun vlxls-Excel-textcolor(xlapp row col color / sheet cell)
  1119.   (setq sheet (vlax-get-property xlapp "ActiveSheet"))
  1120.   (setq cell (vlxls-get-cell sheet row col))
  1121.   (vlax-put-property (vlax-get-property cell "font") "ColorIndex" color))
  1122. ;;;*************************************************************************
  1123. ;;; 模塊: vlxls-Excel-textsize
  1124. ;;; 描述: 更改單元格文字大小
  1125. ;;; 參數: row col size
  1126. ;;; 示例: (vlxls-Excel-textsize 2 3 18);;更改單元格C2文字為18號字大小
  1127. ;;;*************************************************************************

  1128. (defun vlxls-Excel-textsize(xlapp row col size / sheet cell)
  1129.   (setq sheet (vlax-get-property xlapp "ActiveSheet"))
  1130.   (setq cell (vlxls-get-cell sheet row col))
  1131.   (vlax-put-property (vlax-get-property cell "font") "Size" size))
  1132. ;;;*************************************************************************
  1133. ;;; 模塊: vlxls-Excel-textunderline
  1134. ;;; 描述: 更改單元格文字下畫線
  1135. ;;; 參數: row col size
  1136. ;;; 示例: (vlxls-Excel-textunderline 2 3 1);;更改單元格C2文字無下划線
  1137. ;;;*************************************************************************

  1138. (defun vlxls-Excel-textunderline(xlapp row col underline / sheet cell)
  1139.   (setq sheet (vlax-get-property xlapp "ActiveSheet"))
  1140.   (setq cell (vlxls-get-cell sheet row col))
  1141.   (vlax-put-property (vlax-get-property cell "font") "Underline" underline))
  1142. ;;;;;注:   underline 1---------無下划線
  1143. ;;;;;                2---------單線
  1144. ;;;;;                3---------雙線
  1145. ;;;;;                4---------會計用單線
  1146. ;;;;;                5---------會計用雙線


  1147. ;;;*************************************************************************
  1148. ;;; 模塊: vlxls-Excel-fontstyle
  1149. ;;; 描述: 更改單元格文字形式
  1150. ;;; 參數: row col color
  1151. ;;; 示例: (vlxls-Excel-fontstyle 2 3 "粗體");;更改單元格C2文字為14粗體
  1152. ;;;*************************************************************************

  1153. (defun vlxls-Excel-fontstyle(xlapp row col style / sheet cell)
  1154.   (setq sheet (vlax-get-property xlapp "ActiveSheet"))
  1155.   (setq cell (vlxls-get-cell sheet row col))
  1156.   (vlax-put-property (vlax-get-property cell "font") "FontStyle" style))
  1157. ;;;*************************************************************************
  1158. ;;; 模塊: vlxls-Excel-fontspecial
  1159. ;;; 描述: 更改單元格文字特殊效果
  1160. ;;; 參數: row col color
  1161. ;;; 示例: (vlxls-Excel-fontspecial 2 3 "Strikethrough" item);;更改單元格C2文字特殊效果為刪線
  1162. ;;;        "Superscript"為上標 "Subscript" 為下標 (item設置為0則停用,-1為啟用)
  1163. ;;;*************************************************************************

  1164. (defun vlxls-Excel-fontspecial(xlapp row col special item / sheet cell)
  1165.   (setq sheet (vlax-get-property xlapp "ActiveSheet"))
  1166.   (setq cell (vlxls-get-cell sheet row col))
  1167.   (vlax-put-property (vlax-get-property cell "font") special item))
  1168. ;;;*************************************************************************
  1169. ;;; 模塊: vlxls-Excel-textAlignment
  1170. ;;; 描述: 更改單元格文字對齊方式
  1171. ;;; 參數: row col color hal val
  1172. ;;; 示例: (vlxls-Excel-textAlignment 2 3 1 -4108);;更改單元格C2文字對齊方式水平方向一般﹐垂直置中
  1173. ;;;*************************************************************************

  1174. (defun vlxls-Excel-textAlignment(xlapp row col hal val / sheet cell)
  1175.   (setq sheet (vlax-get-property xlapp  "ActiveSheet"))
  1176.   (setq cell (vlxls-get-cell sheet row col))
  1177.   (vlax-put-property  cell  "HorizontalAlignment" hal)
  1178.   (vlax-put-property  cell  "VerticalAlignment" val))

  1179. ;;;注:水平方式  1    ----------一般               
  1180. ;;;;;;;;;      -4131----------左縮排 ;;;;或2
  1181. ;;;;;;;;;      -4108----------置中對齊 ;;或3
  1182. ;;;;;;;;;      -4152----------靠右對齊 ;;或4
  1183. ;;;;;;;;;      5    ----------填滿     ;;或5
  1184. ;;;;;;;;;      -4130----------水平對齊 ;;或6
  1185. ;;;;;;;;;          7----------跨欄置中  
  1186. ;;;;;;;;;      -4117----------分散對齊  ;;或8

  1187. ;;;注:垂直方式  -4160 ----------靠上        或1      
  1188. ;;;;;;;;;       -4108----------置中對齊     或2
  1189. ;;;;;;;;;       -4107----------靠下         或3
  1190. ;;;;;;;;;       -4130----------垂直對齊     或4
  1191. ;;;;;;;;;       -4117 ----------分散對齊    或5


此乃本人积累下来的一些小小经验.希望对大家有用,因公司
用的是繁体系统,故以上有些文字为繁体望见谅,大家可以自己回
去转化一下!
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
发表于 2005-3-26 21:49:53 | 显示全部楼层
太有用了.
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2005-3-26 21:53:29 | 显示全部楼层
正发愁呢,就来了,谢谢
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2005-3-27 01:24:11 | 显示全部楼层
强烈要求给楼主加分,呵呵,楼主该感谢我一下了...

你现在中山还好吗?看到此信息加我QQ:22903161
手机号改了,QQ上联系
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2005-3-27 15:53:46 | 显示全部楼层
如何使用,请高手指点!
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-3-28 10:08:47 | 显示全部楼层
和普通LISP一样调用啊!只是你的电脑上必须有装EXCEL软件!
你可以逐个试一下就知道怎样用了!你可以参考每个子程序后面的
EXAMPLE啊!
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2005-4-2 20:13:43 | 显示全部楼层
多谢高手的好东东!
我正缺这方面的东西!
谢谢了!
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2005-4-2 23:32:54 | 显示全部楼层
有些复杂,下回来学习
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2005-4-3 15:48:29 | 显示全部楼层
aaa
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2005-4-3 23:49:24 | 显示全部楼层
你的ㄧ小步卻是我的ㄧ大步
感謝你的分享
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2005-4-4 07:53:42 | 显示全部楼层
我对LISP还不熟,不过以后还可以慢慢学习.

警告:请不要发表和主题无关的帖子!
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2005-4-4 08:09:01 | 显示全部楼层
虽然现在还不太明白,先下了。谢谢。
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 8612个

财富等级: 富甲天下

发表于 2005-4-25 16:42:20 | 显示全部楼层
你指的是哪一部分是自己开发的?好像很多东西都在这儿呢。
http://www.ikozmos.com/
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 22个

财富等级: 恭喜发财

发表于 2014-5-19 14:44:58 | 显示全部楼层
留名占位。以后好找。哈哈
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2014-8-27 16:57:49 | 显示全部楼层
这个很给力
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-9-21 13:35 , Processed in 0.217898 second(s), 61 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表