明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 763|回复: 7

[资源] 【分享】分享网上下载的KozMos VLXLS Project 函数

[复制链接]
发表于 2022-4-21 17:30 | 显示全部楼层 |阅读模式
本帖最后由 qq1254582201 于 2022-4-21 18:05 编辑
  1. <div class="blockcode"><blockquote>;|Copyright(C) 1994-2005 by KozMos Inc.
  2. Permission to use, copy, modify, and distribute this software for any purpose and without fee is hereby
  3. granted, provided that the above copyright notice appears in all copies and that both that copyright notice
  4. and the limited warranty and restricted rights notice below appear in all supporting documentation.
  5. KozMos PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS. KozMos SPECIFICALLY DISCLAIMS ANY IMPLIED
  6. WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. KozMos, INC. DOES NOT WARRANT THAT THE OPERATION
  7. OF THE PROGRAM WILL BE UNINTERRUPTED OR ERROR FREE.
  8. Public Function
  9. Name
  10. (vlxls-variant->list VariantValue)
  11. Usage
  12. Convert a variant into normal Visual LISP LIST data, nested Variant and safearray will also be converted.
  13. Input
  14. VARIANT
  15. Input Variant
  16. RetVal
  17. True
  18. LIST
  19. Valid Visual LISP variable value
  20. Fail
  21. STR
  22. “”
  23. |;
  24. (Defun vlxls-variant->list (VarX / Run Item Rtn)
  25.   (setq Run T)
  26.   (while
  27.     Run
  28.      (cond ((= (type VarX) 'SAFEARRAY)
  29.            (setq VarX (vlax-safearray->list VarX))
  30.           )
  31.           ((= (type VarX) 'VARIANT)
  32.            (if    (member (vlax-variant-type VarX) (list 5 4 3 2))
  33.              (setq VarX (vlax-variant-change-type Varx vlax-vbString))
  34.            )
  35.            (setq VarX (vlax-variant-value VarX))
  36.           )
  37.           (t (setq Run nil))
  38.      )
  39.   )
  40.   (cond  ((= (type VarX) 'LIST)
  41.         (foreach Item VarX
  42.           (setq Item (vlxls-variant->list Item)
  43.                Rtn  (append Rtn (list Item))
  44.           )
  45.         )
  46.        )
  47.        ((= VarX nil) (setq Rtn ""))
  48.        (t (setq Rtn VarX))
  49.   )
  50.   Rtn
  51. )
  52. ;|Examples:
  53. NONE
  54. Color Transfer Function
  55. Name
  56. (vlxls-color-eci->truecolor ExcelColorIndexNumber)
  57. Usage
  58. Convert Excel ColorIndex number into most matched AutoCAD2004+ truecolor number (stored by DXF420).
  59. Input
  60. INT
  61. Excel ColorIndex integer (0 to 56)
  62. RetVal
  63. True
  64. INT
  65. Valid AutoCAD 2004+ truecolor number
  66. Fail
  67. INT
  68. 16711935 for None|;
  69. (Defun vlxls-color-ECI->truecolor (Color / Rtn)
  70.   (if (setq Rtn (cdr (assoc Color *xls-color*)))
  71.     (setq Rtn (nth 1 Rtn))
  72.   )
  73.   (if (null Rtn)
  74.     (setq Rtn 16711935)
  75.   )
  76.   Rtn
  77. )
  78. ;|Examples:
  79. (vlxls-color-eci->truecolor 0) è16711935
  80. (vlxls-color-eci->truecolor 1)è 0
  81. (vlxls-color-eci->truecolor 12)è 8355584
  82. (vlxls-color-eci->truecolor 120) è16711935
  83. Color Transfer Function
  84. Name
  85. (vlxls-color-eci->aci ExcelColorIndexNumber)
  86. Usage
  87. Convert Excel ColorIndex number into most matched AutoCAD ACI Integer number.
  88. Input
  89. INT
  90. Excel ColorIndex integer (0 to 56)
  91. RetVal
  92. True
  93. INT
  94. Valid AutoCAD ACI Integer number (0 to 256)
  95. Fail
  96. INT
  97. 256 for BYLAYER
  98. |;
  99. (Defun vlxls-color-eci->aci (Color / Rtn)
  100. (if (null (setq Rtn (cdr (assoc Color *xls-color*))))
  101.   (setq Rtn 256)
  102.     (setq Rtn (nth 0 Rtn))
  103.   )
  104.   Rtn
  105. )
  106. ;|
  107. Examples:
  108. (vlxls-color-eci->aci 0) è256
  109. (vlxls-color-eci->aci 1)è 18
  110. (vlxls-color-eci->aci 12)è 56
  111. (vlxls-color-eci->aci 120) è256
  112. Color Transfer Function
  113. Name
  114. (vlxls-color-aci->eci AutoCADColorIndexNumber)
  115. Usage
  116. Convert AutoCAD ColorIndex number into Excel ColorIndex .
  117. Input
  118. INT
  119. AutoCAD ColorIndex integer (0 to 256)
  120. RetVal
  121. True
  122. INT
  123. Valid Excel ColorIndex number (from 1 to 56)
  124. Fail
  125. INT
  126. 0 for NONE
  127. |;
  128. (Defun vlxls-color-aci->eci (Color / Item Rtn)
  129.   (foreach Item    *xls-color*
  130.     (if    (= (nth 1 Item) Color)
  131.       (setq Rtn (car Item))
  132.     )
  133.   )
  134.   (if (null Rtn)
  135.     (setq Rtn 0)
  136.   )
  137.   Rtn
  138. )
  139. ;|
  140. Examples:
  141. (vlxls-color-aci->eci 0) è0
  142. (vlxls-color-aci->eci 1)è 3
  143. (vlxls-color-aci->eci 12)è 0
  144. (vlxls-color-aci->eci 120) è0
  145. Color Transfer Function
  146. Name
  147. (vlxls-color-aci->truecolor AutoCADColorIndexNumber)
  148. Usage
  149. Convert AutoCAD ColorIndex number into most matched AutoCAD2004+ true color number (using Excel ColorIndex as
  150. intermediary, provided for use in AutoCAD2002. In AutoCAD2004+, this can be done directly by AutoCAD.
  151. Input
  152. INT
  153. AutoCAD ColorIndex integer (0 to 256)
  154. RetVal
  155. True
  156. INT
  157. Valid AutoCAD2004+ truecolor number
  158. Fail
  159. INT
  160. 16711935 for None
  161. |;
  162. (Defun vlxls-color-aci->truecolor (aci)
  163.   (vlxls-color-eci->truecolor (vlxls-color-aci->eci aci))
  164. )
  165. ;|
  166. Examples:
  167. (vlxls-color-aci-> truecolor 0) è 16711935
  168. (vlxls-color-aci->truecolor 1)è 16711680
  169. (vlxls-color-aci-> truecolor 12)è 16711935
  170. (vlxls-color-aci-> truecolor 120) è 16711935
  171. Excel Application Session Progress Function
  172. Name
  173. (vlxls-app-init)
  174. Usage
  175. Import Microsoft Excel Type Library, set prefix of "msxl-" for all of the :methods-prefix; :properties-prefix
  176. & :constants-prefix. This function can detect Excel’s installation path automatically from Windows registry so
  177. that it can run smoothly on any language platform of Windows and Office.
  178. Input
  179. NONE
  180. No Arguments
  181. RetVal
  182. True
  183. BOOLEAN
  184. msxl-xl24HourClock
  185. Fail
  186. BOOLEAN
  187. NIL
  188. |;
  189. (Defun vlxls-app-Init
  190.        (/ OSVar GGG Olb8 Olb9 Olb10 TLB Out msg msg1 msg2)
  191.   (if *Chinese*
  192.     (setq msg  "n 初始化微软Excel "
  193.          msg1 "42初始化Excel错误42"
  194.          msg2 (strcat
  195.                "42 警告"
  196.                "n ===="
  197.                "n 无法在您的计算机上检测到微软Excel软件"
  198.                "n 如果您确认已经安装Excel, 请发送电子邮"
  199.                "n 件到GuXiaolin@hxch.com.cn获取更多的解决方案42"
  200.               )
  201.     )
  202.     (setq msg  "n Initializing Microsoft Excel "
  203.          msg1 "42Initialization Error42"
  204.          msg2 (strcat
  205.                "42 WARNING"
  206.      "n ======="
  207.                "n Can NOT detect Excel97/200X/XP in your computer"
  208.                "n If you already have Excel installed, please email"
  209.                "n us to get more solution via GuXiaolin@hxch.com.cn42")
  210.     )
  211.   )
  212.   (if (null msxl-xl24HourClock)
  213.     (progn
  214.       (if (and (setq GGG
  215.                     (vl-registry-read
  216.                      "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Excel.EXE"
  217.                      "Path"
  218.                     )
  219.               )
  220.               (setq GGG (strcase (strcat GGG "Excel.EXE")))
  221.          )
  222.        (progn
  223.          (foreach OSVar (list "SYSTEMROOT" "WINDIR"
  224.                             "WINBOOTDIR"     "SYSTEMDRIVE"
  225.                             "USERNAME"  "COMPUTERNAME"
  226.                             "HOMEDRIVE"       "HOMEPATH"
  227.                             "PROGRAMFILES"
  228.                            )
  229.            (if    (vl-string-search (strcat "%" OSVar "%") GGG)
  230.              (setq GGG       (vl-string-subst
  231.                        (strcase (getenv OSVar))
  232.                        (strcat "%" OSVar "%")
  233.                        GGG
  234.                      )
  235.              )
  236.            )
  237.          )
  238.          (setq   Olb8  (findfile (vl-string-subst "EXCEL8.OLB" "EXCEL.EXE" GGG))
  239.               Olb9  (findfile (vl-string-subst "EXCEL9.OLB" "EXCEL.EXE" GGG))
  240.               Olb10 (findfile (vl-string-subst "EXCEL10.OLB" "EXCEL.EXE" GGG))
  241.          )
  242.          (cond  ((= (vl-filename-base (vl-filename-directory GGG))
  243.                   "OFFICE11"
  244.                )
  245.                (setq TLB GGG
  246.                      Out "2003"
  247.                )
  248.               )
  249.               ((= (vl-filename-base (vl-filename-directory GGG))
  250.                   "OFFICE10"
  251.                )
  252.                (setq TLB GGG
  253.                      Out "XP"
  254.                )
  255.               )
  256.               (Olb9
  257.                (setq TLB Olb9
  258.                      Out "2000"
  259.                )
  260.               )
  261.               (Olb8
  262.                (setq TLB Olb8
  263.                      Out "97"
  264.                )
  265.               )
  266.               (t (setq Out "Version Unknown"))
  267.          )
  268.          (if TLB
  269.            (progn
  270.              (princ (strcat MSG Out "..."))
  271.              (vlax-import-type-library
  272.               :tlb-filename    TLB               :methods-prefix
  273.               "msxl-"             :properties-prefix
  274.               "msxl-"             :constants-prefix "msxl-"
  275.               )
  276.            )
  277.          )
  278.        )
  279.        (progn
  280.          (if vldcl-msgbox
  281. (vldcl-msgbox "x" msg1 msg2)
  282. (alert (read msg2))
  283. )
  284.          (exit)
  285.        )
  286.       )
  287.     )
  288.   )
  289.   msxl-xl24HourClock
  290. )
  291. ;|
  292. Examples:
  293. (vlxls-app-init)è 33
  294. Excel Application Session Progress Function
  295. Name
  296. (vlxls-app-new ShowExcelFlag)
  297. Usage
  298. Open a new Excel session and start a new workbook.
  299. Input
  300. BOOLEAN
  301. T for display, nil for hide
  302. RetVal
  303. True
  304. VLOBJ
  305. Excel Session vla-object
  306. Fail
  307. BOOLEAN
  308. NIL
  309. |;
  310. (Defun vlxls-app-New (UnHide / Rtn)
  311.   (if (vlxls-app-init)
  312.     (progn
  313.       (if *Chinese*
  314.            (princ "n 新建微软Excel工作表...")
  315.        (princ "n Creating new Excel Spreadsheet file...")
  316.       )
  317.       (if (setq Rtn (vlax-get-or-create-object "Excel.Application"))
  318.        (progn
  319.          (vlax-invoke-method
  320.            (vlax-get-property Rtn 'WorkBooks)
  321.            'Add
  322.          )
  323.          (if UnHide
  324.            (vla-put-visible Rtn 1)
  325.            (vla-put-visible Rtn 0)
  326.          )
  327.        )
  328.       )
  329.     )
  330.   )
  331.   Rtn
  332. )
  333. ;|
  334. Examples:
  335. (setq *xlapp* (vlxls-app-new T)) è #<VLA-OBJECT _Application 001db27c>
  336. Excel Application Session Progress Function
  337. Name
  338. (vlxls-app-open XLSfilename ShowExcelFlag)
  339. Usage
  340. Open a new Excel session to start existing XLS file.
  341. Input
  342. STR
  343. XLS file name with full path, ".XLS" not needed.
  344. BOOLEAN
  345. T for display, nil for hide
  346. RetVal
  347. True
  348. VLOBJ
  349. Excel Session vla-object
  350. Fail
  351. BOOLEAN
  352. NIL
  353. |;
  354. (Defun vlxls-app-open
  355.        (XLSFile UnHide / ExcelApp WorkSheet Sheets ActiveSheet Rtn)
  356.   (setq XLSFile (strcase XLSFile))
  357.   (if (null (wcmatch XLSFile "*.XLS"))
  358.     (setq XLSFile (strcat XLSFile ".XLS"))
  359.   )
  360.   (if (and (findfile XLSFile)
  361.           (setq Rtn (vlax-get-or-create-object "Excel.Application"))
  362.       )
  363.     (progn
  364.       (vlax-invoke-method
  365.        (vlax-get-property Rtn 'WorkBooks)
  366.        'Open
  367.        XLSFile
  368.       )
  369.       (if UnHide
  370.        (vla-put-visible Rtn 1)
  371.        (vla-put-visible Rtn 0)
  372.       )
  373.     )
  374.   )
  375.   Rtn
  376. )
  377. ;|
  378. Examples:
  379. (setq *xlapp* (vlxls-app-open “C:/test.XLS” T)) è #<VLA-OBJECT _Application 001efd2c>
  380. Excel Application Session Progress Function
  381. Name
  382. (vlxls-app-save ExcelSessionVLA-OBJECT)
  383. Usage
  384. Perform save operation in Excel.
  385. Input
  386. VLOBJ
  387. Excel session vla-object
  388. RetVal
  389. True
  390. BOOLEAN
  391. T
  392. Fail
  393. BOOLEAN
  394. NIL
  395. |;
  396. (Defun vlxls-app-save (xlapp)
  397.   (equal (vlax-invoke-method
  398.           (vlax-get-property Xlapp "ActiveWorkbook")
  399.           "Save"
  400.         )
  401.         :vlax-true
  402.   )
  403. )
  404. ;|
  405. Examples:
  406. (vlxls-app-save *xlapp*) è T
  407. Excel Application Session Progress Function
  408. Name
  409. (vlxls-app-saveas ExcelSessionVLA-OBJECT SavedFileName)
  410. Usage
  411. Perform saveas operation in Excel.
  412. Input
  413. VLOBJ
  414. Excel session vla-object
  415. STR
  416. Saved XLS file name with full path
  417. NIL for a temporary “XLS.XLS” file in current drawing path.
  418. RetVal
  419. True
  420. STRING
  421. XLS file name with full path
  422. Fail
  423. BOOLEAN
  424. NIL
  425. |;
  426. (Defun vlxls-app-saveas    (xlapp Filename / Rtn)
  427.   (if (null filename)
  428.     (setq filename (strcat (getvar "dwgprefix") "XLS.XLS"))
  429.   )
  430.   (if (null (wcmatch (setq filename (strcase Filename)) "*`.XLS"))
  431.     (setq filename (strcat filename ".XLS"))
  432.   )
  433.   (if (findfile Filename)
  434.     (vl-file-delete (findfile Filename))
  435.   )
  436.   (vlax-invoke-method
  437.     (vlax-get-property Xlapp "ActiveWorkbook")
  438.     "SaveAs"
  439.     Filename
  440.     msxl-xlNormal
  441.     ""
  442.     ""
  443.     :vlax-False
  444.     :vlax-False
  445.     nil
  446.   )
  447.   (findfile Filename)
  448. )
  449. ;|
  450. Examples:
  451. (vlxls-app-saveas *xlapp* nil) è “C:/Temp-Folder/XLS.XLS”
  452. (vlxls-app-saveas *xlapp* “C:/Temp-Folder/XLS.XLS”) è “C:/Temp-Folder/XLS.XLS”
  453. (vlxls-app-saveas *xlapp* nil) è NIL
  454. Excel Application Session Progress Function
  455. Name
  456. (vlxls-app-quit ExcelSessionVLA-OBJECT SavedFlag)
  457. Usage
  458. Quit active workbook of Excel session and release Excel application.
  459. Input
  460. VLOBJ
  461. Excel session vla-object
  462. BOOLEAN
  463. Save Excel active workwook flag, T for save, NIL for unsave
  464. RetVal
  465. True
  466. BOOLEAN
  467. NIL
  468. Fail
  469. BOOLEAN
  470. NIL
  471. |;
  472. (Defun vlxls-app-quit (ExlObj SaveYN)
  473.   (if SaveYN
  474.     (vlax-invoke-method
  475.       (vlax-get-property ExlObj "ActiveWorkbook")
  476.       'Close
  477.     )
  478.     (vlax-invoke-method
  479.       (vlax-get-property ExlObj "ActiveWorkbook")
  480.       'Close
  481.       :vlax-False
  482.     )
  483.   )
  484.   (vlax-invoke-method ExlObj 'QUIT)
  485.   (vlax-release-object ExlObj)
  486.   (setq ExlObj nil)
  487.   (gc)
  488. )
  489. ;|
  490. Examples:
  491. (vlxls-app-quit *xlapp* nil) è nil
  492. Excel Application Session Progress Function
  493. Name
  494. (vlxls-app-kill)
  495. Usage
  496. Close all active Excel workbooks.
  497. Input
  498. NONE
  499. No Arguments
  500. RetVal
  501. True
  502. BOOLEAN
  503. NIL
  504. Fail
  505. BOOLEAN
  506. NIL
  507. |;
  508. (Defun vlxls-app-kill (SaveYN / ExlObj)
  509.   (while (setq ExlObj (vlax-get-object "Excel.Application"))
  510.     (vlxls-app-quit ExlObj SaveYN)
  511.   )
  512. )
  513. ;|
  514. Examples:
  515. (vlxls-app-kill T) è nil
  516. Excel Application Session Progress Function
  517. Name
  518. (vlxls-app-autofit ExcelSessionVLA-OBJECT)
  519. Usage
  520. Autofit the column width of all Excel session used ranges.
  521. Input
  522. VLOBJ
  523. Excel session vla-object
  524. RetVal
  525. True
  526. Variant
  527. T
  528. Fail
  529. BOOLEAN
  530. NIL
  531. |;
  532. (Defun vlxls-app-autofit (xlapp / sh act Rtn)
  533.   (setq act (vlxls-Sheet-Get-Active xlapp))
  534.   (foreach sh (append (vl-remove act (vlxls-sheet-get-all Xlapp))
  535.                     (list act)
  536.              )
  537.     (setq Rtn (variant-value
  538.               (msxl-autofit
  539.                 (msxl-get-columns
  540.                   (msxl-get-Cells
  541.                     (vlxls-sheet-get-usedrange xlapp sh)
  542.                   )
  543.                 )
  544.               )
  545.              )
  546.     )
  547.   )
  548.   (equal Rtn :vlax-true)
  549. )
  550. ;|
  551. Examples:
  552. (vlxls-app-autofit *xlapp*) è T
  553. (vlxls-app-autofit *xlapp*) è NIL
  554. Excel Sheet Progress Function
  555. Name
  556. (vlxls-sheet-get-all ExcelSessionVLA-OBJECT)
  557. Usage
  558. Get name list of all sheets.
  559. Input
  560. VLOBJ
  561. Excel session vla-object
  562. RetVal
  563. True
  564. LIST
  565. List contain all sheets’ name
  566. Fail
  567. BOOLEAN
  568. NIL
  569. |;
  570. (Defun vlxls-sheet-get-all (xlapp / SH Rtn)
  571.   (vlax-for SH (vlax-get-property Xlapp "sheets")
  572.     (setq Rtn (cons (vlax-get-property sh "Name") Rtn))
  573.   )
  574.   (reverse Rtn)
  575. )
  576. ;|
  577. Examples:
  578. (vlxls-sheet-get-all *xlapp*) è ("Sheet1" "Sheet2" "Sheet3")
  579. Excel Sheet Progress Function
  580. Name
  581. (vlxls-sheet-get-active ExcelSessionVLA-OBJECT)
  582. Usage
  583. Get active sheet name.
  584. Input
  585. VLOBJ
  586. Excel session vla-object
  587. RetVal
  588. True
  589. STRING
  590. Active sheet's name string
  591. Fail
  592. BOOLEAN
  593. NIL
  594. |;
  595. (Defun vlxls-Sheet-Get-Active (xlapp)
  596.   (vlax-get-property (msxl-get-ActiveSheet Xlapp) 'name)
  597. )
  598. ;|
  599. Examples:
  600. (vlxls-sheet-get-active *xlapp*) è "Sheet2"
  601. Excel Sheet Progress Function
  602. Name
  603. (vlxls-sheet-delete ExcelSessionVLA-OBJECT DeleteSheetName)
  604. Usage
  605. Delete certain sheet by name.
  606. Input
  607. VLOBJ
  608. Excel session vla-object
  609. STRING
  610. Sheet name to delete
  611. RetVal
  612. True
  613. BOOLEAN
  614. T
  615. Fail
  616. BOOLEAN
  617. NIL
  618. |;
  619. (Defun vlxls-sheet-delete (xlapp Name / sh Rtn)
  620.   (setq Rtn (vlxls-sheet-get-all Xlapp))
  621.   (vlax-for sh (vlax-get-property Xlapp "sheets")
  622.     (if    (= (vlax-get-property sh "Name") Name)
  623.       (vlax-invoke-method sh "Delete")
  624.     )
  625.   )
  626.   (not (equal Rtn (vlxls-sheet-get-all Xlapp)))
  627. )
  628. ;|
  629. Examples:
  630. (vlxls-sheet-delete *xlapp* “Sheet1”) è T
  631. (vlxls-sheet-delete *xlapp* “UnExistingSheet”) è NIL
  632. Excel Sheet Progress Function
  633. Name
  634. (vlxls-sheet-rename NewSheetName OldSheetName ExcelSessionVLA-OBJECT)
  635. Usage
  636. Rename certain sheet by name.
  637. Input
  638. STRING
  639. New sheet name string
  640. STRING
  641. Old sheet name string
  642. VLOBJ
  643. Excel session vla-object
  644. RetVal
  645. True
  646. BOOLEAN
  647. T
  648. Fail
  649. BOOLEAN
  650. NIL
  651. |;
  652. (Defun vlxls-sheet-rename (New Old Xlapp / sh Rtn)
  653.   (if (null old)
  654.     (setq old (msxl-get-name (msxl-get-activesheet Xlapp)))
  655.   )
  656.   (if (member New (vlxls-sheet-get-all Xlapp))
  657.     (setq Rtn nil)
  658.     (progn
  659.       (vlax-for     sh (vlax-get-property Xlapp "sheets")
  660.        (if (= (msxl-get-name sh) Old)
  661.          (msxl-put-name sh New)
  662.        )
  663.       )
  664.       (setq Rtn
  665.             (equal New
  666.                   (vlax-get-property (msxl-get-ActiveSheet Xlapp) 'name)
  667.             )
  668.       )
  669.     )
  670.   )
  671.   Rtn
  672. )
  673. ;|Examples:
  674. (vlxls-sheet-rename “New” “Sheet1” *xlapp*) è T
  675. (vlxls-sheet-rename “New” NIL *xlapp*) è T
  676. (vlxls-sheet-rename “Sheet3” NIL *xlapp*) è NIL
  677. (vlxls-sheet-rename “Sheet2” “Sheet1” *xlapp*) è NIL
  678. (vlxls-sheet-rename “Sheet2” “UnExistSheet” *xlapp*) è NIL
  679. Excel Sheet Progress Function
  680. Name
  681. (vlxls-sheet-add ExcelSessionVLA-OBJECT NewSheetName)
  682. Usage
  683. New sheet name. If sheet name exist, return NIL
  684. Input
  685. VLOBJ
  686. Excel session vla-object
  687. STRING
  688. New added sheet name string
  689. RetVal
  690. True
  691. BOOLEAN
  692. T
  693. Fail
  694. BOOLEAN
  695. NIL
  696. |;
  697. (Defun vlxls-sheet-add (xlapp Name / Rtn)
  698.   (if (member name (vlxls-sheet-get-all xlapp))
  699.     (setq Rtn nil)
  700.     (progn
  701.       (vlax-put-property
  702.        (vlax-invoke-method
  703.          (vlax-get-property Xlapp "sheets")
  704.          "Add"
  705.        )
  706.        "name"
  707.        Name
  708.       )
  709.       (setq Rtn (equal (vlxls-sheet-get-active xlapp) name))
  710.     )
  711.   )
  712.   Rtn
  713. )
  714. ;|
  715. Examples:
  716. (vlxls-sheet-add *xlapp* “Sheet1”) èT
  717. (vlxls-sheet-add *xlapp* NIL) èT
  718. (vlxls-sheet-add *xlapp* “NewSheet”) è NIL
  719. Excel Sheet Progress Function
  720. Name
  721. (vlxls-sheet-put-active ExcelSessionVLA-OBJECT ActiveSheetName)
  722. Usage
  723. Put certain sheet as active sheet. If sheet name not exist, create automatically.
  724. Input
  725. VLOBJ
  726. Excel session vla-object
  727. STRING
  728. New active sheet name string
  729. RetVal
  730. True
  731. BOOLEAN
  732. T
  733. Fail
  734. BOOLEAN
  735. NIL
  736. |;
  737. (Defun vlxls-sheet-put-active (xlapp Name / sh)
  738.   (if (null (vlxls-sheet-add xlapp name))
  739.     (vlax-for sh    (vlax-get-property Xlapp "sheets")
  740.       (if (= (vlax-get-property sh "Name") Name)
  741.        (vlax-invoke-method sh "Activate")
  742.       )
  743.     )
  744.   )
  745.   (equal (vlxls-sheet-get-active xlapp) name)
  746. )
  747. ;|
  748. Examples:
  749. (vlxls-sheet-put-active *xlapp* “Sheet1”) è T
  750. (vlxls-sheet-put-active *xlapp* “NewSheet”) è T
  751. Excel Sheet Progress Function
  752. Name
  753. (vlxls-sheet-get-usedrange ExcelSessionVLA-OBJECT SheetName)
  754. Usage
  755. Get all used range of certain Excel sheet. If sheet name not exist, return NIL.
  756. Input
  757. VLOBJ
  758. Excel session vla-object
  759. STRING
  760. Excel sheet name string, NIL for current active sheet.
  761. RetVal
  762. True
  763. VLOBJ
  764. Excel Range vla-object
  765. Fail
  766. BOOLEAN
  767. NIL
  768. |;
  769. (Defun vlxls-sheet-get-UsedRange (xlapp Name / sh Rtn)
  770.   (if (null Name)
  771.     (setq Name (vlax-get-property (msxl-get-ActiveSheet Xlapp) 'Name))
  772.   )
  773.   (vlax-for sh (vlax-get-property Xlapp "sheets")
  774.     (if    (= (vlax-get-property sh "Name") Name)
  775.       (setq Rtn (vlax-get-property sh "UsedRange"))
  776.     )
  777.   )
  778.   Rtn
  779. )
  780. ;|
  781. Examples:
  782. (vlxls-sheet-get-usedrange *xlapp* “Sheet1”) è T
  783. (vlxls-sheet- get-usedrange *xlapp* “NewSheet”) è T
  784. Excel Cell and Range Progress Function
  785. Name
  786. (vlxls-cellid CellIDStringOrList)
  787. Usage
  788. Divide complex Excel Cell ID into a two-string-item list, contain the Left-Upper and Right-Lower Cell ID.
  789. If only one Cell ID is provided, set the Right-Lower Cell ID to “”.
  790. Input
  791. STR/LIST
  792. Complex Excel Cell ID string or simple Cell ID string/list.
  793. RetVal
  794. True
  795. LIST
  796. List of Left-Upper and Right-Lower Cell ID
  797. Fail
  798. BOOLEAN
  799. NIL
  800. |;
  801. (Defun vlxls-cellid (id / xx id1 id2 Rtn)
  802.   (if (= (type id) 'list)
  803.     (setq id (vlxls-rangeid id))
  804.   )
  805.   (setq id (strcase id))
  806.   (if (null (setq xx (vl-string-search ":" id)))
  807.     (setq Rtn (list id ""))
  808.     (setq id1 (substr id 1 xx)
  809.          id2 (substr id (+ xx 2))
  810.          id1 (vlxls-rangeid id1)
  811.          id2 (vlxls-rangeid id2)
  812.          Rtn (list (vlxls-rangeid
  813.                     (list (min (car id1) (car id2))
  814.                          (min (cadr id1) (cadr id2))
  815.                     )
  816.                   )
  817.                   (vlxls-rangeid
  818.                     (list (max (car id1) (car id2))
  819.                          (max (cadr id1) (cadr id2))
  820.                     )
  821.                   )
  822.              )
  823.     )
  824.   )
  825.   Rtn
  826. )
  827. ;|
  828. Examples:
  829. (vlxls-cellid ‘(3 14)) è ("C14" "")
  830. (vlxls-cellid “D23”) è ("D23" "")
  831. (vlxls-cellid “C12:F3”) è ("C3" "F12")
  832. (vlxls-cellid “F15:G22”) è ("F15" "G22")
  833. Excel Cell and Range Progress Function
  834. Name
  835. (vlxls-rangeid CellIDStringOrList)
  836. Usage
  837. 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.
  838. Input
  839. STR/LIST
  840. The Cell ID list or string
  841. RetVal
  842. True
  843. STR/LIST
  844. Cell ID value in another VLXLS ID type
  845. Fail
  846. BOOLEAN
  847. NIL
  848. |;
  849. (Defun vlxls-rangeid (id / str->list list->str xid->str Rtn)
  850.   (Defun str->list (str / ii xk xv rr pos x y)
  851.     (setq rr (strlen str))
  852.     (foreach ii     '("0" "1" "2" "3" "4" "5" "6" "7" "8" "9")
  853.       (if (setq pos (vl-string-search ii str))
  854.        (setq rr (min pos rr))
  855.       )
  856.     )
  857.     (setq x (substr str 1 rr)
  858.          y (substr str (1+ rr))
  859.     )
  860.     (if    (= (strlen x) 2)
  861.       (setq xk (- (ascii (substr x 1 1)) 64)
  862.            xv (- (ascii (substr x 2)) 64)
  863.       )
  864.       (setq xk 0
  865.            xv (- (ascii x) 64)
  866.       )
  867.     )
  868.     (list (+ (* xk 26) xv) (read y))
  869.   )
  870.   (Defun xid->str (IntNum / PosNum Nm-One)
  871.     (setq Nm-One (1- IntNum)
  872.          PosNum (/ Nm-One 26)
  873.     )
  874.     (if    (= PosNum 0)
  875.       (chr (+ 65 (rem Nm-One 26)))
  876.       (strcat (chr (+ 64 PosNum)) (chr (+ 65 (rem Nm-One 26))))
  877.     )
  878.   )
  879.   (Defun list->str (idr / x y)
  880.     (setq x (car idr)
  881.          y (cadr idr)
  882.          x (xid->str x)
  883.          y (itoa y)
  884.     )
  885.     (strcat x y)
  886.   )
  887.   (cond  ((= (type id) 'str) (setq Rtn (str->list id)))
  888.        ((= (type id) 'list) (setq Rtn (list->str id)))
  889.   )
  890.   Rtn
  891. )
  892. ;|
  893. Examples:
  894. (vlxls-rangeid ‘(3 14)) è "C14"
  895. (vlxls-rangeid “D23”) è (4 23)
  896. (vlxls-rangeid “DD23”) è (108 23)
  897. Excel Cell and Range Progress Function
  898. Name
  899. (vlxls-range-autofit RangeVLA_OBJECT)
  900. Usage
  901. Autofit the column width of a certain range object.
  902. Input
  903. VLOBJ
  904. The Excel Range vla-object
  905. RetVal
  906. True
  907. BOOLEAN
  908. T
  909. Fail
  910. BOOLEAN
  911. NIL
  912. |;
  913. (Defun vlxls-range-autofit (range)
  914.   (equal (vlax-variant-value
  915.           (msxl-autofit
  916.             (msxl-get-columns (msxl-get-Cells range))
  917.           )
  918.         )
  919.         :vlax-true
  920.   )
  921. )
  922. ;|
  923. Examples:
  924. (vlxls-range-autofit (msxl-get-range *xlapp* “C12:F15”)) è T
  925. (vlxls-range-autofit RangeObject) è NIL
  926. Excel Cell and Range Progress Function
  927. Name
  928. (vlxls-cell-put-active ExcelSessionVLA-OBJECT CellIDStringOrList)
  929. Usage
  930. Select to certain Cell ID and activate it.
  931. Input
  932. VLOBJ
  933. The Excel Session vla-object
  934. STR/LIST
  935. The Cell ID list or string
  936. RetVal
  937. True
  938. VLOBJ
  939. Active Range vla-object
  940. Fail
  941. BOOLEAN
  942. NIL
  943. |;
  944. (Defun vlxls-cell-put-active (xl id / Rtn)
  945.   (if (= (type id) 'list)
  946.     (setq id (vlxls-rangeid id))
  947.   )
  948.   (msxl-activate (setq Rtn (msxl-get-range xl id)))
  949.   Rtn
  950. )
  951. ;|
  952. Examples:
  953. (vlxls-cell-put-active *xlapp* “C12:F15”) è #<VLA-OBJECT Range 09d1998c>
  954. (vlxls-cell-put-active *xlapp* “F12”) è #<VLA-OBJECT Range 06c389a2>
  955. Excel Cell and Range Progress Function
  956. Name
  957. (vlxls-cell-get-value ExcelSessionVLA-OBJECT CellIDStringOrList)
  958. Usage
  959. Get value of certain Cell ID.
  960. Input
  961. VLOBJ
  962. The Excel Session vla-object
  963. STR/LIST
  964. The Cell ID list or string
  965. RetVal
  966. True
  967. STR/LIST
  968. String for one cell, a 2 dimension list for multiple cells or merged cell
  969. Fail
  970. BOOLEAN
  971. NIL
  972. |;
  973. (Defun vlxls-cell-get-value (xl id)
  974.   (if (= (type id) 'list)
  975.     (setq id (vlxls-rangeid id))
  976.   )
  977.   (vlxls-variant->list
  978.     (msxl-get-value2 (msxl-get-range xl id))
  979.   )
  980. )
  981. ;|
  982. Examples:
  983. (vlxls-cell-get-value *xlapp* “C12”) è “g”
  984. (vlxls-cell-get-value *xlapp* “C12:C12”) è “g”
  985. (vlxls-cell-get-value *xlapp* “C12:C15”) è (("g") ("") ("") (""))
  986. (vlxls-cell-get-value *xlapp* “C12:F12”) è (("g" "ds" "" ""))
  987. (vlxls-cell-get-value *xlapp* “C12:F15”) è (("g" "ds" "" "") ("" "" "g" "") ("" "" "" "") ("" "" "" ""))
  988. Excel Cell and Range Progress Function
  989. Name
  990. (vlxls-cell-put-value ExcelSessionVLA-OBJECT CellIDStringOrList DataList)
  991. Usage
  992. Pass a 1 dimension or a 2 dimension string list into Excel, started at certain Cell ID.
  993. Input
  994. VLOBJ
  995. The Excel Session vla-object
  996. STR/LIST
  997. The start Cell ID [Left-Upper] list or string
  998. STR/LIST
  999. If this argument is a string, VLXLS will fill same string to all cells.
  1000. 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
  1001. given cell ID, VLXLS will only fill first cell, fill to other cells will be ignored.
  1002. RetVal
  1003. True
  1004. VLOBJ
  1005. All Excel Range vla-object that just be filled in by given data list
  1006. Fail
  1007. BOOLEAN
  1008. NIL
  1009. |;
  1010. (Defun vlxls-cell-put-value
  1011.        (xl id Data / vllist-explode idx xx yy ary Rtn)
  1012.     (Defun vllist-explode  (lst)
  1013. (cond
  1014.     ((not lst) nil)
  1015.     ((atom lst) (list lst))
  1016.     ((append (vllist-explode (car lst))
  1017.      (vllist-explode (cdr lst))
  1018.      )
  1019.      )
  1020.     )
  1021. )
  1022.     (if  (null id)
  1023. (setq id "A1")
  1024. )
  1025.     (if  (= (type id) 'list)
  1026. (setq id (vlxls-rangeid id))
  1027. )
  1028.     (if  (= (type (car Data)) 'LIST)
  1029. (setq ARY (vlax-make-safearray
  1030.       vlax-vbstring
  1031.       (cons 0 (1- (length Data)))
  1032.       (cons 1 (length (car Data)))
  1033.       )
  1034.       XX  (1- (length (car Data)))
  1035.       YY  (1- (length Data))
  1036.       )
  1037. (setq
  1038.     ARY  (vlax-make-safearray
  1039.     vlax-vbstring
  1040.     (cons 0 1)
  1041.     (cons 1 (length Data))
  1042.     )
  1043.     XX  (1- (length Data))
  1044.     YY  0
  1045.     )
  1046. )
  1047.     (if  (= xx yy 0)
  1048. (MSXL-PUT-VALUE2
  1049.     (setq Rtn (msxl-get-range xl id))
  1050.     (car (vllist-explode data))
  1051.     )
  1052. (progn
  1053.     (setq id (vlxls-cellid-calc id xx yy))
  1054.     (MSXL-PUT-VALUE2
  1055. (setq Rtn (msxl-get-range xl id))
  1056. (vlax-safearray-fill ary data)
  1057. )
  1058.     )
  1059. )
  1060.     Rtn
  1061.     )
  1062. ;|
  1063. Examples:
  1064. (vlxls-cell-put-value *xlapp* “C12” “xx”) è #<VLA-OBJECT Range 093a7764>
  1065. (vlxls-cell-put-value *xlapp* “C12:F3” “xx”) è #<VLA-OBJECT Range 43c5ac64>
  1066. (vlxls-cell-put-value *xlapp* “C12:D13” ‘((“zz” “xx”)(“xx” “zz”))) è #<VLA-OBJECT Range 1b8f2a64>
  1067. Excel Cell and Range Progress Function
  1068. Name
  1069. (vlxls-cellid-calc BaseCellId XOffset YOffset)
  1070. Usage
  1071. Calculate a new Cell ID for given delta X and Y from base Cell ID.
  1072. Input
  1073. STR/LIST
  1074. Base Cell ID string or list
  1075. INT
  1076. X offset integer of Cell ID
  1077. INT
  1078. Y offset integer of Cell ID
  1079. RetVal
  1080. True
  1081. STRING
  1082. An Excel Complex Cell ID format contain the base Cell ID and target Cell ID.
  1083. Fail
  1084. BOOLEAN
  1085. NIL
  1086. |;
  1087. (Defun vlxls-cellid-calc (id x y / idx)
  1088.   (setq   id  (car (vlxls-cellid id))
  1089.        idx (vlxls-rangeid id)
  1090.        x   (+ x (car idx))
  1091.        x   (if    (< x 1)
  1092.              1
  1093.              x
  1094.            )
  1095.        y   (+ y (cadr idx))
  1096.        y   (if    (< y 1)
  1097.              1
  1098.              y
  1099.            )
  1100.        idx (vlxls-rangeid (list x y))
  1101.        id  (vlxls-cellid (strcat id ":" idx))
  1102.        id  (strcat (car id) ":" (cadr id))
  1103.   )
  1104.   id
  1105. )
  1106. ;|
  1107. Examples:
  1108. (vlxls-cellid-calc “C12” 2 20) è "C12:E32"
  1109. (vlxls-cellid-calc ‘(2 23) 2 -120) è "B1:D23"
  1110. Excel Cell and Range Progress Function
  1111. Name
  1112. (vlxls-get-row-value ExcelSessionVLA-OBJECT StartCellIDStringOrList RowCellNumber)
  1113. Usage
  1114. Get values of certain row.
  1115. Input
  1116. VLOBJ
  1117. The Excel Session vla-object
  1118. STR/LIST
  1119. The Start Cell ID list or string
  1120. INT
  1121. Number of cells in row to read.
  1122. RetVal
  1123. True
  1124. LIST
  1125. A list contain cells' value in row
  1126. Fail
  1127. BOOLEAN
  1128. NIL
  1129. |;
  1130. (Defun vlxls-get-row-value (xl id len / vllist-explode Rtn)
  1131.   (Defun vllist-explode       (lst)
  1132.     (cond
  1133.       ((not lst) nil)
  1134.       ((atom lst) (list lst))
  1135.       ((append (vllist-explode (car lst))
  1136.               (vllist-explode (cdr lst))
  1137.        )
  1138.       )
  1139.     )
  1140.   )
  1141.   (if (> len 0)
  1142.     (setq id (vlxls-cellid-calc id (1- len) 0))
  1143.     (setq id (vlxls-cellid-calc id (1+ len) 0))
  1144.   )
  1145.   (setq Rtn (vllist-explode (vlxls-cell-get-value xl id)))
  1146.   Rtn
  1147. )
  1148. ;|
  1149. Examples:
  1150. (vlxls-get-row-value *xlapp* “C12” 2) è ("zz" "xxx")
  1151. (vlxls-get-row-value *xlapp* “C12” -20) è ("" "" "zz")
  1152. Excel Cell and Range Progress Function
  1153. Name
  1154. (vlxls-put-row-value ExcelSessionVLA-OBJECT StartCellIDStringOrList StringList)
  1155. Usage
  1156. Put a string list into Excel row started by certain cell.
  1157. Input
  1158. VLOBJ
  1159. The Excel Session vla-object
  1160. STR/LIST
  1161. The Start Cell ID list or string
  1162. STR/LIST
  1163. A string to fill in one cell or a 1 dimension string list to fill in row cells.
  1164. RetVal
  1165. True
  1166. VLOBJ
  1167. Filled Excel Range vla-object
  1168. Fail
  1169. BOOLEAN
  1170. NIL
  1171. |;
  1172. (Defun vlxls-put-row-value (xl id data / Rtn)
  1173.   (if (= (type data) 'str)
  1174.     (setq data (list data))
  1175.   )
  1176.   (setq   id (car (vlxls-cellid id))
  1177.        id (vlxls-cellid-calc id (1- (length data)) 0)
  1178.   )
  1179. ;;;不允许自动调整大小
  1180.   ;(vlxls-range-autofit
  1181.     (setq Rtn (vlxls-cell-put-value xl id (list data)))
  1182.   ;)
  1183.   Rtn
  1184. )
  1185. ;|
  1186. Examples:
  1187. (vlxls-put-row-value *xlapp* “C12” “abc”) è#<VLA-OBJECT Range 2a621cac>
  1188. (vlxls-put-row-value *xlapp* ‘(12 3) “abc”) è#<VLA-OBJECT Range 7a36c491>
  1189. (vlxls-put-row-value *xlapp* “C12” ‘("zz" "xxx")) è#<VLA-OBJECT Range 09d1da1c>
  1190. (vlxls-put-row-value *xlapp* ‘(12 3) ‘("zz" "xxx")) è#<VLA-OBJECT Range 0a26c4f3>
  1191. Excel Cell and Range Progress Function
  1192. Name
  1193. (vlxls-get-column-value ExcelSessionVLA-OBJECT StartCellIDStringOrList ColumnCellNumber)
  1194. Usage
  1195. Get values of certain column.
  1196. Input
  1197. VLOBJ
  1198. The Excel Session vla-object
  1199. STR/LIST
  1200. The Start Cell ID list or string
  1201. INT
  1202. Number of cells in column to read.
  1203. RetVal
  1204. True
  1205. LIST
  1206. A list contain cells' value in column
  1207. Fail
  1208. BOOLEAN
  1209. NIL
  1210. |;
  1211. (Defun vlxls-get-column-value (xl id len / vllist-explode Rtn)
  1212.   (Defun vllist-explode       (lst)
  1213.     (cond
  1214.       ((not lst) nil)
  1215.       ((atom lst) (list lst))
  1216.       ((append (vllist-explode (car lst))
  1217.               (vllist-explode (cdr lst))
  1218.        )
  1219.       )
  1220.     )
  1221.   )
  1222.   (setq id (car (vlxls-cellid id)))
  1223.   (if (> len 0)
  1224.     (setq id (vlxls-cellid-calc id 0 (1- len)))
  1225.     (setq id (vlxls-cellid-calc id 0 (1+ len)))
  1226.   )
  1227.   (setq Rtn (vllist-explode (vlxls-cell-get-value xl id)))
  1228.   Rtn
  1229. )
  1230. ;|
  1231. Examples:
  1232. (vlxls-get-column-value *xlapp* “C12” 2) è ("zz" "sdfsdf")
  1233. (vlxls-get-column-value *xlapp* “C12” -20) è ("" "" "xxx" "xxx" "xxx" "xxx" "xxx" "xxx" "xxx" "xxx" "xxx" "zz")
  1234. Excel Cell and Range Progress Function
  1235. Name
  1236. (vlxls-put-column-value ExcelSessionVLA-OBJECT StartCellIDStringOrList StringList)
  1237. Usage
  1238. Put a string list into Excel column started by certain cell.
  1239. Input
  1240. VLOBJ
  1241. The Excel Session vla-object
  1242. STR/LIST
  1243. The Start Cell ID list or string
  1244. STR/LIST
  1245. A string to fill in one cell or a 1 dimension string list to fill in column cells.
  1246. RetVal
  1247. True
  1248. VLOBJ
  1249. Filled Excel Range vla-object
  1250. Fail
  1251. BOOLEAN
  1252. NIL
  1253. |;
  1254. (Defun vlxls-put-column-value (xl id data / item Rtn)
  1255.   (if (= (type data) 'str)
  1256.     (setq data (list data))
  1257.   )
  1258. (setq   id (car (vlxls-cellid id))
  1259.        id (vlxls-cellid-calc id 0 (1- (length data)))
  1260.   )
  1261.   (foreach item    data
  1262.     (setq Rtn (cons (list item) Rtn))
  1263.   )
  1264. ;;;不允许自动调整表格大小
  1265.   ;(vlxls-range-autofit
  1266.     (setq Rtn (vlxls-cell-put-value xl id (reverse Rtn)))
  1267.   ;)
  1268.   Rtn
  1269. )
  1270. ;|
  1271. Examples:
  1272. (vlxls-put-column-value *xlapp* “C12” “abc”) è#<VLA-OBJECT Range 049c521b>
  1273. (vlxls-put-column-value *xlapp* ‘(12 3) “abc”) è#<VLA-OBJECT Range 0235cba1>
  1274. (vlxls-put-column-value *xlapp* “C12” ‘("zz" "xxx")) è#<VLA-OBJECT Range 09d1da1c>
  1275. (vlxls-put-column-value *xlapp* ‘(12 3) ‘("zz" "xxx")) è#<VLA-OBJECT Range 0a26c4f3>
  1276. Excel Cell and Range Progress Function
  1277. Name
  1278. (vlxls-cell-get-aci ExcelSessionVLA-OBJECT CellIDStringOrList)
  1279. Usage
  1280. Get the background color (In AutoCAD ColorIndex mode) of certain Excel cell, Multiple color will return 256.
  1281. Input
  1282. VLOBJ
  1283. The Excel Session vla-object
  1284. STR/LIST
  1285. The Cell ID list or string
  1286. RetVal
  1287. True
  1288. INT
  1289. Valid ACI Integer number (0 to 256)
  1290. Fail
  1291. BOOLEAN
  1292. NIL
  1293. |;
  1294. (Defun vlxls-cell-get-aci (xl id)
  1295.   (vlxls-color-eci->aci
  1296.     (vlax-variant-value
  1297.       (msxl-get-colorindex
  1298.        (msxl-get-interior (msxl-get-range xl id))
  1299.       )
  1300.     )
  1301.   )
  1302. )
  1303. ;|
  1304. Examples:
  1305. (vlxls-cell-get-aci *xlapp* “C12”) è256
  1306. (vlxls-cell-get-aci *xlapp* ‘(12 3)) è15
  1307. Excel Cell and Range Progress Function
  1308. Name
  1309. (vlxls-cell-put-aci ExcelSessionVLA-OBJECT CellIDStringOrList ACINumber)
  1310. Usage
  1311. Put or clear the background color (In AutoCAD ColorIndex mode) of certain Excel cells.
  1312. Input
  1313. VLOBJ
  1314. The Excel Session vla-object
  1315. STR/LIST
  1316. The Cell ID list or string
  1317. INT
  1318. ACI Integer number, NIL for remove background color
  1319. RetVal
  1320. True
  1321. VLOBJ
  1322. Modified Excel Range vla-object
  1323. Fail
  1324. BOOLEAN
  1325. NIL
  1326. |;
  1327. (Defun vlxls-cell-put-aci (xl id aci / Rtn)
  1328.   (if (null aci)
  1329.     (msxl-put-colorindex
  1330.       (msxl-get-interior (setq Rtn (msxl-get-range xl id)))
  1331.       (vlax-make-variant -4142)
  1332.     )
  1333.     (msxl-put-colorindex
  1334.       (msxl-get-interior (setq Rtn (msxl-get-range xl id)))
  1335.       (vlxls-color-aci->eci aci)
  1336.     )
  1337.   )
  1338.   Rtn
  1339. )
  1340. ;|
  1341. Examples:
  1342. (vlxls-cell-put-aci *xlapp* “C12” 6) è#<VLA-OBJECT Range 09d1369c>
  1343. (vlxls-cell-put-aci *xlapp* “C12” nil) è#<VLA-OBJECT Range 09d1369c>
  1344. Excel Cell and Range Progress Function
  1345. Name
  1346. (vlxls-text-get-aci ExcelSessionVLA-OBJECT CellIDStringOrList)
  1347. Usage
  1348. Get the text color (In AutoCAD ColorIndex mode) of certain Excel cells.
  1349. Input
  1350. VLOBJ
  1351. The Excel Session vla-object
  1352. STR/LIST
  1353. The Cell ID list or string
  1354. RetVal
  1355. True
  1356. INT
  1357. Valid ACI Integer number (0 to 256)
  1358. Fail
  1359. BOOLEAN
  1360. NIL
  1361. |;
  1362. (Defun vlxls-text-get-aci (xl id)
  1363.   (vlxls-color-eci->aci
  1364.     (vlax-variant-value
  1365.       (msxl-get-colorindex
  1366.        (msxl-get-font (msxl-get-range xl id))
  1367.       )
  1368.     )
  1369. )
  1370. Rtn
  1371. )
  1372. ;|
  1373. Examples:
  1374. (vlxls-text-get-aci *xlapp* “C12”) è256
  1375. (vlxls-text-get-aci *xlapp* ‘(12 3)) è15
  1376. Excel Cell and Range Progress Function
  1377. Name
  1378. (vlxls-text-put-aci ExcelSessionVLA-OBJECT CellIDStringOrList ACINumber)
  1379. Usage
  1380. Put or clear the content color (In AutoCAD ColorIndex mode) of certain Excel cells.
  1381. Input
  1382. VLOBJ
  1383. The Excel Session vla-object
  1384. STR/LIST
  1385. The Cell ID list or string
  1386. INT
  1387. ACI Integer number, NIL for remove background color
  1388. RetVal
  1389. True
  1390. VLOBJ
  1391. Modified Excel Range vla-object
  1392. Fail
  1393. BOOLEAN
  1394. NIL
  1395. |;
  1396. (Defun vlxls-text-put-aci (xl id aci / Rtn)
  1397.   (if (null aci)
  1398.     (msxl-put-colorindex
  1399.       (msxl-get-font (setq Rtn (msxl-get-range xl id)))
  1400.       (vlax-make-variant -4105)
  1401.     )
  1402.     (msxl-put-colorindex
  1403.       (msxl-get-font (setq Rtn (msxl-get-range xl id)))
  1404.       (vlxls-color-aci->eci aci)
  1405.     )
  1406.   )
  1407.   Rtn
  1408. )
  1409. ;|
  1410. Examples:
  1411. (vlxls-text-put-aci *xlapp* “C12” 6) è#<VLA-OBJECT Range 09d1369c>
  1412. (vlxls-text-put-aci *xlapp* “C12” nil) è#<VLA-OBJECT Range 09d1369c>
  1413. Excel Cell and Range Progress Function
  1414. Name
  1415. (vlxls-text-get-prop ExcelSessionVLA-OBJECT CellIDStringOrList)
  1416. Usage
  1417. Get the properties of content of certain Excel cells. Multiple cells will only record the Left-Upper cell.
  1418. Input
  1419. VLOBJ
  1420. The Excel Session vla-object
  1421. STR/LIST
  1422. The Cell ID list or string
  1423. RetVal
  1424. True
  1425. LIST
  1426. A dot-paired list contain text properties. Syntax is as following:
  1427. ((0 . LeftUpperCellID)(7 . FontStyle) (62 . TextACIColor) (72 . TextAlignment) (420 . TextTrueColor))
  1428. FontStyle will be recorded as Windows TTF font name displayed in Excel
  1429. VLXLS only support horizontal for TextAlignment: 9=Left, 10=Center, 11=Right
  1430. Fail
  1431. BOOLEAN
  1432. NIL
  1433. |;
  1434. (Defun vlxls-text-get-prop
  1435.        (xl id / Cell Font DXF1 DXF7 DXF40 DXF72 DXF62 DXF420 Rtn)
  1436.   (setq   id     (car (vlxls-cellid id))
  1437.        cell   (msxl-get-range xl id)
  1438.        font   (msxl-get-font cell)
  1439.        DXF7   (vlax-variant-value (msxl-get-name Font))
  1440.        DXF40  (vlax-variant-value (msxl-get-size Font))
  1441.        DXF72  (vlax-variant-value
  1442.                (msxl-get-HorizontalAlignment Cell)
  1443.               )
  1444.        DXF72  (cond ((= DXF72 -4152) 11)
  1445.                    ((= DXF72 -4108) 10)
  1446.                    (t 9)
  1447.               )
  1448.        DXF62  (vlxls-color-eci->aci
  1449.                (vlax-variant-value (msxl-get-colorIndex Font))
  1450.               )
  1451.        DXF420 (vlxls-color-eci->truecolor
  1452.                (vlax-variant-value (msxl-get-colorIndex Font))
  1453.               )
  1454.        Rtn    (list (cons 0 (strcase id))
  1455.                    (cons 7 DXF7)
  1456.                    (cons 40 DXF40)
  1457.                    (cons 62 DXF62)
  1458.                    (cons 72 DXF72)
  1459.                    (cons 420 DXF420)
  1460.               )
  1461.   )
  1462.   Rtn
  1463. )
  1464. ;|
  1465. Examples:
  1466. (vlxls-text-get-prop *xlapp* “C12”) è((0 . "C12") (7 . "Arial") (40 . 12.0) (62 . 256) (72 . 9) (420 . 16711935))
  1467. (vlxls-text-get-prop *xlapp* ‘(2 10)) è((0 . "B10") (7 . "Arial") (40 . 12.0) (62 . 256) (72 . 11) (420 . 16711935))
  1468. Excel Cell and Range Progress Function
  1469. Name
  1470. (vlxls-cell-get-prop ExcelSessionVLA-OBJECT CellIDString)
  1471. Usage
  1472. Get the properties of certain Excel cells.
  1473. Input
  1474. VLOBJ
  1475. The Excel Session vla-object
  1476. STR
  1477. The Cell ID string
  1478. RetVal
  1479. True
  1480. LIST
  1481. A dot-paired list contain cell properties. Syntax is as following:
  1482. ((0 . CellIDString)(1 . CellValueList) (10 . LeftUpperLocation_of_LeftUpperCell) (41 . TotalColumnWidth)
  1483. (42 . TotalRowHeight) (-1 . ReturnValue_of_vlxls-text-get-prop))
  1484. If only one cell, CellValueList can be a string, or it will be a 2 dimension list.
  1485. LeftUpperLocation_of_LeftUpperCell is in Excel units and Cell “A1” will be original.
  1486. TotalRowHeight and TotalColumnWidth are both in Excel units
  1487. Fail
  1488. BOOLEAN
  1489. NIL
  1490. |;
  1491. (Defun vlxls-cell-get-prop
  1492.        (xl id / range left top width height dxf10 Rtn)
  1493.   (if (vlxls-cell-merge-p xl id)
  1494.     (setq id (vlxls-cell-get-mergeid xl id))
  1495.   )
  1496.   (setq   range  (msxl-get-range xl id)
  1497.        left   (vlax-variant-value (msxl-get-left Range))
  1498.        top    (vlax-variant-value (msxl-get-top Range))
  1499.        width  (vlax-variant-value (msxl-get-width Range))
  1500.        height (vlax-variant-value (msxl-get-height Range))
  1501.        dxf10  (list left top)
  1502.        Rtn    (list (cons 0 (strcase id))
  1503.                    (cons 1 (vlxls-cell-get-value xl id))
  1504.                    (cons 10 dxf10)
  1505.                    (cons 41 width)
  1506.                    (cons 42 height)
  1507.                    (cons -1 (vlxls-text-get-prop xl id))
  1508.               )
  1509.   )
  1510.   Rtn
  1511. )
  1512. ;|
  1513. Examples:
  1514. (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)))
  1515. (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)))
  1516. Excel Cell and Range Progress Function
  1517. Name
  1518. (vlxls-cell-border ExcelSessionVLA-OBJECT CellIDString)
  1519. Usage
  1520. Force to draw or hide 4 slim border to certain Excel cells.
  1521. Input
  1522. VLOBJ
  1523. The Excel Session vla-object
  1524. STR/LIST
  1525. The Cell ID list or string
  1526. BOOLEAN
  1527. Flag to draw border line or NOT, T for draw, NIL for disable
  1528. RetVal
  1529. True
  1530. BOOLEAN
  1531. NIL
  1532. Fail
  1533. BOOLEAN
  1534. NIL
  1535. |;
  1536. (Defun vlxls-cell-border (xl id flg / bdr)
  1537.   (if flg
  1538.     (msxl-put-value
  1539.       (msxl-get-borders
  1540.        (msxl-get-range xl id)
  1541.       )
  1542.       1
  1543.     )
  1544.     (msxl-put-value
  1545.       (msxl-get-borders
  1546.        (msxl-get-range xl id)
  1547.       )
  1548.       'linestyle
  1549.       msxl-xlnone
  1550.     )
  1551.   )
  1552. )
  1553. ;|
  1554. Examples:
  1555. (vlxls-cell-border *xlapp* “C12:F14” T) èNIL
  1556. (vlxls-cell-border *xlapp* “B8” NIL) èNIL
  1557. Excel Cell and Range Progress Function
  1558. Name
  1559. (vlxls-cell-merge ExcelSessionVLA-OBJECT CellIDString)
  1560. Usage
  1561. Run cell merge in Excel. Only 1st un-empty value will be left in merged cell.
  1562. Input
  1563. VLOBJ
  1564. The Excel Session vla-object
  1565. STR/LIST
  1566. The Cell ID list or string
  1567. RetVal
  1568. True
  1569. VLOBJ
  1570. New merged cell range vla-object
  1571. Fail
  1572. BOOLEAN
  1573. NIL
  1574. |;
  1575. (Defun vlxls-cell-merge      (xl id / vllist-explode Val Rtn)
  1576.   (Defun vllist-explode       (lst)
  1577.     (cond
  1578.       ((not lst) nil)
  1579.       ((atom lst) (list lst))
  1580.       ((append (vllist-explode (car lst))
  1581.               (vllist-explode (cdr lst))
  1582.        )
  1583.       )
  1584.     )
  1585.   )
  1586.   (setq val (vllist-explode (vlxls-cell-get-value xl id)))
  1587.   (while (vl-position "" val)
  1588.     (setq val (vl-remove "" val))
  1589.   )
  1590.   (setq   val (car val)
  1591.        Rtn (msxl-get-range xl id)
  1592.   )
  1593.   (msxl-clear Rtn)
  1594.   (msxl-merge Rtn nil)
  1595.   (msxl-put-value2 Rtn Val)
  1596.   (msxl-put-HorizontalAlignment Rtn -4108)
  1597.   Rtn
  1598. )
  1599. ;|
  1600. Examples:
  1601. (vlxls-cell-merge *xlapp* “C12:F14”) è#<VLA-OBJECT Range 0023ab7c>
  1602. Excel Cell and Range Progress Function
  1603. Name
  1604. (vlxls-cell-unmerge ExcelSessionVLA-OBJECT CellIDString)
  1605. Usage
  1606. Run cell unmerge in Excel. merged value will be placed into the left upper cell, others will be empty.
  1607. If given Cell ID is not a valid merged cell, return NIL
  1608. Input
  1609. VLOBJ
  1610. The Excel Session vla-object
  1611. STR/LIST
  1612. The Cell ID list or string
  1613. RetVal
  1614. True
  1615. VLOBJ
  1616. All unmerged cells range vla-object
  1617. Fail
  1618. BOOLEAN
  1619. NIL
  1620. |;
  1621. (Defun vlxls-cell-unmerge (xl id / Rtn)
  1622.   (if (vlxls-cell-merge-p xl id)
  1623.     (progn
  1624.       (vlax-invoke-method (msxl-get-range xl id) 'unmerge)
  1625.       (setq Rtn (msxl-get-range xl id))
  1626.     )
  1627.   )
  1628.   Rtn
  1629. )
  1630. ;|
  1631. Examples:
  1632. (vlxls-cell-unmerge *xlapp* “C12:F14”) è#<VLA-OBJECT Range 0023ab7c>
  1633. (vlxls-cell-unmerge *xlapp* “E14”) è#<VLA-OBJECT Range 09ce72e4>
  1634. Excel Cell and Range Progress Function
  1635. Name
  1636. (vlxls-cell-merge-p ExcelSessionVLA-OBJECT CellIDString)
  1637. Usage
  1638. Check if the certain Excel cell is merged
  1639. Input
  1640. VLOBJ
  1641. The Excel Session vla-object
  1642. STR/LIST
  1643. The Cell ID list or string
  1644. RetVal
  1645. True
  1646. BOOLEAN
  1647. T
  1648. Fail
  1649. BOOLEAN
  1650. NIL
  1651. |;
  1652. (Defun vlxls-cell-merge-p (xl id)
  1653.   (equal (vlax-variant-value
  1654.           (msxl-get-mergecells (msxl-get-range xl id))
  1655.         )
  1656.         :vlax-true
  1657.   )
  1658. )
  1659. ;|
  1660. Examples:
  1661. (vlxls-cell-merge-p *xlapp* “C12:F14”) èT
  1662. (vlxls-cell-merge-p *xlapp* “E14”) èNIL
  1663. Excel Cell and Range Progress Function
  1664. Name
  1665. (vlxls-cell-get-mergeid ExcelSessionVLA-OBJECT CellIDString)
  1666. Usage
  1667. Get the Left-Upper and Right-Lower Cell ID of a merged cell.
  1668. Input
  1669. VLOBJ
  1670. The Excel Session vla-object
  1671. STR/LIST
  1672. Any Cell ID list or string of a merged cell
  1673. RetVal
  1674. True
  1675. STRING
  1676. A string contain Left-Upper and Right-Lower cells’ ID
  1677. Fail
  1678. BOOLEAN
  1679. NIL
  1680. |;
  1681. (Defun vlxls-cell-get-mergeid (XL ID / Rtn)
  1682.   (if (vlxls-cell-merge-p xl id)
  1683.     (progn
  1684.       (msxl-select (msxl-get-range xl id))
  1685.       (setq Rtn (vlxls-range-getid (msxl-get-selection xl)))
  1686.     )
  1687.   )
  1688.   Rtn
  1689. )
  1690. ;|
  1691. Examples:
  1692. (vlxls-cell-get-mergeid *xlapp* “C12:F14”) è”B9:G19”
  1693. (vlxls-cell-get-mergeid *xlapp* “E14”) è”A11:G19”
  1694. Excel Cell and Range Progress Function
  1695. Name
  1696. (vlxls-range-getid RangeObject)
  1697. Usage
  1698. Get the Left-Upper and Right-Lower Cell ID of a range object.
  1699. Input
  1700. VLOBJ
  1701. The Excel Range vla-object
  1702. RetVal
  1703. True
  1704. STRING
  1705. A string contain Left-Upper and Right-Lower cells’ ID
  1706. Fail
  1707. BOOLEAN
  1708. NIL
  1709. |;
  1710. (Defun vlxls-range-getID (range / col row dx dy)
  1711.   (setq   dx  (vlxls-get-property range "MergeArea.Rows.Count")
  1712.        dy  (vlxls-get-property range "MergeArea.Columns.Count")
  1713.        row (vlxls-get-property range "MergeArea.Row")
  1714.        col (vlxls-get-property range "MergeArea.Column")
  1715.   )
  1716.   (strcat (vlxls-rangeid (list col row))
  1717.          ":"
  1718.          (vlxls-rangeid (list (1- (+ col dy)) (1- (+ row dx))))
  1719.   )
  1720. )
  1721. ;|
  1722. Examples:
  1723. (vlxls-range-getid RangeObject) è”C12:G19”
  1724. (vlxls-range-getid RangeObject) è”B16:B16”
  1725. Excel Cell and Range Progress Function
  1726. Name
  1727. (vlxls-range-size RangeObject)
  1728. Usage
  1729. Get the column width and row height list of a range object.
  1730. Input
  1731. VLOBJ
  1732. The Excel Range vla-object
  1733. RetVal
  1734. True
  1735. STRING
  1736. A list contain two sub-list, each sub-list contain real number of columns' width and rows' height. Syuntax:
  1737. ((Column1Width Column2Width…)(Row1Height Row2Height…))
  1738. Fail
  1739. BOOLEAN
  1740. NIL
  1741. |;
  1742. (Defun vlxls-range-size      (range / xl row col rrr ccc xxx yyy)
  1743.   (setq   xl  (msxl-get-parent range)
  1744.        Row (msxl-get-count (msxl-get-rows Range))
  1745.        Col (msxl-get-count (msxl-get-columns Range))
  1746.        RRR (1- (msxl-get-row Range))
  1747.        CCC (msxl-get-column Range)
  1748.   )
  1749.   (repeat Row
  1750.     (setq
  1751.       yyy (cons   (vlax-variant-value
  1752.                 (msxl-get-height
  1753.                   (msxl-get-range
  1754.                     xl
  1755.                     (vlxls-rangeid (list CCC (setq RRR (1+ RRR))))
  1756.                   )
  1757.                 )
  1758.               )
  1759.               yyy
  1760.          )
  1761.     )
  1762.   )
  1763.   (setq   RRR (msxl-get-row Range)
  1764.        CCC (1- (msxl-get-column Range))
  1765.   )
  1766.   (repeat Col
  1767.     (setq
  1768.       xxx (cons   (vlax-variant-value
  1769.                 (msxl-get-width
  1770.                   (msxl-get-range
  1771.                     xl
  1772.                     (vlxls-rangeid (list (setq CCC (1+ CCC)) RRR))
  1773.                   )
  1774.                 )
  1775.               )
  1776.               xxx
  1777.          )
  1778.     )
  1779.   )
  1780.   (list (reverse xxx) (reverse yyy))
  1781. )
  1782. ;|
  1783. Examples:
  1784. (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))
  1785. Excel Cell and Range Progress Function
  1786. Name
  1787. (vlxls-rangevalue->safearray RangeValueList)
  1788. Usage
  1789. Convert a Range-Value-List into safearray list so that they can be passed into Excel directly.
  1790. 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"))
  1791. 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.
  1792. Input
  1793. VLOBJ
  1794. The Excel Range vla-object
  1795. RetVal
  1796. True
  1797. STRING
  1798. A safearray variant contain all given Range-Value-List
  1799. Fail
  1800. BOOLEAN
  1801. NIL
  1802. |;
  1803. (Defun vlxls-Rangevalue->SafeArray (Data       /      XSub_GetXY
  1804.                                 XSub_GetMinMaxID
  1805.                                 xsub-MergeID->List       MinID
  1806.                                 MaxID      ID       ID1
  1807.                                 ID2         IDN     X
  1808.                                 minid      xy        Y
  1809.                                 Rtn         Item
  1810.                                )
  1811.   (Defun xsub-MergeID->List (ID / KK ID1 ID2 IDX IDY Rtn)
  1812.     (Setq ID (strcase ID))
  1813.     (if    (setq KK (vl-string-search ":" ID))
  1814.       (setq ID1   (substr ID 1 KK)
  1815.            ID2  (substr ID (+ 2 KK))
  1816.       )
  1817.       (setq ID1   ID
  1818.            ID2  ID
  1819.       )
  1820.     )
  1821.     (setq ID1 (vlxls-rangeid ID1)
  1822.          ID2 (vlxls-rangeid ID2)
  1823.          IDX (vlxls-rangeid
  1824.               (list (min (nth 0 ID1) (nth 0 ID2))
  1825.                     (min (nth 1 ID1) (nth 1 ID2))
  1826.               )
  1827.              )
  1828.          IDY
  1829.              (vlxls-rangeid
  1830.               (list (max (nth 0 ID1) (nth 0 ID2))
  1831.                     (max (nth 1 ID1) (nth 1 ID2))
  1832.               )
  1833.              )
  1834.          Rtn (list IDX IDY)
  1835.     )
  1836.     Rtn
  1837.   )
  1838.   (Defun XSub_GetXY (ID SID / S10 S11 DX DY Rtn)
  1839.     (setq S10 (nth 0 MinID)
  1840.          S11 (nth 1 MinID)
  1841.          ID  (vlxls-rangeid ID)
  1842.          DX  (- (nth 0 ID) S10)
  1843.          DY  (- (nth 1 ID) S11)
  1844.          Rtn (list DX DY)
  1845.     )
  1846.     Rtn
  1847.   )
  1848.   (Defun XSub_GetMinMaxID (ID1 ID MinorMax / X Y X1 Y1 Rtn)
  1849.     (if    (null ID)
  1850.       (setq Rtn ID1)
  1851.       (progn
  1852.        (setq ID1 (vlxls-rangeid ID1)
  1853.              ID  (vlxls-rangeid ID)
  1854.              X1  (nth 0 ID1)
  1855.              Y1  (nth 1 ID1)
  1856.              X    (nth 0 ID)
  1857.              Y   (nth 1 ID)
  1858.        )
  1859.        (if (null MinorMax)
  1860.          (setq Rtn (vlxls-rangeid (list (min X X1) (min Y Y1))))
  1861.          (setq Rtn (vlxls-rangeid (list (max X X1) (max Y Y1))))
  1862.        )
  1863.       )
  1864.     )
  1865.     Rtn
  1866.   )
  1867.   (foreach Item    Data
  1868.     (setq ID (strcase (car Item)))
  1869.     (if    (vl-string-search ":" ID)
  1870.       (setq IDN (xsub-MergeID->List ID))
  1871.       (setq IDN (list ID))
  1872.     )
  1873.     (foreach ID    IDN
  1874.       (setq MinID (XSub_GetMinMaxID ID MinID nil)
  1875.            MaxID (XSub_GetMinMaxID ID MaxID T)
  1876.       )
  1877.     )
  1878.   )
  1879.   (setq   MinID (vlxls-rangeid MinID)
  1880.        MaxID (vlxls-rangeid MaxID)
  1881.        X     (- (nth 0 MaxID) (nth 0 MinID))
  1882.        Y     (- (nth 1 MaxID) (nth 1 MinID))
  1883.        Rtn   (vlax-make-safearray
  1884.               vlax-vbstring
  1885.               (cons 0 Y)
  1886.               (cons 1 (1+ X))
  1887.              )
  1888.   )
  1889.   (foreach Item    Data
  1890.     (setq ID (strcase (car Item)))
  1891.     (if    (vl-string-search ":" ID)
  1892.       (setq IDN (xsub-MergeID->List ID))
  1893.       (setq IDN (list ID))
  1894.     )
  1895.     (foreach ID    IDN
  1896.       (setq XY (XSub_GetXY ID MinID))
  1897.       (vlax-safearray-put-element
  1898.        Rtn
  1899.        (nth 1 XY)
  1900.        (1+ (nth 0 XY))
  1901.        (cdr Item)
  1902.       )
  1903.     )
  1904.   )
  1905.   Rtn
  1906. )
  1907. ;|
  1908. Examples:
  1909. (vlxls-rangevalue->safearray ‘((“A1” . “aaa”)(“B4” . “ccc”))) è#<safearray...>
  1910. (vlxls-variant->list (vlxls-rangevalue->safearray '(("A1" . "aaa")("B4" . "ccc"))))è(("aaa" "") ("" "") ("" "") ("" "ccc"))
  1911. Public Function
  1912. Name
  1913. (vlxls-get-property TopVLAObject NestPropertyString)
  1914. Usage
  1915. Get the property of a nested VLA-Object from the main top vla-object. Use same property indicator as VBA.
  1916. Input
  1917. VLOBJ
  1918. The Top vla-object
  1919. STRING
  1920. The Property combination string, divided with “.”, ordered from top to inner.
  1921. RetVal
  1922. True
  1923. ANY
  1924. The value of the most nested property.
  1925. Fail
  1926. BOOLEAN
  1927. NIL
  1928. |;
  1929. (Defun vlxls-get-property (top prop / vlstring->list item Rtn)
  1930.   (Defun vlstring->list (str st / lst e)
  1931.     (setq str (strcat str st))
  1932.     (while (vl-string-search st str)
  1933.       (setq
  1934.        lst
  1935.         (append lst (list (substr str 1 (vl-string-search st str))))
  1936.       )
  1937.       (setq
  1938.        str
  1939.         (substr str (+ (1+ (strlen st)) (vl-string-search st str)))
  1940.       )
  1941.     )
  1942.     (if    lst
  1943.       (mapcar '(lambda (e) (vl-string-trim " " e)) lst)
  1944.     )
  1945.   )
  1946.   (cond  ((= (type prop) 'sym)
  1947.         (setq Rtn (vlax-get-property top prop))
  1948.        )
  1949.        ((= (type prop) 'str)
  1950.         (if (null (vl-string-search "." prop))
  1951.           (setq Rtn (vlax-get-property top prop))
  1952.           (foreach item (vlstring->list prop ".")
  1953.             (if (null Rtn)
  1954.               (setq Rtn (vlax-get-property top item))
  1955.               (setq Rtn (vlax-get-property Rtn item))
  1956.             )
  1957.           )
  1958.         )
  1959.        )
  1960.   )
  1961.   (cond  ((= (type Rtn) 'variant)
  1962.         (setq Rtn (vlax-variant-value Rtn))
  1963.        )
  1964.        ((= (type Rtn) 'safearray)
  1965.         (setq Rtn (vlxls-variant->list Rtn))
  1966.        )
  1967.   )      
  1968.   Rtn
  1969. )
  1970. ;|
  1971. Examples:
  1972. (vlxls-get-property RangeObject “Application.ActiveSheet.Name”) è”Sheet1”
  1973. (vlxls-get-property RangeObject “MergeArea.Columns.Count”) è3
  1974. 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.
  1975. 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.
  1976. |;
  1977. (setq *xls-color*
  1978.        (list (list 1 18 0)
  1979.             (list 2 7 1677215)
  1980.             (list 3 1 16711680)
  1981.             (list 4 3 65280)
  1982.             (list 5 5 255)
  1983.             (list 6 2 16776960)
  1984.             (list 7 6 16711935)
  1985.             (list 8 4 65535)
  1986.             (list 9 16 8323072)
  1987.             (list 10 96 32512)
  1988.             (list 11 176 127)
  1989.             (list 12 56 8355584)
  1990.             (list 13 216 8323199)
  1991.             (list 14 136 32639)
  1992.             (list 15 9 12566463)
  1993.             (list 16 8 8355711)
  1994.             (list 17 161 9476095)
  1995.             (list 18 237 9449568)
  1996.             (list 19 7 1677167)
  1997.             (list 20 254 12648447)
  1998.             (list 21 218 6291552)
  1999.             (list 22 11 16744319)
  2000.             (list 23 152 24768)
  2001.             (list 24 254 13617407)
  2002.             (list 25 176 127)
  2003.             (list 26 6 16711935)
  2004.             (list 27 2 16776960)
  2005.             (list 28 4 65535)
  2006.             (list 29 216 8323199)
  2007.             (list 30 16 8323072)
  2008.             (list 31 136 32639)
  2009.             (list 32 5 255)
  2010.             (list 33 140 51455)
  2011.             (list 34 254 12648447)
  2012.             (list 35 254 13631439)
  2013.             (list 36 51 16777104)
  2014.             (list 37 151 9488639)
  2015.             (list 38 221 16750799)
  2016.             (list 39 191 13605119)
  2017.             (list 40 31 16763024)
  2018.             (list 41 150 3105023)
  2019.             (list 42 132 3131584)
  2020.             (list 43 62 9488384)
  2021.             (list 44 40 16762880)
  2022.             (list 45 30 16750336)
  2023.             (list 46 30 16738048)
  2024.             (list 47 165 6317968)
  2025.             (list 48 252 9475984)
  2026.             (list 49 148 12384)
  2027.             (list 50 105 3184736)
  2028.             (list 51 98 12032)
  2029.             (list 52 48 3158016)
  2030.             (list 53 24 9449472)
  2031.             (list 54 237 9449311)
  2032.             (list 55 177 3158160)
  2033.             (list 56 250 3092527)
  2034.        )
  2035.     *Chinese* t
  2036. )
  2037. (if vl-load-com
  2038.   (vl-load-com)
  2039. )
  2040. (if vl-arx-import
  2041.   (foreach item    '(ACAD_COLORDLG       ACAD_truecolordlg
  2042.                 ACAD_STRLSORT      INITDIA
  2043.                 ACAD-POP-DBMOD     ACAD-PUSH-DBMOD
  2044.                 STARTAPP            layoutlist
  2045.                )
  2046.     (vl-arx-import item)
  2047.   )
  2048. )
  2049. (setq item      nil
  2050.       *xls-ver*     "1.2.50331"
  2051. )
  2052. ;|(princ
  2053.   (strcat "n VLAE:VLXLS Freebie API Version " *xls-ver*)
  2054. )
  2055. (princ
  2056.   "n Copyright(C) 1994-2005 KozMos Inc. All rights reserved"
  2057. )
  2058. |;
  2059. ;(princ)
  2060. ;;;;;;;;;;;;;;;;;
  2061. (defun vlxls-ScreenUpdating-Off  (*xlapp*)
  2062.   (vlax-put-property *xlapp* 'ScreenUpdating 0))
  2063. (defun vlxls-ScreenUpdating-On  (*xlapp*)
  2064.   (vlax-put-property *xlapp* 'ScreenUpdating -1))
  2065. ;;*************************************************************************
  2066. ;;; 模塊: vlxls-Excel-ColumnWidth
  2067. ;;; 描述: 調整寬度col為width
  2068. ;;; 參數: sheet (object)
  2069. ;;; 示例: (vlxls-Excel-ColumnWidth xlapp 2 12);;調整B欄寬為12
  2070. ;;;*************************************************************************
  2071. (defun vlxls-ColumnWidth(xlapp col width / sheet cell)
  2072.   (setq sheet (vlax-get-property xlapp "ActiveSheet"))
  2073.   (vlax-put-property (setq cell (vlxls-get-cell sheet 1 col)) "ColumnWidth"
  2074. width)
  2075.   )
  2076. ;;;*************************************************************************
  2077. ;;; 模塊: mSX-Excel-RowHeight
  2078. ;;; 描述: 調整列高row為height
  2079. ;;; 參數: sheet (object)
  2080. ;;; 示例: (mSX-Excel-ColumnWidth xlapp 3 15);;調整3列高為15
  2081. ;;;*************************************************************************
  2082. (defun vlxls-RowHeight(xlapp row height / sheet cell)
  2083.   (setq sheet (vlax-get-property xlapp "ActiveSheet"))
  2084.   (vlax-put-property (setq cell (vlxls-get-cell sheet row 1)) "RowHeight"
  2085. height)
  2086.   )
  2087. (defun vlxls-get-cell  (obj row col / item cells)
  2088.   (setq item (vlax-get-property
  2089.     (setq cells (vlax-get-property obj "Cells"))
  2090.     "Item"
  2091.     (vlax-make-variant row)
  2092.     (vlax-make-variant col)))
  2093.   (vlax-release-object cells)
  2094.   (vlax-variant-value item))
  2095. (defun vlxls-put-pagesetup(xlapp top bot lef rig hea fot flh flv);;設置版面
  2096.   (setq sheet (vlax-get-property xlapp "ActiveSheet"))
  2097.   (setq page (vlax-get-property sheet "pagesetup"))
  2098.   (vlax-put-property page "footermargin" (* fot 28.3465))
  2099.   (vlax-put-property page "headermargin" (* hea 28.3465))
  2100.   (vlax-put-property page "leftmargin" (* lef 28.3465))
  2101.   (vlax-put-property page "rightmargin" (* 28.3465 rig))
  2102.   (vlax-put-property page "topmargin" (* top 28.3465))
  2103.   (vlax-put-property page "bottommargin" (* bot 28.3465))
  2104.   (vlax-put-property page "CenterHorizontally" (* 28.3465 flh))
  2105.   (vlax-put-property page "CenterVertically" (* flv 28.3465))
  2106.   )
  2107. ;;;*************************************************************************
  2108. ;;; 模塊: vlxls-Excel-cellfontname
  2109. ;;; 描述: 更改單元格字體
  2110. ;;; 參數: row col name
  2111. ;;; 示例: (vlxls-Excel-cellfontname 2 3 "新細明體");;更改單元格C2字體為"新細明體"
  2112. ;;;*************************************************************************
  2113. (defun vlxls-Excel-cellfontname(xlapp row col name / sheet cell)
  2114.   (setq sheet (vlax-get-property xlapp "ActiveSheet"))
  2115.   (vlax-put-property(vlax-get-property (setq cell (msx-get-cell sheet row col)) "font"
  2116. ) "name" name
  2117.   ))
  2118. ;;;*************************************************************************
  2119. ;;; 模塊: vlxls-Excel-cellcolor
  2120. ;;; 描述: 更改單元格顏色
  2121. ;;; 參數: row col color
  2122. ;;; 示例: (vlxls-Excel-cellcolor2 3 14);;更改單元格C2為14號色
  2123. ;;;*************************************************************************
  2124. (defun vlxls-Excel-cellcolor(xlapp row col color / sheet cell)
  2125.   (setq sheet (vlax-get-property xlapp  "ActiveSheet"))
  2126.   (setq cell (vlxls-get-cell sheet row col))
  2127.   (msxl-put-ColorIndex (msxl-get-Interior cell) color))
  2128. ;;;*************************************************************************
  2129. ;;; 模塊: vlxls-Excel-textcolor
  2130. ;;; 描述: 更改單元格文字顏色
  2131. ;;; 參數: row col color
  2132. ;;; 示例: (vlxls-Excel-textcolor 2 3 14);;更改單元格C2文字為14號色
  2133. ;;;*************************************************************************
  2134. (defun vlxls-Excel-textcolor(xlapp row col color / sheet cell)
  2135.   (setq sheet (vlax-get-property xlapp "ActiveSheet"))
  2136.   (setq cell (vlxls-get-cell sheet row col))
  2137.   (vlax-put-property (vlax-get-property cell "font") "ColorIndex" color))
  2138. ;;;*************************************************************************
  2139. ;;; 模塊: vlxls-Excel-textsize
  2140. ;;; 描述: 更改單元格文字大小
  2141. ;;; 參數: row col size
  2142. ;;; 示例: (vlxls-Excel-textsize 2 3 18);;更改單元格C2文字為18號字大小
  2143. ;;;*************************************************************************
  2144. (defun vlxls-Excel-textsize(xlapp row col size / sheet cell)
  2145.   (setq sheet (vlax-get-property xlapp "ActiveSheet"))
  2146.   (setq cell (vlxls-get-cell sheet row col))
  2147.   (vlax-put-property (vlax-get-property cell "font") "Size" size))
  2148. ;;;*************************************************************************
  2149. ;;; 模塊: vlxls-Excel-textunderline
  2150. ;;; 描述: 更改單元格文字下畫線
  2151. ;;; 參數: row col size
  2152. ;;; 示例: (vlxls-Excel-textunderline 2 3 1);;更改單元格C2文字無下划線
  2153. ;;;*************************************************************************
  2154. (defun vlxls-Excel-textunderline(xlapp row col underline / sheet cell)
  2155.   (setq sheet (vlax-get-property xlapp "ActiveSheet"))
  2156.   (setq cell (vlxls-get-cell sheet row col))
  2157.   (vlax-put-property (vlax-get-property cell "font") "Underline" underline))
  2158. ;;;;;注:   underline 1---------無下划線
  2159. ;;;;;                2---------單線
  2160. ;;;;;                3---------雙線
  2161. ;;;;;                4---------會計用單線
  2162. ;;;;;                5---------會計用雙線
  2163. ;;;*************************************************************************
  2164. ;;; 模塊: vlxls-Excel-fontstyle
  2165. ;;; 描述: 更改單元格文字形式
  2166. ;;; 參數: row col color
  2167. ;;; 示例: (vlxls-Excel-fontstyle 2 3 "粗體");;更改單元格C2文字為14粗體
  2168. ;;;*************************************************************************
  2169. (defun vlxls-Excel-fontstyle(xlapp row col style / sheet cell)
  2170.   (setq sheet (vlax-get-property xlapp "ActiveSheet"))
  2171.   (setq cell (vlxls-get-cell sheet row col))
  2172.   (vlax-put-property (vlax-get-property cell "font") "FontStyle" style))
  2173. ;;;*************************************************************************
  2174. ;;; 模塊: vlxls-Excel-fontspecial
  2175. ;;; 描述: 更改單元格文字特殊效果
  2176. ;;; 參數: row col color
  2177. ;;; 示例: (vlxls-Excel-fontspecial 2 3 "Strikethrough" item);;更改單元格C2文字特殊效果為刪線
  2178. ;;;        "Superscript"為上標 "Subscript" 為下標 (item設置為0則停用,-1為啟用)
  2179. ;;;*************************************************************************
  2180. (defun vlxls-Excel-fontspecial(xlapp row col special item / sheet cell)
  2181.   (setq sheet (vlax-get-property xlapp "ActiveSheet"))
  2182.   (setq cell (vlxls-get-cell sheet row col))
  2183.   (vlax-put-property (vlax-get-property cell "font") special item))
  2184. ;;;*************************************************************************
  2185. ;;; 模塊: vlxls-Excel-textAlignment
  2186. ;;; 描述: 更改單元格文字對齊方式
  2187. ;;; 參數: row col color hal val
  2188. ;;; 示例: (vlxls-Excel-textAlignment 2 3 1 -4108);;更改單元格C2文字對齊方式水平方向一般﹐垂直置中
  2189. ;;;*************************************************************************
  2190. (defun vlxls-Excel-textAlignment (xlapp row col hal val / sheet cell)
  2191.   (setq sheet (vlax-get-property xlapp  "ActiveSheet"))
  2192.   (setq cell (vlxls-get-cell sheet row col))
  2193.   (vlax-put-property  cell  "HorizontalAlignment" hal)
  2194.   (vlax-put-property  cell  "VerticalAlignment" val))
  2195. ;;;注:水平方式  1    ----------一般               
  2196. ;;;;;;;;;      -4131----------左縮排 ;;;;或2
  2197. ;;;;;;;;;      -4108----------置中對齊 ;;或3
  2198. ;;;;;;;;;      -4152----------靠右對齊 ;;或4
  2199. ;;;;;;;;;      5    ----------填滿     ;;或5
  2200. ;;;;;;;;;      -4130----------水平對齊 ;;或6
  2201. ;;;;;;;;;          7----------跨欄置中  
  2202. ;;;;;;;;;      -4117----------分散對齊  ;;或8
  2203. ;;;注:垂直方式  -4160 ----------靠上        或1      
  2204. ;;;;;;;;;       -4108----------置中對齊     或2
  2205. ;;;;;;;;;       -4107----------靠下         或3
  2206. ;;;;;;;;;       -4130----------垂直對齊     或4
  2207. ;;;;;;;;;       -4117 ----------分散對齊    或5
  2208. ;;;页面设置
  2209. ;;;(vlxls-Excel-Pagesetup *xlApp* ".LeftFooter" "&P")
  2210. ;;;具体设置参考如下
  2211. ;|
  2212.     ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=ActiveCell  插入分页符
  2213.     With ActiveSheet.PageSetup
  2214.         .PrintTitleRows = "$1:$3"  工作表顶端标题行
  2215.         .PrintTitleColumns = ""    工作表左端标题列
  2216.     End With
  2217.     ActiveSheet.PageSetup.PrintArea = "$C$1:$H$255"   工作表打印区域
  2218.     With ActiveSheet.PageSetup
  2219.         .LeftHeader = ""    左页眉
  2220.         .CenterHeader = ""  中页眉
  2221.         .RightHeader = ""   右页眉
  2222.         .LeftFooter = "&P"  左页脚
  2223.         .CenterFooter = "&N" 中页脚
  2224.         .RightFooter = "aaaaaaaaa"  右页脚
  2225.         .LeftMargin = Application.InchesToPoints(0.62)   左边距
  2226.         .RightMargin = Application.InchesToPoints(0.748031496062992) 右边距
  2227.         .TopMargin = Application.InchesToPoints(0.984251968503937)
  2228.         .BottomMargin = Application.InchesToPoints(0.393700787401575)
  2229.         .HeaderMargin = Application.InchesToPoints(0.511811023622047)
  2230.         .FooterMargin = Application.InchesToPoints(0.511811023622047)   
  2231.         .PrintHeadings = False
  2232.         .PrintGridlines = False
  2233.         .PrintComments = xlPrintNoComments
  2234.         .CenterHorizontally = False
  2235.         .CenterVertically = False
  2236.         .Orientation = xlPortrait
  2237.         .Draft = False
  2238.         .PaperSize = xlPaperA4
  2239.         .FirstPageNumber = xlAutomatic  打印起始页
  2240.         .Order = xlDownThenOver
  2241.         .BlackAndWhite = False
  2242.         .Zoom = 100
  2243.         .PrintErrors = xlPrintErrorsDisplayed
  2244.     End With
  2245. End Sub
  2246. |;
  2247. (defun vlxls-Excel-Pagesetup (xlapp Key var / sheet PageSetup)
  2248.   (setq sheet (vlax-get-property xlapp "ActiveSheet"))
  2249.   (setq PageSetup (vlax-get-property sheet "PageSetup"))
  2250.   (vlax-put-property PageSetup Key var)
  2251.   )
  2252. ;;; ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=ActiveCell
  2253. ;;;在单元格ID 之前插入分页符
  2254. (defun vlxls-Excel-InsertHPageBreaks (xlapp id / sheet HPageBreaks HPageBreaks)
  2255.   (setq sheet (vlax-get-property xlapp "ActiveSheet"))
  2256.   (setq HPageBreaks (vlax-get-property sheet "HPageBreaks"))
  2257.   (vlxls-cell-put-active xlapp id)
  2258.   (vlax-invoke-method HPageBreaks 'Add (vlax-get-property xlapp "Activecell"))
  2259.   )

评分

参与人数 2明经币 +2 收起 理由
tigcat + 1 很给力!
USER2128 + 1 赞一个!

查看全部评分

发表于 2022-4-22 09:18 | 显示全部楼层
这是excel表格转CAD表格吗?
发表于 2022-4-22 09:24 | 显示全部楼层
Kozmos 当年写的 AutoLISP 操作excel 的函数库。非常感谢Kozmos的工作与开源。

Kozmos 也是 Revit LinkDwg 函数库, 室内设计工具“图助理”,Autodesk AppStore上很多工具程序的作者。
发表于 2023-8-11 04:22 | 显示全部楼层
EXCEL版本支持老了点,不知道有没有新的?
发表于 2023-8-14 11:33 | 显示全部楼层
尘缘一生 发表于 2023-8-11 04:22
EXCEL版本支持老了点,不知道有没有新的?

改一下相应的文件名称就可以了。
发表于 2023-8-14 13:31 | 显示全部楼层
新版本Excel的olb库直接集成在exe里面了,不需要取判断,直接用excel.exe就可以。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-2 10:16 , Processed in 2.194603 second(s), 29 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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