明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 155333|回复: 530

[【Gu_xl】] ExCel表格->AutoCAD表格(源码公布)

    [复制链接]
发表于 2013-6-9 13:24 | 显示全部楼层 |阅读模式
本帖最后由 Gu_xl 于 2013-6-22 09:04 编辑

花了两天时间,仿照  KozMos XL2CAD 的程序同样写了一个Excel2CAD程序,控制对话框就直接照搬 KozMos XL2CAD的对话框,操作方式完全和他一样!
2013年6月22日公布全部源码

程序界面:

使用演示:

编译的VLX程序文件:  
2013.06.11更新程序 :
增加按Excel页面设置来分页输出表格功能!(包括页眉、页脚、表头等内容)
新程序界面:

2013.06.12日更新,修正了一些Bug, 增加了表格实体颜色随层或随块的选项。更新了界面如下:
请大家来下载使用,使用过程中发现问题,多提出宝贵意见,等程序完善后,我再放出全部源码,下面是主程序源码:
  1. (defun c:x2c (/        *XLAPP*              ACT_ANNOCOLOR ACT_BLAYER          ACT_CELLCOLOR                ACT_GETFILE   ACT_GROUP            ACT_KEEPTHEIGHT
  2.                 ACT_MERGE     ACT_NONE            ACT_PAGESETUP ACT_PRINTAREA
  3.                 ACT_TLAYER    ACT_UBLOCK    ACT_USED          ACT_USER
  4.                 BASEPOINT     CELLS            COL                  CURPT
  5.                 DCLCODE              DD            DEFAULTHEIGHT DRAWPAGESETUP
  6.                 DXF40              DXF420            DXF62          DXF7
  7.                 DXF71              DXF71DATA            ECODE          ENDENT
  8.                 FONT              GET9JUSTPTS   GETRANGETEXTSTYLE
  9.                 GRIDSCALE     HEIGHT            HEIGHT1
  10.                 HORIZONTALALIGNMENT            HORLINE          HPAGEBREAKS
  11.                 INTERIORCOLOR INTERIORTRUECOLOR                  LAYERS
  12.                 MERGEID              MERGEP            MKTMPDCL         
  13.                 OLDHEIGHT     OLDROW            P0                  P1
  14.                 P2              P3            PAGE          PAGEMARGIN
  15.                 PAGESETUP     PRINTAREA            PRINTTITLEROWS
  16.                 RANGE              RANGEFONT            RIGHTTOPPT          ROW
  17.                 S1              SCALE            SELECTION          SHEET
  18.                 SS              STANDARDFONT  STANDARDFONTSIZE
  19.                 START_XL2X    STARTPOINT    TEXT          TEXTFONT
  20.                 TEXTPT              TEXTVERFLAG   TMP                  TO
  21.                 TOTALHEIGHT   TOTALPAGE            TOTALWIDE          USEDRANGE
  22.                 VERLINES      VERTICALALIGNMENT                  WIDTH
  23.                 WIDTH1              WORKBOOK            WORKBOOKS          ACT_RANGE
  24.                 ACT_THEIGHT   BLAYER            CAPTION          CFONT
  25.                 CHAR              CHARFONT            F
  26.                 HORIZONTALALIGNMEN            I                  II
  27.                 INTERIORCOLOR1                    KD                  SSTITLE
  28.                 TLAYER              TMPPT            VERLINE          TITLEROWS
  29.                 TMP              TMP1            *DRAWRANGE*          *CELLCOLOR*
  30.                 *ANNOCOLOR*   *OPRATE*            *MERGE*          *THEIGHT*
  31.                 *KEEPTHEIGHT* *PAGESETUP*   *DEFAULTCOLOR* SSSolid
  32.                )
  33.   ;;计算九宫格点
  34.   (defun Get9JustPts (LL UR / tmp BC BL BR MC ML MR TC TL TR)
  35.     (setq
  36.       LL (list (car LL) (cadr LL) 0.0)
  37.       UR (list (car UR) (cadr UR) 0.0)
  38.       BL LL
  39.       TR UR
  40.       MC (GXL-MIDPOINT BL TR)
  41.       TL (list (car BL) (cadr TR) 0.0)
  42.       TC (list (car MC) (cadr TR) 0.0)
  43.       MR (list (car TR) (cadr MC) 0.0)
  44.       BR (list (car TR) (cadr BL) 0.0)
  45.       BC (list (car MC) (cadr BL) 0.0)
  46.       ML (list (car BL) (cadr MC) 0.0)
  47.       )
  48.     (list TL TC TR ML MC MR BL BC BR)
  49.     )
  50. ;;创建临时对话框
  51. (defun mkTmpDcl (dclname / tmpdcl f _GetSavePath)
  52.    (DEFUN _GETSAVEPATH (/ TMP)
  53.      (COND ((SETQ TMP (GETVAR (QUOTE ROAMABLEROOTPREFIX)))
  54.             (OR (EQ "\\" (SUBSTR TMP (STRLEN TMP)))
  55.                 (SETQ TMP (STRCAT TMP "\\"))
  56.                 )
  57.             (STRCAT TMP "Support")
  58.             )
  59.            ((SETQ TMP (FINDFILE "ACAD.pat"))
  60.             (SETQ TMP (VL-FILENAME-DIRECTORY TMP))
  61.             (AND (EQ "\\" (SUBSTR TMP (STRLEN TMP)))
  62.                  (SETQ TMP (SUBSTR TMP (1- (STRLEN TMP))))
  63.                  )
  64.             TMP
  65.             )
  66.            )
  67.      )
  68.    (IF DCLNAME
  69.      (SETQ TMPDCL
  70.             (STRCAT (_GETSAVEPATH)
  71.                     "\\"
  72.                     (if        (and
  73.                           (> (strlen DCLNAME) 4)
  74.                           (= ".dcl"
  75.                              (substr (setq DCLNAME (STRCASE DCLNAME T))
  76.                                      (- (strlen DCLNAME) 3)
  77.                                      4
  78.                              )
  79.                           )
  80.                         )
  81.                       (substr DCLNAME 1 (- (strlen DCLNAME) 4))
  82.                       DCLNAME
  83.                     )
  84.                     ".dcl"
  85.             )
  86.      )
  87.      (SETQ TMPDCL (VL-FILENAME-MKTEMP "tmp" "" ".dcl"))
  88.      )
  89.    (if (not (findfile tmpdcl))
  90.      (progn
  91.        (setq f (open tmpdcl "w"))
  92.        (foreach str '("xl2cad:dialog {"
  93.                       "    label = \"Excel 转CAD表格 【Gu_xl】\" ;"
  94.                       "    :boxed_radio_column {"
  95.                       "        key = \"Range\" ;"
  96.                       "        label = \"Excel数据范围\" ;"
  97.                       "        :radio_button {"
  98.                       "            key = \"Used\" ;"
  99.                       "            label = \"所有使用的单元格\" ;"
  100.                       "        }"
  101.                       "        :radio_button {"
  102.                       "            key = \"User\" ;"
  103.                       "            label = \"用户选定的单元格\" ;"
  104.                       "        }"
  105.                       "        :radio_button {"
  106.                       "            key = \"PrintArea\" ;"
  107.                       "            label = \"页面可打印区域\" ;"
  108.                       "        }"
  109.                       "    }"
  110.                       ":button {"
  111.                       "    alignment = left ;"
  112.                       "    fixed_height = true ;"
  113.                       "    fixed_width = true ;"
  114.                       "    key = \"getfile\" ;"
  115.                       "    label = \"选择Excel文件->\" ;"
  116.                       "    width = 20 ;"
  117.                       "}"
  118.                       "    :boxed_column {"
  119.                       "        label = \"生成设定\" ;"
  120.                       "        :row {"
  121.                       "            :toggle {"
  122.                       "                key = \"CellColor\" ;"
  123.                       "                label = \"单元格背景颜色\" ;"
  124.                       "            }"
  125.                       "            :toggle {"
  126.                       "                key = \"AnnoColor\" ;"
  127.                       "                label = \"文 本 颜 色\" ;"
  128.                       "            }"
  129.                       "        }"
  130.                       "        :row {"
  131.                       "        :toggle {"
  132.                       "            key = \"PageSetup\" ;"
  133.                       "            label = \"按页面设置输出\" ;"
  134.                       "        }"
  135.                       "        :toggle {"
  136.                       "            key = \"Merge\" ;"
  137.                       "            label = \"合并表格线\" ;"
  138.                       "        }"
  139.                       "        }"
  140.                       "        :row {"
  141.                       "            :toggle {"
  142.                       "                key = \"KeepTHeight\" ;"
  143.                       "                label = \"缺省文本高度\" ;"
  144.                       "            }"
  145.                       "            :edit_box {"
  146.                       "                key = \"THeight\" ;"
  147.                       "                label = \"\" ;"
  148.                       "            }"
  149.                       "        }"
  150.                       "        :boxed_radio_row {"
  151.                       "            key = \"Gather\" ;"
  152.                       "            label = \"实体集合\" ;"
  153.                       "            :radio_button {"
  154.                       "                key = \"None\" ;"
  155.                       "                label = \"无操作\" ;"
  156.                       "            }"
  157.                       "            :radio_button {"
  158.                       "                key = \"Group\" ;"
  159.                       "                label = \"无名组\" ;"
  160.                       "            }"
  161.                       "            :radio_button {"
  162.                       "                key = \"UBlock\" ;"
  163.                       "                label = \"无名块\" ;"
  164.                       "            }"
  165.                       "        }"
  166.                       "        :boxed_column {"
  167.                       "            label = \"实体图层\" ;"
  168.                       "            :popup_list {"
  169.                       "                edit_width = 15 ;"
  170.                       "                key = \"BLayer\" ;"
  171.                       "                label = \"单元格线:\" ;"
  172.                       "            }"
  173.                       "            :popup_list {"
  174.                       "                edit_width = 15 ;"
  175.                       "                key = \"TLayer\" ;"
  176.                       "                label = \"表格内容:\" ;"
  177.                       "            }"
  178.                       "         :row {"
  179.                       "        :radio_button {"
  180.                       "            key = \"ByLayer\" ;"
  181.                       "            label = \"颜色随层\" ;"
  182.                       "        }"
  183.                       "        :radio_button {"
  184.                       "            key = \"ByBlock\" ;"
  185.                       "            label = \"颜色随块\" ;"
  186.                       "        }"
  187.                       "            }"
  188.                       "        }"
  189.                       "    }"
  190.                       "    ok_cancel_help;"
  191.                       "    errtile;"
  192.                       "}"
  193.                       )
  194.          (write-line str f)
  195.          )
  196.        (close f)
  197.        )
  198.      )
  199.    tmpdcl
  200.    )
  201.   ;;
  202. (defun start_xl2x ()
  203.    (setq *DrawRange* (getenv "Excel2CAD\\DrawRange"))
  204.    (if (null *DrawRange*)
  205.      (progn
  206.      (setq *DrawRange* "Used")
  207.      (setEnv "Excel2CAD\\DrawRange" *DrawRange*)
  208.      )
  209.      )
  210.    (set_tile *DrawRange* "1")
  211.    (GXL-DCL-ADDLIST "BLayer" Layers (VL-POSITION "0" Layers))
  212.    (setq BLayer (nth 0 layers))
  213.    (GXL-DCL-ADDLIST "TLayer" Layers (VL-POSITION "0" Layers))
  214.    (setq TLayer (nth 0 layers))
  215.    (setq *CellColor* (= "1" (getenv "Excel2CAD\\CellColor")))
  216.    (if *CellColor*
  217.        (set_tile "CellColor" "1") ;_ 背景颜色
  218.      (progn
  219.        (set_tile "CellColor" "0") ;_ 背景颜色
  220.        (setEnv "Excel2CAD\\CellColor" "0")
  221.      )
  222.    )
  223.    (setq *AnnoColor* (= "1" (getenv "Excel2CAD\\AnnoColor")))
  224.    (if *AnnoColor*
  225.        (set_tile "AnnoColor" "1") ;_ 文本颜色
  226.      (progn
  227.        (set_tile "AnnoColor" "0") ;_ 文本颜色
  228.        (setEnv "Excel2CAD\\AnnoColor" "0")
  229.      )
  230.    )
  231.    (setq *Oprate* (getenv "Excel2CAD\\Oprate"))
  232.    (if *Oprate*
  233.      (setq *Oprate* (atoi *Oprate*))
  234.      (setq *Oprate* 0)
  235.      )
  236.    (setenv "Excel2CAD\\Oprate" (itoa *Oprate*))
  237.    (cond
  238.      ((or (null *Oprate*) (= 0 *Oprate*))
  239.       (setq *Oprate* 0)
  240.       (set_tile "None" "1")
  241.       )
  242.      ((= 1 *Oprate*)
  243.       (set_tile "Group" "1")
  244.       )
  245.      ((= 2 *Oprate*)
  246.       (set_tile "UBlock" "1")
  247.       )
  248.      )
  249.    (setq *Merge* (= "1" (getenv "Excel2CAD\\Merge")))
  250.    (if *Merge*
  251.      (set_tile "Merge" "1")
  252.      (progn
  253.      (set_tile "Merge" "0")
  254.      (Setenv "Excel2CAD\\Merge" "0")
  255.      )
  256.      )
  257.    (setq *THeight* (getenv "Excel2CAD\\THeight"))
  258.    (if (null *THeight*)
  259.      (progn
  260.        (setq *THeight* 300)
  261.        (Setenv "Excel2CAD\\THeight" "300")
  262.      )
  263.      (setq *THeight* (atof *THeight*))
  264.    )
  265.    (set_tile "THeight" (rtos *THeight* 2))
  266.    (setq *KeepTHeight* (= "1" (getenv "Excel2CAD\\KeepTHeight")))
  267.    (if *KeepTHeight*
  268.      (progn
  269.      (mode_tile "THeight" 0)
  270.      (set_tile "KeepTHeight" "1")
  271.      )
  272.      (progn
  273.      (mode_tile "THeight" 1)
  274.      (set_tile "KeepTHeight" "0")
  275.      (Setenv "Excel2CAD\\KeepTHeight" "0")
  276.      )
  277.      )
  278.    (setq *pageSetUp* (= "1" (getenv "Excel2CAD\\pageSetUp")))
  279.    (if *pageSetUp*
  280.      (set_tile "PageSetup" "1")
  281.      (progn
  282.      (set_tile "PageSetup" "0")
  283.      (Setenv "Excel2CAD\\PageSetup" "0")
  284.      )
  285.      )
  286.    (setq *defaultColor* (getenv "Excel2CAD\\defaultColor"))
  287.    (if (null *defaultColor*)
  288.      (progn
  289.      (setq *defaultColor* 0)
  290.      (Setenv "Excel2CAD\\defaultColor" "0")
  291.      )
  292.      (setq *defaultColor* (atoi *defaultColor*))
  293.      )
  294.    (cond
  295.      ((= 0 *defaultColor*) (set_tile "ByBlock" "1"))
  296.      (t (set_tile "ByLayer" "1")
  297.       (setq *defaultColor* 256)
  298.       )
  299.      )
  300. ;;控件控制动作
  301.    (action_tile "getfile" "(act_getfile)")
  302.    (action_tile "Used" "(act_Used $key $value $reason)")
  303.    (action_tile "PrintArea" "(act_PrintArea $key $value)")
  304.    (action_tile "User" "(act_User $key $value $reason)")
  305.    (action_tile "CellColor" "(act_CellColor $key $value $reason)")
  306.    (action_tile "AnnoColor" "(act_AnnoColor $key $value $reason)")
  307.    (action_tile "PageSetup" "(act_PageSetup $key $value)")
  308.    (action_tile "Merge" "(act_Merge $key $value $reason)")
  309.    (action_tile "KeepTHeight" "(act_KeepTHeight $value)")
  310.    (action_tile "THeight" "(setq *THeight* (gxl-chkrealp $value $key 6)) (if *THeight* (Setenv \"Excel2CAD\\\\THeight\" (rtos *THeight* 2)))")
  311.    (action_tile "Gather" "(act_Gather $key $value $reason)")
  312.    (action_tile "None" "(act_None $key $value $reason)")
  313.    (action_tile "Group" "(act_Group $key $value $reason)")
  314.    (action_tile "UBlock" "(act_UBlock $key $value $reason)")
  315.    (action_tile "BLayer" "(act_BLayer $key $value $reason)")
  316.    (action_tile "TLayer" "(act_TLayer $key $value $reason)")
  317.    (action_tile "ByBlock" "(setq *defaultColor* 0) (Setenv \"Excel2CAD\\\\defaultColor\" \"0\")")
  318.    (action_tile "ByLayer" "(setq *defaultColor* 256) (Setenv \"Excel2CAD\\\\defaultColor\" \"256\")")
  319.    (action_tile "help" "(alert \"***Excel To AutoCAD*** \n\n版权所有:Gu_xl \n\n联系方式:Gu_xl@sohu.com\n\n\")")
  320. )
  321.   ;;act_getfile动作
  322.   (defun act_getfile (/ filename)
  323.     (setq filename (getfiled "" "" "xls;xlsx" 4))
  324.     (if filename (setq *xlapp* (vlxls-app-open filename t)))
  325.     )

  326.   ;;控件 Used 动作
  327.     (defun act_Used (key val reason)
  328.       (setq *DrawRange* key)
  329.       (setEnv "Excel2CAD\\DrawRange" key)
  330.      )

  331.   ;;控件 User 动作
  332.     (defun act_User (key val reason)
  333.       (setq *DrawRange* key)
  334.       (setEnv "Excel2CAD\\DrawRange" key)
  335.      )
  336.    (defun act_PrintArea (key val)
  337.      (setq *DrawRange* key)
  338.      (setEnv "Excel2CAD\\DrawRange" key)
  339.      )
  340.   ;;控件 CellColor 动作
  341.     (defun act_CellColor (key val reason)
  342.       (setq *CellColor* (= "1" val))
  343.       (setEnv "Excel2CAD\\CellColor" val)
  344.      )

  345.   ;;控件 AnnoColor 动作
  346.     (defun act_AnnoColor (key val reason)
  347.       (setq *AnnoColor* (= "1" val))
  348.       (setEnv "Excel2CAD\\AnnoColor" val)
  349.      )
  350. ;;按页面设置输出
  351.   (defun act_PageSetup (key val)
  352.     (setq *PageSetUp* (= "1" val))
  353.     (setEnv "Excel2CAD\\PageSetup" val)
  354.     )
  355.   ;;控件 Merge 动作
  356.     (defun act_Merge (key val reason)
  357.       (setq *Merge* (= "1" val))
  358.       (setEnv "Excel2CAD\\Merge" val)
  359.      )


  360.   ;;控件 None 动作
  361.     (defun act_None (key val reason)
  362.       (setq *Oprate* 0)
  363.       (set_tile "None" "1")
  364.       (setEnv "Excel2CAD\\Oprate" "0")
  365.      )

  366.   ;;控件 Group 动作
  367.     (defun act_Group (key val reason)
  368.       (setq *Oprate* 1)
  369.       (set_tile "Group" "1")
  370.       (setEnv "Excel2CAD\\Oprate" "1")
  371.      )

  372.   ;;控件 UBlock 动作
  373.     (defun act_UBlock (key val reason)
  374.       (setq *Oprate* 2)
  375.       (set_tile "UBlock" "1")
  376.       (setEnv "Excel2CAD\\Oprate" "2")
  377.      )
  378.   ;;缺省文本高度
  379.   (defun act_KeepTHeight (val)
  380.     (setq *KeepTHeight* (= "1" val))
  381.     (setEnv "Excel2CAD\\KeepTHeight" val)
  382.     (if *KeepTHeight*
  383.       (mode_tile "THeight" 0)
  384.       (mode_tile "THeight" 1)
  385.       )
  386.     )
  387.   ;;控件 BLayer 动作
  388.     (defun act_BLayer (key val reason)
  389.       (setq BLayer (nth (read val) layers))
  390.      )

  391.   ;;控件 TLayer 动作
  392.     (defun act_TLayer (key val reason)
  393.       (setq TLayer (nth (read val) layers))
  394.      )
  395.   ;;绘制顶端标题
  396.   (defun PrintTitleRows        (Range / R                PRINTAREA   
  397.                            CELLS        COL             ROW
  398.                            MERGEP        WIDTH             HEIGHT
  399.                            TEXT                FONT             HORIZONTALALIGNMENT
  400.                            VERTICALALIGNMENT             DXF71
  401.                            DXF62        DXF420             RANGEFONT
  402.                            DXF7                TEXTFONT     DXF40
  403.                            TEXTVERFLAG        TMP             OLDROW
  404.                                    P0            
  405.                            RIGHTTOPPT        OLDHEIGHT    MERGEID
  406.                            WIDTH1        HEIGHT1             P1
  407.                            P2                P3             HORLINE
  408.                            VERLINES        INTERIORCOLOR
  409.                            INTERIORTRUECOLOR             TEXTPT
  410.                          Columns
  411.                           )
  412.     (setq r (VLXLS-GET-PROPERTY
  413.               *XLAPP*
  414.               "ActiveSheet.PageSetup.PrintTitleRows"
  415.             )
  416.     )
  417.     (if        (/= "" r)
  418.       (progn
  419.         (progn
  420.             (setq r            (GXL-STRPARSE r ":"))
  421.           (vlax-for a (VLXLS-GET-PROPERTY range "Columns")
  422.             (setq
  423.               Columns (cons (VLXLS-GET-PROPERTY a "Column") Columns)
  424.               )
  425.             )
  426.           (setq Columns (reverse Columns))
  427.           (setq r (strcat (chr (+ 64 (car Columns))) (car r) ":" (chr (+ 64 (last Columns))) (last r)))
  428.           (setq range            (vlax-get-property *XLAPP* 'range r)
  429.                 cells            (vlax-get-property range 'cells)
  430.                 )
  431.             ;;逐个绘制表头,未完成
  432.             (vlax-for cell cells
  433.               (gxl-Sys-Progress to -1)
  434.               (setq col           (vlax-get-property cell 'column)
  435.                     row           (vlax-get-property cell 'row)
  436.                     range  (msxlp-get-range
  437.                              *xlApp*
  438.                              (VLXLS-RANGEID (list col row))
  439.                            )
  440.                     Mergep (equal :vlax-true
  441.                                   (vlax-variant-value
  442.                                     (vlax-get-property cell 'MergeCells)
  443.                                   )
  444.                            )
  445.                     width  (* defaultHeight
  446.                               GridScale
  447.                               (vlax-variant-value
  448.                                 (vlax-get-property cell 'width)
  449.                               )
  450.                            )
  451.                     height (* defaultHeight
  452.                               GridScale
  453.                               (vlax-variant-value
  454.                                 (vlax-get-property cell 'height)
  455.                               )
  456.                            )
  457.                     text   (vlax-variant-value (vlax-get-property cell 'text))
  458.               )
  459.               (if (and (/= text "")
  460.                        (not (equal width 0 0.01))
  461.                   )
  462.                 (progn
  463.                   (setq
  464.                     font (vlax-get-property range 'font)
  465.                     HorizontalAlignment
  466.                      (vlax-variant-value
  467.                        (vlax-get-property
  468.                          Cell
  469.                          'HorizontalAlignment
  470.                        )
  471.                      )
  472.                     HorizontalAlignment
  473.                      (cond ((= HorizontalAlignment -4152) 2) ;_ 右
  474.                            ((= HorizontalAlignment -4108) 1) ;_ 中
  475.                            (t 0) ;_ 左
  476.                      )
  477.                     VerticalAlignment
  478.                      (vlax-variant-value
  479.                        (vlax-get-property
  480.                          Cell
  481.                          'VerticalAlignment
  482.                        )
  483.                      )
  484.                     VerticalAlignment
  485.                      (cond ((= VerticalAlignment -4160) 0) ;_ 上
  486.                            ((= VerticalAlignment -4108) 1) ;_ 中
  487.                            (t 2) ;_ 下
  488.                      )
  489.                     DXF71 (nth VerticalAlignment
  490.                                (nth HorizontalAlignment dxf71data)
  491.                           )
  492.                     DXF62 (vlxls-color-eci->aci
  493.                             (vlax-variant-value
  494.                               (vlax-get-property Font 'colorIndex)
  495.                             )
  496.                           )
  497.                     DXF420 (vlxls-color-eci->truecolor
  498.                              (vlax-variant-value
  499.                                (vlax-get-property Font 'colorIndex)
  500.                              )
  501.                            )
  502.                   )
  503.                   ;;计算Range的字体 RangeFont i ii char cfont charFont caption f TextVerFlag
  504.                   (setq        RangeFont
  505.                          (mapcar
  506.                            '(lambda (x) (cons x (VLXLS-GET-PROPERTY font x)))
  507.                            '("NAME"            "SIZE"
  508.                              "COLORINDEX"   "BOLD"
  509.                              "ITALIC"            "SUBSCRIPT"
  510.                              "SUPERSCRIPT"  "UNDERLINE"
  511.                             )
  512.                          )
  513.                   )
  514.                   (setq DXF7 (cdr (assoc "NAME" RangeFont)))
  515.                   (if (null dxf7)
  516.                     (setq DXF7 StandardFont)
  517.                   )
  518.                   ;;字体
  519.                   (setq textFont (strcat "{\\f" DXF7 "|b0|i0|c134|p0;"))
  520.                   (setq Dxf40 (cdr (assoc "SIZE" RangeFont)))
  521.                   (if (null DXF40)
  522.                     (setq DXF40 StandardFontSize)
  523.                   )
  524.                   ;;字大小
  525.                   (setq        textFont (strcat textFont
  526.                                          "\\H"
  527.                                          (rtos DXF40 2 1)
  528.                                          "x;"
  529.                                  )
  530.                   )
  531.                   ;;加粗
  532.                   (if (equal :vlax-true (cdr (assoc "BOLD" RangeFont)))
  533.                     (setq textfont (strcat textFont "\\W1.2;"))
  534.                   )
  535.                   ;;倾斜
  536.                   (if
  537.                     (equal :vlax-true (cdr (assoc "ITALIC" RangeFont)))
  538.                      (setq textfont (strcat textFont "\\Q18;"))
  539.                   )
  540.                   ;;下划线
  541.                   (if (= 2 (cdr (assoc "UNDERLINE" RangeFont)))
  542.                     (setq textfont (strcat textFont "\\L"))
  543.                   )
  544.                   ;;上标 "SUPERSCRIPT"
  545.                   ;;下标 "SUBSCRIPT"
  546.                   ;;文字是否竖向
  547.                   (setq        TextVerFlag
  548.                          (= (GXL-CATCHAPPLY
  549.                               VLXLS-GET-PROPERTY
  550.                               (list range "Orientation")
  551.                             )
  552.                             -4166
  553.                          )
  554.                   )
  555.                   (if TextVerFlag
  556.                     (progn
  557.                       (setq text (gxl-str->singleonly text))
  558.                       (setq tmp         (car text)
  559.                             text (cdr text)
  560.                       )
  561.                       (foreach a text (setq tmp (strcat tmp "\\P" a)))
  562.                       (setq text tmp)
  563.                     )
  564.                   )
  565.                   ;;逐字取样式
  566.                   ;;(setq textFont (strcat textFont (GetRangeTextStyle RANGE RANGEFONT text) "}"))

  567.                   (setq text (strcat textFont text "}"))

  568.                 )
  569.               )
  570.               (cond ((null OldRow) (setq OldRow Row))
  571.                     ((/= OldRow Row) ;_ 换行
  572.                      (if *pageSetUp*
  573.                        (progn
  574.                          (if nil        ;(member row HPageBreaks) ;_ 换页
  575.                            (progn
  576.                              (setq OldRow Row
  577.                                    StartPoint
  578.                                     (polar StartPoint
  579.                                            (* 1.5 pi)
  580.                                            oldheight
  581.                                     )
  582.                              )
  583.                              (if *Merge*
  584.                                (progn
  585.                                  (entmake
  586.                                    (list
  587.                                      '(0 . "line")
  588.                                      '(100 . "AcDbEntity")
  589.                                      '(67 . 0)
  590.                                      (cons 8 Blayer)
  591.                                      (cons 62 *defaultColor*)
  592.                                      '(100 . "AcDbLine")
  593.                                      (cons 10
  594.                                            StartPoint

  595.                                      )
  596.                                      (cons
  597.                                        11
  598.                                        (setq p0
  599.                                               (polar
  600.                                                 StartPoint
  601.                                                 0
  602.                                                 (* defaultHeight
  603.                                                    GridScale
  604.                                                    Totalwide
  605.                                                 )
  606.                                               )
  607.                                        )
  608.                                      )
  609.                                      '(210 0.0 0.0 1.0)
  610.                                    )
  611.                                  )
  612.                                  (entmake
  613.                                    (list
  614.                                      '(0 . "line")
  615.                                      '(100 . "AcDbEntity")
  616.                                      '(67 . 0)
  617.                                      (cons 8 Blayer)
  618.                                      (cons 62 *defaultColor*)
  619.                                      '(100 . "AcDbLine")
  620.                                      (cons 10 RightTopPt)
  621.                                      (cons 11 p0)
  622.                                      '(210 0.0 0.0 1.0)
  623.                                    )
  624.                                  )

  625.                                )
  626.                              )
  627.                              (setq StartPoint (polar StartPoint
  628.                                                      (* 1.5 pi)
  629.                                                      PageMargin
  630.                                               )
  631.                                    Curpt      StartPoint
  632.                                    RightTopPt (polar StartPoint
  633.                                                      0
  634.                                                      (*        defaultHeight
  635.                                                         GridScale
  636.                                                         Totalwide
  637.                                                      )
  638.                                               )
  639.                              ) ;_ 移动页间距
  640.                            )
  641.                            (setq OldRow            Row
  642.                                  StartPoint (polar StartPoint
  643.                                                    (* 1.5 pi)
  644.                                                    oldheight
  645.                                             )
  646.                                  Curpt            StartPoint
  647.                            )
  648.                          )
  649.                        )
  650.                        (setq OldRow        Row
  651.                              StartPoint        (polar StartPoint (* 1.5 pi) oldheight)
  652.                              Curpt        StartPoint
  653.                        )
  654.                      )


  655.                     )
  656.               )

  657.               (setq oldheight height)
  658.               (if (not (equal width 0 0.01))
  659.                 (progn
  660.                   (if Mergep
  661.                     (progn
  662.                       (setq mergeId (mapcar 'vlxls-rangeid
  663.                                             (vlxls-cellid
  664.                                               (vlxls-range-getid range)
  665.                                             )
  666.                                     )
  667.                             width1  (* defaultHeight
  668.                                        GridScale
  669.                                        (VLXLS-GET-PROPERTY
  670.                                          range
  671.                                          "MergeArea.width"
  672.                                        )
  673.                                     )
  674.                             height1 (* defaultHeight
  675.                                        GridScale
  676.                                        (VLXLS-GET-PROPERTY
  677.                                          range
  678.                                          "MergeArea.height"
  679.                                        )
  680.                                     )
  681.                       )
  682.                     )
  683.                     (setq width1  width
  684.                           height1 height
  685.                     )
  686.                   )
  687.                   (if
  688.                     (or        (not Mergep)
  689.                         (and Mergep (equal (car mergeId) (list col row)))
  690.                     )
  691.                      (progn
  692.                        (setq p0        (polar Curpt (* 1.5 pi) height1)
  693.                              p1        Curpt
  694.                              p2        (polar Curpt 0 width1)
  695.                              p3        (polar p2 (* 1.5 pi) height1)
  696.                        ) ;_ 框的四个角点 左下、左上、右上、右下
  697.                        (if *Merge*
  698.                          (progn
  699.                            (if Horline
  700.                              (progn
  701.                                (if (equal p1 (gxl-dxf HorLine 11) 1e-3)
  702.                                  (gxl-ch_ent HorLine 11 p2) ;_ 更新水平直线末端点
  703.                                  (progn
  704.                                    (entmake
  705.                                      (list
  706.                                        '(0 . "line")
  707.                                        '(100 . "AcDbEntity")
  708.                                        '(67 . 0)
  709.                                        (cons 8 Blayer)
  710.                                        (cons 62 *defaultColor*)
  711.                                        '(100 . "AcDbLine")
  712.                                        (cons 10 p1)
  713.                                        (cons 11 p2)
  714.                                        '(210 0.0 0.0 1.0)
  715.                                      )
  716.                                    )
  717.                                    (setq Horline (entlast))
  718.                                  )
  719.                                )
  720.                              )
  721.                              (progn
  722.                                (entmake
  723.                                  (list
  724.                                    '(0 . "line")
  725.                                    '(100 . "AcDbEntity")
  726.                                    '(67 . 0)
  727.                                    (cons 8 Blayer)
  728.                                    (cons 62 *defaultColor*)
  729.                                    '(100 . "AcDbLine")
  730.                                    (cons 10 p1)
  731.                                    (cons 11 p2)
  732.                                    '(210 0.0 0.0 1.0)
  733.                                  )
  734.                                )
  735.                                (setq Horline (entlast))
  736.                              )
  737.                            )
  738.                            (if VerLines
  739.                              (progn
  740.                                (if (not
  741.                                      (vl-some
  742.                                        (Function
  743.                                          (lambda (Line)
  744.                                            (if (equal p1
  745.                                                       (gxl-dxf Line 11)
  746.                                                       1e-3
  747.                                                )
  748.                                              (gxl-ch_ent Line 11 p0) ;_ 更新垂直直线末端点
  749.                                            )
  750.                                          )
  751.                                        )
  752.                                        VerLines
  753.                                      )
  754.                                    )
  755.                                  (progn
  756.                                    (entmake
  757.                                      (list
  758.                                        '(0 . "line")
  759.                                        '(100 . "AcDbEntity")
  760.                                        '(67 . 0)
  761.                                        (cons 8 Blayer)
  762.                                        (cons 62 *defaultColor*)
  763.                                        '(100 . "AcDbLine")
  764.                                        (cons 10 p1)
  765.                                        (cons 11 p0)
  766.                                        '(210 0.0 0.0 1.0)
  767.                                      )
  768.                                    )
  769.                                    (setq
  770.                                      VerLines (cons (entlast) VerLines)
  771.                                    )
  772.                                  )
  773.                                )
  774.                              )
  775.                              (progn
  776.                                (entmake
  777.                                  (list
  778.                                    '(0 . "line")
  779.                                    '(100 . "AcDbEntity")
  780.                                    '(67 . 0)
  781.                                    (cons 8 Blayer)
  782.                                    (cons 62 *defaultColor*)
  783.                                    '(100 . "AcDbLine")
  784.                                    (cons 10 p1)
  785.                                    (cons 11 p0)
  786.                                    '(210 0.0 0.0 1.0)
  787.                                  )
  788.                                )
  789.                                (setq VerLines (cons (entlast) VerLines))
  790.                              )
  791.                            )
  792.                          )
  793.                          (entmake
  794.                            (list
  795.                              '(0 . "LWPOLYLINE")
  796.                              '(100 . "AcDbEntity")
  797.                              '(67 . 0)
  798.                              (cons 8 BLayer)
  799.                              (cons 62 *defaultColor*)
  800.                              '(100 . "AcDbPolyline")
  801.                              '(90 . 4)
  802.                              '(70 . 1)
  803.                              '(43 . 0.0)
  804.                              '(38 . 0.0)
  805.                              '(39 . 0.0)
  806.                              (cons 10 p0)
  807.                              (cons 10 p1)
  808.                              (cons 10 p2)
  809.                              (cons 10 p3)
  810.                              '(210 0.0 0.0 1.0)
  811.                            )
  812.                          )
  813.                        )
  814.                        (if *CellColor* ;_ 绘制背景颜色
  815.                          (progn
  816.                            (if (/= -4142
  817.                                    (setq Interiorcolor
  818.                                           (VLXLS-GET-PROPERTY
  819.                                             range
  820.                                             "Interior.ColorIndex"
  821.                                           )
  822.                                    )
  823.                                )
  824.                              (progn
  825.                                (setq Interiorcolor     (VLXLS-COLOR-ECI->ACI
  826.                                                          Interiorcolor
  827.                                                        )
  828.                                      Interiortruecolor (VLXLS-COLOR-ECI->TRUECOLOR
  829.                                                          Interiorcolor
  830.                                                        )
  831.                                )
  832.                                (entmake
  833.                                  (vl-remove
  834.                                    nil
  835.                                    (list
  836.                                      '(0 . "SOLID")
  837.                                      '(100 . "AcDbEntity")
  838.                                      '(67 . 0)
  839.                                      (cons 8 BLayer)
  840.                                      (cons 62 Interiorcolor)
  841.                                      ;|(if (not (or (= 256 Interiorcolor)
  842.                                    (= 0 Interiortruecolor)
  843.                                )
  844.                           )
  845.                         (cons 420 Interiortruecolor)
  846.                       )|;
  847.                                      '(100 . "AcDbTrace")
  848.                                      (cons 10 p0)
  849.                                      (cons 11 p1)
  850.                                      (cons 12 p3)
  851.                                      (cons 13 p2)
  852.                                      '(210 0.0 0.0 1.0)
  853.                                    )
  854.                                  )
  855.                                )
  856.                                ;(setq SSSolid (cons (entlast) SSSolid))
  857.                              )
  858.                            )

  859.                          )
  860.                        )
  861.                        (if (/= "" text)
  862.                          (progn
  863.                            (setq textpt
  864.                                   (nth (1- DXF71) (Get9JustPts p0 p2))
  865.                            )
  866.                            (cond ((= 0 HorizontalAlignment) ;_ 左对齐
  867.                                   (setq
  868.                                     textpt (polar textpt 0 (* height 0.1))
  869.                                   )
  870.                                  )
  871.                                  ((= 2 HorizontalAlignment) ;_ 右对齐
  872.                                   (setq
  873.                                     textpt (polar textpt pi (* height 0.1))
  874.                                   )
  875.                                  )
  876.                            )
  877.                            (cond
  878.                              ((= 0 VerticalAlignment) ;_ 上对齐
  879.                               (setq textpt (polar textpt
  880.                                                   (* 1.5 pi)
  881.                                                   (* height 0.1)
  882.                                            )
  883.                               )
  884.                              )
  885.                              ((= 2 VerticalAlignment) ;_ 下对齐
  886.                               (setq textpt (polar textpt
  887.                                                   (* 0.5 pi)
  888.                                                   (* height 0.1)
  889.                                            )
  890.                               )
  891.                              )
  892.                            )
  893.                            (entmake
  894.                              (vl-remove
  895.                                nil
  896.                                (list
  897.                                  (cons 0 "MTEXT")
  898.                                  '(100 . "AcDbEntity")
  899.                                  '(67 . 0)
  900.                                  (cons 8 TLayer)
  901.                                  (if *AnnoColor*
  902.                                    (cons 62 dxf62)
  903.                                    (cons 62 *defaultColor*)
  904.                                  )
  905.                                  '(100 . "AcDbMText")
  906.                                  (cons 10 textpt)
  907.                                  (cons 40 defaultHeight)
  908.                                  (cons 41 width1)
  909.                                         ;(cons 50 0)
  910.                                  ;;'(46 . 0.0)
  911.                                  (cons 71 DXF71)
  912.                                  (cons 72 5)
  913.                                  (cons 1 text)
  914.                                  (cons 7 "Standard")
  915.                                  '(210 0.0 0.0 1.0)
  916.                                  '(11 1.0 0.0 0.0)
  917.                                  '(50 . 0.0)
  918.                                  '(73 . 1)
  919.                                )
  920.                              )
  921.                            )
  922.                          )
  923.                        )
  924.                      )
  925.                   )
  926.                   (setq Curpt (polar Curpt 0 width))
  927.                 )
  928.               )
  929.             ) ;_ vlax-for
  930.             
  931.           )
  932.         (setq startpoint (polar startpoint (* 1.5 pi) oldheight) curpt startpoint)
  933.       )
  934.     )

  935.   )
  936.   ;;Range的text逐字取样式
  937.   (defun GetRangeTextStyle (RANGE RANGEFONT text            /             I
  938.                                   II           CHAR            CFONT    CAPTION
  939.                                   CHARFONT F            TEXTFONT
  940.                                  )
  941.    (if (equal :vlax-false (vlxls-get-property range "HasFormula"))
  942.           (progn
  943.             (setq i  0
  944.                   ii (GXL-CATCHAPPLY
  945.                        vlax-get-property
  946.                        (list (vlax-get-property range 'characters) 'count)
  947.                      )
  948.             )
  949.             (if        ii
  950.               (repeat ii
  951.                 (setq char  (vlax-get-property
  952.                               range
  953.                               'characters
  954.                               (setq i (1+ i))
  955.                               1
  956.                             )
  957.                       cfont (vlax-get-property char 'font)
  958.                       caption (VLXLS-GET-PROPERTY char "caption")
  959.                 )
  960.                 (setq charFont
  961.                        (mapcar
  962.                          '(lambda (x) (cons x (VLXLS-GET-PROPERTY cfont x)))
  963.                          '("NAME"          "SIZE"         "COLORINDEX"
  964.                            "BOLD"          "ITALIC"         "SUBSCRIPT"
  965.                            "SUPERSCRIPT"  "UNDERLINE"
  966.                           )
  967.                        )
  968.                 )
  969.                 (if (and (setq f (cdr (assoc "NAME" charFont)))
  970.                          (/= f (cdr (assoc "NAME" RangeFont)))
  971.                          )
  972.                   (setq textfont (strcat "\\f" f  "|b0|i0|c134|p0;"))
  973.                   ) ;_ 字体
  974.                 (if (and (setq f (cdr (assoc "SIZE" charFont)))
  975.                          (equal f (cdr (assoc "SIZE" RangeFont)) 0.01)
  976.                          )
  977.                   (setq textfont (strcat textFont "\\H" (rtos f 2 1) "x;"))
  978.                   ) ;_ 大小
  979.                 (if (and (setq f (cdr (assoc "COLORINDEX" charFont)))
  980.                          (equal f (cdr (assoc "COLORINDEX" RangeFont)) 0.01)
  981.                          )
  982.                   (setq textfont (strcat textFont "\\C" (itoa (vlxls-color-eci->aci f)) ";"))
  983.                   ) ;_ 颜色
  984.                 ;;加粗
  985.                 (if (not (equal        (setq f (cdr (assoc "BOLD" charFont)))
  986.                                 (cdr (assoc "BOLD" RangeFont))
  987.                          )
  988.                     )
  989.                   (if (equal :vlax-true f)
  990.                     (setq textfont (strcat textFont "\\W1.2;"))
  991.                     (setq textfont (strcat textFont "\\W0.83;"))
  992.                   )
  993.                 )
  994.                 ;;倾斜
  995.                 (if
  996.                   (not (equal (setq f (cdr (assoc "ITALIC" charFont)))
  997.                               (cdr (assoc "ITALIC" RangeFont))
  998.                        )
  999.                   )
  1000.                    (if (equal :vlax-true f)
  1001.                      (setq textfont (strcat textFont "\\Q18;"))
  1002.                      (setq textfont (strcat textFont "\\Q0;"))
  1003.                    )
  1004.                 )
  1005.                 ;;上标
  1006.                 (if (equal :vlax-true (cdr (assoc "SUPERSCRIPT" RangeFont)))
  1007.                     (setq textFont (strcat textFont "\\H0.33x;\\A2;"))
  1008.                     )
  1009.                 ;;下标
  1010.                 (if (equal :vlax-true (cdr (assoc "SUPERSCRIPT" RangeFont)))
  1011.                     (setq textFont (strcat textFont "\\H0.33x;\\A0;"))
  1012.                     )
  1013.                 ;;下划线
  1014.                 (if
  1015.                   (not (equal (setq f (cdr (assoc "UNDERLINE" charFont)))
  1016.                               (cdr (assoc "UNDERLINE" RangeFont))
  1017.                        )
  1018.                   )
  1019.                    (if (= 2 f)
  1020.                      (setq textfont (strcat textFont "\\L"))
  1021.                      (setq textfont (strcat textFont "\\l"))
  1022.                    )
  1023.                 )
  1024.                (setq textFont (strcat textFont caption))
  1025.                (if (and TextVerFlag (/= i ii)) (setq textFont (strcat textFont "\\P")))
  1026.               )
  1027.               (setq textfont (strcat textfont text))
  1028.             )
  1029.           )
  1030.           (setq textfont (strcat textfont text))
  1031.         )
  1032.     )
  1033.   ;;绘制页眉页脚 PageSetUp vla对象 pt 表格基点 Flag = t 页眉 = nil 页脚
  1034.   (defun DrawPageSetUp (PAGESETUP PT              FLAG          /
  1035.                                   GETFONTSTR  LEFTHEADER  CENTERHEADER
  1036.                                   RIGHTHEADER D                  TEXTPT
  1037.                          LeftFooter CenterFooter RightFooter
  1038.                                  )
  1039. ; PageSetup:特性值:
  1040. ;   AlignMarginsHeaderFooter = 0
  1041. ;   Application (RO) = #<VLA-OBJECT _Application 0cdd3e9c>
  1042. ;   BlackAndWhite = 0
  1043. ;   BottomMargin = 70.8661
  1044. ;   CenterFooter = "&\"幼圆,加粗\"&16页脚中&N第&P页"
  1045. ;   CenterFooterPicture (RO) = #<VLA-OBJECT Graphic 1821ca84>
  1046. ;   CenterHeader = "页眉中"
  1047. ;   CenterHeaderPicture (RO) = #<VLA-OBJECT Graphic 1821d5c4>
  1048. ;   CenterHorizontally = 0
  1049. ;   CenterVertically = 0
  1050. ;   Creator (RO) = 1480803660
  1051. ;   DifferentFirstPageHeaderFooter = 0
  1052. ;   Draft = 0
  1053. ;   EvenPage (RO) = #<VLA-OBJECT Page 1821c454>
  1054. ;   FirstPage (RO) = #<VLA-OBJECT Page 1821ddec>
  1055. ;   FirstPageNumber = -4105
  1056. ;   FitToPagesTall = 1
  1057. ;   FitToPagesWide = 1
  1058. ;   FooterMargin = 36.8504
  1059. ;   HeaderMargin = 36.8504
  1060. ;   LeftFooter = "&\"楷体,常规\"&14页&\"楷体,加粗 倾斜\"脚&\"楷体,常规\"左"
  1061. ;   LeftFooterPicture (RO) = #<VLA-OBJECT Graphic 1821df54>
  1062. ;   LeftHeader = "页眉左"
  1063. ;   LeftHeaderPicture (RO) = #<VLA-OBJECT Graphic 1821c724>
  1064. ;   LeftMargin = 53.8583
  1065. ;   OddAndEvenPagesHeaderFooter = 0
  1066. ;   Order = 1.0
  1067. ;   Orientation = 1.0
  1068. ;   Pages (RO) = #<VLA-OBJECT Pages 1821c0ac>
  1069. ;   PaperSize = 9.0
  1070. ;   Parent (RO) = #<VLA-OBJECT _Worksheet 1821dad4>
  1071. ;   PrintArea = "$A$1:$N$105"
  1072. ;   PrintComments = -4142
  1073. ;   PrintErrors = 0
  1074. ;   PrintGridlines = 0
  1075. ;   PrintHeadings = 0
  1076. ;   PrintNotes = 0
  1077. ;   PrintQuality = ...不显示带索引的内容...
  1078. ;   PrintTitleColumns = ""
  1079. ;   PrintTitleRows = "$1:$3"
  1080. ;   RightFooter = "&\"楷体,加粗\"&KFF0000页脚右"
  1081. ;   RightFooterPicture (RO) = #<VLA-OBJECT Graphic 1821dccc>
  1082. ;   RightHeader = "页眉右"
  1083. ;   RightHeaderPicture (RO) = #<VLA-OBJECT Graphic 1821c8d4>
  1084. ;   RightMargin = 53.8583
  1085. ;   ScaleWithDocHeaderFooter = -1
  1086. ;   TopMargin = 70.8661
  1087. ;   Zoom = 100
  1088.     (defun GetFontstr (str / size fontname fontstr color)
  1089.       ;;用正则表达式删除格式文字
  1090.       ;;"&\"幼圆,加粗\"&16页脚&\"楷体,加粗倾斜\"&12&KFFFF00中共&\"幼圆,加粗\"&16&K000000&N页 第&P页"
  1091.       (setq fontname
  1092.              (gxl-RegExSearch
  1093.                str
  1094.                "\&\\\".+?\""
  1095.                "im"
  1096.                )
  1097.             )
  1098.       (if fontname
  1099.         (progn
  1100.           (setq fontname (caddar fontname))
  1101.           (setq fontname
  1102.                 (gxl-RegExRePlace
  1103.                   fontname
  1104.                   ""
  1105.                   "&\\\"|\\\""
  1106.                   "mg"
  1107.                   )
  1108.                 )
  1109.           (setq fontname (GXL-STRPARSE fontname ","))
  1110.           (setq fontstr (strcat "{\\f" (car fontname) "|b0|i0|c134|p0;"))
  1111.           (if (cadr fontname)
  1112.             (progn
  1113.               (if (WCMATCH (cadr fontname) "*加粗*")
  1114.                 (setq fontstr (strcat fontstr "\\W1.2;"))
  1115.                 )
  1116.               (if (WCMATCH (cadr fontname) "*倾斜*")
  1117.                 (setq fontstr (strcat fontstr "\\Q18;"))
  1118.                 )
  1119.               
  1120.               )
  1121.             )
  1122.           )
  1123.         (setq fontstr (strcat "{\\f" standardFont "|b0|i0|c134|p0;" "\\H" (rtos StandardFontSize 2 1) "x;"))
  1124.         )
  1125.       (setq size
  1126.              (gxl-RegExSearch
  1127.                str
  1128.                "&\\d{1,2}"
  1129.                "im"
  1130.                )
  1131.             )
  1132.       (if size
  1133.         (progn
  1134.           (setq size (caddar size))
  1135.           (setq size
  1136.                 (gxl-RegExRePlace
  1137.                   size
  1138.                   ""
  1139.                   "&"
  1140.                   "mg"
  1141.                   )
  1142.                 )
  1143.           (setq fontstr (strcat fontstr "\\H" size "x;"))
  1144.           )
  1145.         )
  1146.       (if *AnnoColor*
  1147.         (progn
  1148.           (setq        color
  1149.                  (gxl-RegExSearch
  1150.                    str
  1151.                    "\&K[A-Za-z0-9]{6}"
  1152.                    "im"
  1153.                  )
  1154.           )
  1155.           (if color
  1156.             (progn
  1157.               (setq color (strcat "#" (substr (caddar color) 3)))
  1158.               (setq color (gxl-Hex->ACI color))
  1159.               (setq fontstr (strcat fontstr "\\C" (itoa color) ";"))
  1160.             )
  1161.           )
  1162.         )
  1163.         (setq fontstr (strcat fontstr "\\C" (itoa *defaultColor*) ";"))
  1164.       )

  1165.          
  1166.       (setq str
  1167.              (gxl-RegExRePlace
  1168.                str
  1169.                ""
  1170.                "&\\d{1,2}|\&\\\".+?\"|\&K[A-Za-z0-9]{6}"
  1171.                "mg"
  1172.              )
  1173.       )
  1174.       (setq str
  1175.              (gxl-RegExRePlace
  1176.                str
  1177.                (itoa TotalPage)
  1178.                "&N"
  1179.                "mg"
  1180.              )
  1181.       )
  1182.       (setq str
  1183.              (gxl-RegExRePlace
  1184.                str
  1185.                (itoa Page)
  1186.                "&P"
  1187.                "mg"
  1188.              )
  1189.       )
  1190.       ;(strcat "{\\f" standardFont "|b0|i0|c134|p0;" "\\H" (rtos StandardFontSize 2 1) "x;" str"}")
  1191.       (strcat fontstr str "}")
  1192.       )
  1193.     (cond
  1194.       (flag ;_ 页眉
  1195.        (setq LeftHeader (vlax-get-property PageSetUp 'LeftHeader)
  1196.              CenterHeader (vlax-get-property PageSetUp 'CenterHeader)
  1197.              RightHeader (vlax-get-property PageSetUp 'RightHeader)
  1198.              )
  1199.        (if (/= "" LeftHeader)
  1200.          (progn
  1201.            (setq d (* defaultHeight GridScale (vlax-get-property PageSetUp 'HeaderMargin)))
  1202.            (setq textpt (polar pt (* pi 0.5) d))
  1203.            (setq LeftHeader (GetFontstr LeftHeader))
  1204.            (entmake
  1205.               (vl-remove
  1206.                 nil
  1207.                 (list
  1208.                   (cons 0 "MTEXT")
  1209.                   '(100 . "AcDbEntity")
  1210.                   '(67 . 0)
  1211.                   (cons 8 TLayer)
  1212.                   (cons 62 *defaultColor*)
  1213.                   '(100 . "AcDbMText")
  1214.                   (cons 10 textpt)
  1215.                   (cons 40 defaultHeight)
  1216.                   (cons 41 (* 0.333 totalwide GridScale defaultHeight))
  1217.                   (cons 71 4)
  1218.                   (cons 72 5)
  1219.                   (cons 1 LeftHeader)
  1220.                   (cons 7 "Standard")
  1221.                   '(210 0.0 0.0 1.0)
  1222.                   '(11 1.0 0.0 0.0)
  1223.                   '(50 . 0.0)
  1224.                   '(73 . 1)
  1225.                 )
  1226.               )
  1227.             )
  1228.            )
  1229.          )
  1230.        (if (/= "" CenterHeader)
  1231.          (progn
  1232.            (setq d (* defaultHeight GridScale (vlax-get-property PageSetUp 'HeaderMargin)))
  1233.            (setq textpt (polar (polar pt (* pi 0.5) d) 0 (* 0.5 totalwide GridScale defaultHeight)))
  1234.            (setq CenterHeader (GetFontstr CenterHeader))
  1235.            (entmake
  1236.               (vl-remove
  1237.                 nil
  1238.                 (list
  1239.                   (cons 0 "MTEXT")
  1240.                   '(100 . "AcDbEntity")
  1241.                   '(67 . 0)
  1242.                   (cons 8 TLayer)
  1243.                   (cons 62 *defaultColor*)
  1244.                   '(100 . "AcDbMText")
  1245.                   (cons 10 textpt)
  1246.                   (cons 40 defaultHeight)
  1247.                   (cons 41 (* 0.333 totalwide GridScale defaultHeight))
  1248.                   (cons 71 5)
  1249.                   (cons 72 5)
  1250.                   (cons 1 CenterHeader)
  1251.                   (cons 7 "Standard")
  1252.                   '(210 0.0 0.0 1.0)
  1253.                   '(11 1.0 0.0 0.0)
  1254.                   '(50 . 0.0)
  1255.                   '(73 . 1)
  1256.                 )
  1257.               )
  1258.             )
  1259.            )
  1260.          )
  1261.        (if (/= "" RightHeader)
  1262.          (progn
  1263.            (setq d (* defaultHeight GridScale (vlax-get-property PageSetUp 'HeaderMargin)))
  1264.            (setq textpt (polar (polar pt (* pi 0.5) d) 0 (* totalwide GridScale defaultHeight)))
  1265.            (setq RightHeader (GetFontstr RightHeader))
  1266.            (entmake
  1267.               (vl-remove
  1268.                 nil
  1269.                 (list
  1270.                   (cons 0 "MTEXT")
  1271.                   '(100 . "AcDbEntity")
  1272.                   '(67 . 0)
  1273.                   (cons 8 TLayer)
  1274.                   (cons 62 *defaultColor*)
  1275.                   '(100 . "AcDbMText")
  1276.                   (cons 10 textpt)
  1277.                   (cons 40 defaultHeight)
  1278.                   (cons 41 (* 0.333 totalwide GridScale defaultHeight))
  1279.                   (cons 71 6)
  1280.                   (cons 72 5)
  1281.                   (cons 1 RightHeader)
  1282.                   (cons 7 "Standard")
  1283.                   '(210 0.0 0.0 1.0)
  1284.                   '(11 1.0 0.0 0.0)
  1285.                   '(50 . 0.0)
  1286.                   '(73 . 1)
  1287.                 )
  1288.               )
  1289.             )
  1290.            )
  1291.          )
  1292.        )
  1293.       (t ;_ 页脚
  1294.        (setq LeftFooter (vlax-get-property PageSetUp 'LeftFooter)
  1295.              CenterFooter (vlax-get-property PageSetUp 'CenterFooter)
  1296.              RightFooter (vlax-get-property PageSetUp 'RightFooter)
  1297.              d (* defaultHeight GridScale (vlax-get-property PageSetUp 'FooterMargin))
  1298.              )
  1299.        (if (/= "" LeftFooter)
  1300.          (progn
  1301.            (setq textpt (polar pt (* pi 1.5) d))
  1302.            (setq LeftFooter (GetFontstr LeftFooter))
  1303.            (entmake
  1304.               (vl-remove
  1305.                 nil
  1306.                 (list
  1307.                   (cons 0 "MTEXT")
  1308.                   '(100 . "AcDbEntity")
  1309.                   '(67 . 0)
  1310.                   (cons 8 TLayer)
  1311.                   (cons 62 *defaultColor*)
  1312.                   '(100 . "AcDbMText")
  1313.                   (cons 10 textpt)
  1314.                   (cons 40 defaultHeight)
  1315.                   (cons 41 (* 0.333 totalwide GridScale defaultHeight))
  1316.                   (cons 71 4)
  1317.                   (cons 72 5)
  1318.                   (cons 1 LeftFooter)
  1319.                   (cons 7 "Standard")
  1320.                   '(210 0.0 0.0 1.0)
  1321.                   '(11 1.0 0.0 0.0)
  1322.                   '(50 . 0.0)
  1323.                   '(73 . 1)
  1324.                 )
  1325.               )
  1326.             )
  1327.            )
  1328.          )
  1329.        (if (/= "" CenterFooter)
  1330.          (progn
  1331.            (setq textpt (polar (polar pt (* pi 1.5) d) 0 (* 0.5 totalwide GridScale defaultHeight)))
  1332.            (setq CenterFooter (GetFontstr CenterFooter))
  1333.            (entmake
  1334.               (vl-remove
  1335.                 nil
  1336.                 (list
  1337.                   (cons 0 "MTEXT")
  1338.                   '(100 . "AcDbEntity")
  1339.                   '(67 . 0)
  1340.                   (cons 8 TLayer)
  1341.                   (cons 62 *defaultColor*)
  1342.                   '(100 . "AcDbMText")
  1343.                   (cons 10 textpt)
  1344.                   (cons 40 defaultHeight)
  1345.                   (cons 41 (* 0.333 totalwide GridScale defaultHeight))
  1346.                   (cons 71 5)
  1347.                   (cons 72 5)
  1348.                   (cons 1 CenterFooter)
  1349.                   (cons 7 "Standard")
  1350.                   '(210 0.0 0.0 1.0)
  1351.                   '(11 1.0 0.0 0.0)
  1352.                   '(50 . 0.0)
  1353.                   '(73 . 1)
  1354.                 )
  1355.               )
  1356.             )
  1357.            )
  1358.          )
  1359.        (if (/= "" RightFooter)
  1360.          (progn
  1361.            (setq textpt (polar (polar pt (* pi 1.5) d) 0 (* totalwide GridScale defaultHeight)))
  1362.            (setq RightFooter (GetFontstr RightFooter))
  1363.            (entmake
  1364.               (vl-remove
  1365.                 nil
  1366.                 (list
  1367.                   (cons 0 "MTEXT")
  1368.                   '(100 . "AcDbEntity")
  1369.                   '(67 . 0)
  1370.                   (cons 8 TLayer)
  1371.                   (cons 62 *defaultColor*)
  1372.                   '(100 . "AcDbMText")
  1373.                   (cons 10 textpt)
  1374.                   (cons 40 defaultHeight)
  1375.                   (cons 41 (* 0.333 totalwide GridScale defaultHeight))
  1376.                   (cons 71 6)
  1377.                   (cons 72 5)
  1378.                   (cons 1 RightFooter)
  1379.                   (cons 7 "Standard")
  1380.                   '(210 0.0 0.0 1.0)
  1381.                   '(11 1.0 0.0 0.0)
  1382.                   '(50 . 0.0)
  1383.                   '(73 . 1)
  1384.                 )
  1385.               )
  1386.             )
  1387.            )
  1388.          )

  1389.        )
  1390.       )
  1391.     )
  1392. ;;主程序开始
  1393.   (setierr)
  1394. (setq Layers (gxl-table "layer"))
  1395.   ;;对话框开始
  1396.   ;;
  1397.   ;;(vl-file-delete (findfile "xl2cad.dcl"))
  1398.    (setq dclcode (load_dialog (mkTmpDcl "xl2cad")))
  1399.    (new_dialog "xl2cad" dclcode)
  1400.    (start_xl2x)
  1401.    (setq ecode (start_dialog))
  1402.   (cond
  1403.     ((= 1 ecode)
  1404.   (if *CellColor* (setvar "REGENMODE" 0))
  1405. (vlxls-app-init)
  1406. (or *xlapp*
  1407.      (if (VL-CATCH-ALL-ERROR-P
  1408.            (setq *xlApp* (VL-CATCH-ALL-APPLY
  1409.                            'vlax-get-or-create-object
  1410.                            '("Excel.Application")
  1411.                          )
  1412.            )
  1413.          )
  1414.        (exit)
  1415.      )
  1416. )
  1417. (if (equal :vlax-false (vlax-get-property *XLAPP* 'visible))
  1418.     (vla-put-visible *xlApp* 1)
  1419.   )
  1420. (if (= "User" *DrawRange*)
  1421.      (vlax-put-property *XLAPP* 'Visible 1)
  1422. )
  1423.   (setq workbooks (vlax-get-property *xlApp* 'workbooks))
  1424.   (if (= 0 (vla-get-Count workbooks))
  1425.     (setq workbook (vlax-invoke workbooks 'add))
  1426.     (setq workbook (vlax-get-property *xlApp* 'activeworkbook))
  1427.   )
  1428.   (setq sheet (vlax-get-property *xlApp* 'activesheet))
  1429.   (setq        UsedRange (vlax-get-property sheet 'UsedRange)
  1430.         col          (vlax-get-property
  1431.                     (vlax-get-property UsedRange 'columns)
  1432.                     'count
  1433.                   )
  1434.         row          (vlax-get-property
  1435.                     (vlax-get-property UsedRange 'rows)
  1436.                     'count
  1437.                   )
  1438.   )
  1439.   (cond
  1440.     ((= "Used" *DrawRange*)
  1441.      (setq Cells (vlax-get-property UsedRange 'Cells))
  1442.      ;(setq PrintArea (VLXLS-GET-PROPERTY *xlApp* "Activesheet.PageSetup.PrintArea"))
  1443.     )
  1444.     ((= "User" *DrawRange*)
  1445.      (alert "请在表格中选择数据后按确定键!")
  1446.      (setq Selection (vlax-get-property *xlApp* 'Selection)
  1447.            Cells     (vlax-get-property Selection 'Cells)
  1448.      )
  1449.      ;(setq PrintArea (VLXLS-GET-PROPERTY *xlApp* "Activesheet.PageSetup.PrintArea"))
  1450.     )
  1451.     ((= "PrintArea" *DrawRange*)
  1452.      (setq PrintArea (VLXLS-GET-PROPERTY *xlApp* "Activesheet.PageSetup.PrintArea"))
  1453.      (if (/= "" PrintArea)
  1454.        (setq Cells (vlax-get-property
  1455.                      (vlax-get-property *xlApp* 'range PrintArea)
  1456.                      'Cells
  1457.                    )
  1458.        )
  1459.        (progn
  1460.          (alert "当前活动表格没有可打印的页面!\n\n请重新设置页面!程序将退出!")
  1461.          (exit)
  1462.          )
  1463.      )
  1464.     )
  1465.   )
  1466.   (if (= 1 (vlax-get-property cells 'count))
  1467.     (progn
  1468.       (alert "Excel表格只有一行一列,程序将退出!")
  1469.       (exit)
  1470.     )
  1471.   )
  1472.   (if *pageSetUp*
  1473.     (progn
  1474.       (setq HPageBreaks nil)
  1475.       (GXL-CATCHAPPLY
  1476.         (lambda ()
  1477.            (vlax-for a (VLXLS-GET-PROPERTY
  1478.                          *xlapp*
  1479.                          "activesheet.HPageBreaks"
  1480.                        )
  1481.              (setq HPageBreaks
  1482.                     (cons (VLXLS-GET-PROPERTY a "Location.row")
  1483.                           HPageBreaks
  1484.                     )
  1485.              )
  1486.            )
  1487.          )
  1488.         nil
  1489.       )
  1490.       (setq HPageBreaks (reverse HPageBreaks)) ;_ 储存分页的Row位置
  1491.     )
  1492.   )
  1493.   (initget 7)
  1494.   (setq StartPoint (getpoint "\n放置位置:"))
  1495.   (setq StartPoint (trans StartPoint 1 0)
  1496.         BasePoint StartPoint)
  1497.   (setq        curpt  StartPoint
  1498.         OldRow nil
  1499.         to (vlax-get-property cells 'count)
  1500.   )
  1501.     ;|71
  1502.          附着点:
  1503.         1 = 左上;2 = 中上;3 = 右上
  1504.         4 = 左中;5 = 正中;6 = 右中
  1505.         7 = 左下;8 = 中下;9 = 右下
  1506.    |;
  1507.   (setq dxf71data '((1 4 7) (2 5 8) (3 6 9)))
  1508.   (GXL-SYS-PROGRESS-INIT "" to)
  1509.   (setq StandardFont (vlax-get-property *xlApp* 'StandardFont))
  1510.   (setq StandardFontSize (vlax-get-property *XLAPP* 'StandardFontSize))
  1511.   (setq defaultHeight (/ *THeight* StandardFontSize)) ;_ 默认高度
  1512.   (setq GridScale 1.941747572815534)
  1513.   (setq totalwide (vlax-variant-value (vlax-get-property cells 'Width))
  1514.             totalheight (vlax-variant-value (vlax-get-property cells 'height))
  1515.             )
  1516.   (setq pagesetup (VLXLS-GET-PROPERTY *xlapp* "activesheet.pagesetup"))
  1517.      (if (not *KeepTHeight*)
  1518.     (progn      
  1519.       (entmake
  1520.           (list
  1521.             '(0 . "LWPOLYLINE")
  1522.             '(100 . "AcDbEntity")
  1523.             '(67 . 0)
  1524.             '(100 . "AcDbPolyline")
  1525.             '(90 . 4)
  1526.             '(70 . 1)
  1527.             '(43 . 0.0)
  1528.             '(38 . 0.0)
  1529.             '(39 . 0.0)
  1530.             (cons 10 StartPoint)
  1531.             (cons 10
  1532.                   (setq p0 (polar StartPoint
  1533.                                   0
  1534.                                   (* totalwide GridScale defaultHeight)
  1535.                                   )
  1536.                         )
  1537.                   )
  1538.             (cons 10
  1539.                   (polar p0
  1540.                          (* 1.5 pi)
  1541.                          (* totalheight GridScale defaultHeight)
  1542.                          )
  1543.                   )
  1544.             (cons 10
  1545.                   (polar StartPoint
  1546.                          (* 1.5 pi)
  1547.                          (* totalheight GridScale defaultHeight)
  1548.                          )
  1549.                   )
  1550.             '(210 0.0 0.0 1.0)
  1551.             )
  1552.           )
  1553.       (setq endent (entlast))
  1554.       (setvar 'ORTHOMODE 1)
  1555.       (initget 6)
  1556.       (setq p0 (getdist (trans StartPoint 0 1) (strcat "\n输入表格宽度<" (rtos (* totalwide GridScale defaultHeight) 2 2) ">:")))
  1557.       (if (null p0) (setq p0 (* totalwide GridScale defaultHeight)))
  1558.       (entdel endent)
  1559.       (setq scale (/ p0 (* totalwide GridScale defaultHeight)))
  1560.       (setq defaultHeight (* defaultHeight scale))  
  1561.      )
  1562.     )
  1563.      (setq endent (entlast) )
  1564.      (setq page 1 TotalPage (1+ (length HPageBreaks)))
  1565.      (if *pageSetUp*
  1566.        (progn
  1567.          (setq PageMargin  ;_ 计算页间距
  1568.                 (* defaultHeight
  1569.                    GridScale
  1570.                    (+
  1571.                    (VLXLS-GET-PROPERTY
  1572.                      *xlapp*
  1573.                      "activesheet.pagesetup.BottomMargin"
  1574.                    )
  1575.                    (VLXLS-GET-PROPERTY
  1576.                      *xlapp*
  1577.                      "activesheet.pagesetup.FooterMargin"
  1578.                    )
  1579.                    (VLXLS-GET-PROPERTY
  1580.                      *xlapp*
  1581.                      "activesheet.pagesetup.TopMargin"
  1582.                    )
  1583.                    (VLXLS-GET-PROPERTY
  1584.                      *xlapp*
  1585.                      "activesheet.pagesetup.HeaderMargin"
  1586.                    )
  1587.                    )
  1588.                 )
  1589.          )
  1590.          (setq RightTopPt  ;_ 每页右上角点
  1591.                 (polar StartPoint
  1592.                        0
  1593.                        (* defaultHeight GridScale Totalwide)
  1594.                 )
  1595.          )
  1596.          ;;输出页眉
  1597.          (if *pageSetUp* (DrawPageSetUp pagesetup StartPoint t))
  1598.        )
  1599.      )
  1600.   ;;输出表头
  1601.   (if *pageSetUp* (PrintTitleRows cells))
  1602.   (if (setq TitleRows ;_ 存储表头的行数
  1603.              (VLXLS-GET-PROPERTY
  1604.                *XLAPP*
  1605.                "ActiveSheet.PageSetup.PrintTitleRows"
  1606.              )
  1607.       )
  1608.     (progn
  1609.       (setq TitleRows
  1610.              (mapcar
  1611.                'atoi
  1612.                (vl-remove ""
  1613.                           (GXL-STRPARSEBYLST TitleRows '(":" "$"))
  1614.                )
  1615.              )
  1616.             tmp (car TitleRows)
  1617.             tmp1 (cadr TitleRows)
  1618.             TitleRows nil
  1619.       )
  1620.       (if tmp1
  1621.         (while (<= tmp tmp1)
  1622.           (setq TitleRows (cons tmp TitleRows)
  1623.                 tmp (1+ tmp)
  1624.                 )
  1625.           )
  1626.         (setq TitleRows (list tmp))
  1627.         )
  1628.       (setq TitleRows (reverse TitleRows))
  1629.     )
  1630.   )



  1631.    ;;逐行逐列绘制表格
  1632.   (vlax-for cell cells
  1633.     (gxl-Sys-Progress to -1)
  1634.     (setq col         (vlax-get-property cell 'column)
  1635.           row         (vlax-get-property cell 'row)
  1636.           range (msxlp-get-range *xlApp* (VLXLS-RANGEID (list col row)))
  1637.           Mergep (equal :vlax-true (vlax-variant-value (vlax-get-property cell 'MergeCells)))
  1638.           width         (* defaultHeight GridScale (vlax-variant-value (vlax-get-property cell 'width)))
  1639.           height (* defaultHeight GridScale (vlax-variant-value (vlax-get-property cell 'height)))
  1640.           text         (vlax-variant-value (vlax-get-property cell 'text))
  1641.           )
  1642.     (cond
  1643.       ((and *pageSetUp* (member row TitleRows))) ;_ 忽略打印表头位置的表格
  1644.       (t
  1645.     (if        (and (/= text "")
  1646.              (not (equal width 0 0.01))
  1647.         )
  1648.       (progn
  1649.         (setq
  1650.           font (vlax-get-property range 'font)
  1651.           HorizontalAlignment
  1652.            (vlax-variant-value
  1653.              (vlax-get-property
  1654.                Cell
  1655.                'HorizontalAlignment
  1656.              )
  1657.            )
  1658.           HorizontalAlignment
  1659.            (cond ((= HorizontalAlignment -4152) 2) ;_ 右
  1660.                  ((= HorizontalAlignment -4108) 1) ;_ 中
  1661.                  (t 0) ;_ 左
  1662.            )
  1663.           VerticalAlignment
  1664.            (vlax-variant-value
  1665.              (vlax-get-property
  1666.                Cell
  1667.                'VerticalAlignment
  1668.              )
  1669.            )
  1670.           VerticalAlignment
  1671.            (cond ((= VerticalAlignment -4160) 0) ;_ 上
  1672.                  ((= VerticalAlignment -4108) 1) ;_ 中
  1673.                  (t 2) ;_ 下
  1674.            )
  1675.           DXF71        (nth VerticalAlignment
  1676.                      (nth HorizontalAlignment dxf71data)
  1677.                 )
  1678.           DXF62        (vlxls-color-eci->aci
  1679.                   (vlax-variant-value
  1680.                     (vlax-get-property Font 'colorIndex)
  1681.                   )
  1682.                 )
  1683.           DXF420 (vlxls-color-eci->truecolor
  1684.                    (vlax-variant-value
  1685.                      (vlax-get-property Font 'colorIndex)
  1686.                    )
  1687.                  )
  1688.         )
  1689.         ;;计算Range的字体 RangeFont i ii char cfont charFont caption f TextVerFlag
  1690.         (setq RangeFont
  1691.                (mapcar
  1692.                  '(lambda (x) (cons x (VLXLS-GET-PROPERTY font x)))
  1693.                  '("NAME"          "SIZE"         "COLORINDEX"
  1694.                    "BOLD"          "ITALIC"         "SUBSCRIPT"
  1695.                    "SUPERSCRIPT"  "UNDERLINE"
  1696.                   )
  1697.                )
  1698.         )
  1699.         (setq DXF7 (cdr (assoc "NAME" RangeFont)))
  1700.         (if (null dxf7) (setq DXF7 StandardFont))
  1701.         ;;字体
  1702.         (setq textFont (strcat "{\\f" DXF7 "|b0|i0|c134|p0;"))
  1703.         (setq Dxf40 (cdr (assoc "SIZE" RangeFont)))
  1704.         (if (null DXF40) (setq DXF40 StandardFontSize))
  1705.         ;;字大小
  1706.         (setq textFont (strcat textFont "\\H" (rtos DXF40 2 1) "x;"))
  1707.         ;;加粗
  1708.         (if (equal :vlax-true (cdr (assoc "BOLD" RangeFont)))
  1709.           (setq textfont (strcat textFont "\\W1.2;"))
  1710.           )
  1711.         ;;倾斜
  1712.         (if (equal :vlax-true (cdr (assoc "ITALIC" RangeFont)))
  1713.           (setq textfont (strcat textFont "\\Q18;"))
  1714.           )
  1715.         ;;下划线
  1716.         (if (= 2 (cdr (assoc "UNDERLINE" RangeFont)))
  1717.           (setq textfont (strcat textFont "\\L"))
  1718.           )
  1719.         ;;上标 "SUPERSCRIPT"
  1720.         ;;下标 "SUBSCRIPT"
  1721.         ;;文字是否竖向
  1722.         (setq TextVerFlag
  1723.                (= (GXL-CATCHAPPLY
  1724.                     VLXLS-GET-PROPERTY
  1725.                     (list range "Orientation")
  1726.                   )
  1727.                   -4166
  1728.                )
  1729.         )
  1730.         (if TextVerFlag
  1731.           (progn
  1732.             (setq text (gxl-str->singleonly text))
  1733.             (setq tmp  (car text)
  1734.                   text (cdr text)
  1735.             )
  1736.             (foreach a text (setq tmp (strcat tmp "\\P" a)))
  1737.             (setq text tmp)
  1738.           )
  1739.         )
  1740.         ;;逐字取样式
  1741.         ;;(setq textFont (strcat textFont (GetRangeTextStyle RANGE RANGEFONT text) "}"))
  1742.         
  1743.         (setq text (strcat textFont text "}"))

  1744.       )
  1745.     )
  1746.     (cond ((null OldRow) (setq OldRow Row))
  1747.           ((/= OldRow Row) ;_ 换行
  1748.            (if *pageSetUp*
  1749.              (progn
  1750.                (if (member row HPageBreaks) ;_ 换页
  1751.                  (progn
  1752.                    (setq OldRow            Row
  1753.                          StartPoint (polar StartPoint
  1754.                                            (* 1.5 pi)
  1755.                                            oldheight
  1756.                                     )
  1757.                    )
  1758.                    (if *Merge*
  1759.                      (progn
  1760.                        (entmake
  1761.                          (list
  1762.                            '(0 . "line")
  1763.                            '(100 . "AcDbEntity")
  1764.                            '(67 . 0)
  1765.                            (cons 8 Blayer)
  1766.                            (cons 62 *defaultColor*)
  1767.                            '(100 . "AcDbLine")
  1768.                            (cons 10
  1769.                                  StartPoint

  1770.                            )
  1771.                            (cons
  1772.                              11
  1773.                              (setq p0
  1774.                                     (polar
  1775.                                       StartPoint
  1776.                                       0
  1777.                                       (* defaultHeight GridScale Totalwide)
  1778.                                     )
  1779.                              )
  1780.                            )
  1781.                            '(210 0.0 0.0 1.0)
  1782.                          )
  1783.                        )
  1784.                        (entmake
  1785.                          (list
  1786.                            '(0 . "line")
  1787.                            '(100 . "AcDbEntity")
  1788.                            '(67 . 0)
  1789.                            (cons 8 Blayer)
  1790.                            (cons 62 *defaultColor*)
  1791.                            '(100 . "AcDbLine")
  1792.                            (cons 10 RightTopPt)
  1793.                            (cons 11 p0)
  1794.                            '(210 0.0 0.0 1.0)
  1795.                          )
  1796.                        )
  1797.                        
  1798.                      )
  1799.                    )
  1800.                    ;;输出页脚代吗
  1801.                    (if *pageSetUp* (DrawPageSetUp pagesetup StartPoint nil))
  1802.                    ;;分组或分块
  1803.                    (cond
  1804.                      ((= 1 *Oprate*)
  1805.                       (setq ss (GXL-SEL-ENTNEXTALL endent))
  1806.                       (if *CellColor*
  1807.                         (progn
  1808.                           (command "_select" ss "")
  1809.                           (setq s1 (ssget "_p" '((0 . "solid"))))
  1810.                           (if s1
  1811.                             (gxl-MovetoBottom s1)
  1812.                           )
  1813.                         )
  1814.                       )
  1815.                       (gxl-AX:AddUnNameGroup ss)
  1816.                       (setq endent (entlast))
  1817.                      )
  1818.                      ((= 2 *Oprate*)
  1819.                       (setq ss (GXL-SEL-ENTNEXTALL endent))
  1820.                       (if *CellColor*
  1821.                         (progn
  1822.                           (command "_select" ss "")
  1823.                           (setq s1 (ssget "_p" '((0 . "solid"))))
  1824.                           (if s1
  1825.                             (gxl-MovetoBottom s1)
  1826.                           )
  1827.                         )
  1828.                       )
  1829.                       (gxl-BLK-UnBlockBase ss 4)
  1830.                       (setq endent (entlast))
  1831.                      )
  1832.                    )

  1833.                      
  1834.                    (setq StartPoint (polar StartPoint (* 1.5 pi) PageMargin)
  1835.                          Curpt            StartPoint
  1836.                          RightTopPt (polar StartPoint 0 (* defaultHeight GridScale Totalwide))
  1837.                          ) ;_ 移动页间距
  1838.                    (setq page (1+ page))
  1839.                    ;;输出页眉代吗
  1840.                    (if *pageSetUp* (DrawPageSetUp pagesetup StartPoint t))
  1841.                    ;;输出表头
  1842.                    (if *pageSetUp* (PrintTitleRows cells))
  1843.                   
  1844.                  )
  1845.                  (setq OldRow          Row
  1846.                        StartPoint (polar StartPoint (* 1.5 pi) oldheight)
  1847.                        Curpt          StartPoint
  1848.                  )
  1849.                )
  1850.              )
  1851.              (setq OldRow     Row
  1852.                    StartPoint (polar StartPoint (* 1.5 pi) oldheight)
  1853.                    Curpt      StartPoint
  1854.              )
  1855.            )

  1856.            
  1857.           )
  1858.     )

  1859.     (setq oldheight height)
  1860.     (if (not (equal width 0 0.01))
  1861.       (progn
  1862.     (if Mergep
  1863.       (progn
  1864.         (setq mergeId (mapcar 'vlxls-rangeid
  1865.                               (vlxls-cellid (vlxls-range-getid range))
  1866.                               )
  1867.               width1 (* defaultHeight GridScale (VLXLS-GET-PROPERTY range "MergeArea.width"))
  1868.               height1 (* defaultHeight GridScale (VLXLS-GET-PROPERTY range "MergeArea.height"))
  1869.               )
  1870.         )
  1871.       (setq width1 width height1 height)
  1872.       )
  1873.     (if        (or (not Mergep)
  1874.             (and Mergep (equal (car mergeId) (list col row)))
  1875.         )
  1876.       (progn
  1877.         (setq p0 (polar Curpt (* 1.5 pi) height1)
  1878.               p1 Curpt
  1879.               p2 (polar Curpt 0 width1)
  1880.               p3 (polar p2 (* 1.5 pi) height1)
  1881.               ) ;_ 框的四个角点 左下、左上、右上、右下
  1882.         (if *Merge*
  1883.           (progn
  1884.             (if Horline
  1885.               (progn
  1886.                 (if (equal p1 (gxl-dxf HorLine 11) 1e-3)
  1887.                   (gxl-ch_ent HorLine 11 p2) ;_ 更新水平直线末端点
  1888.                   (progn
  1889.                 (entmake
  1890.                   (list
  1891.                     '(0 . "line")
  1892.                     '(100 . "AcDbEntity")
  1893.                     '(67 . 0)
  1894.                     (cons 8 Blayer)
  1895.                     (cons 62 *defaultColor*)
  1896.                     '(100 . "AcDbLine")
  1897.                     (cons 10 p1)
  1898.                     (cons 11 p2)
  1899.                     '(210 0.0 0.0 1.0)
  1900.                     )
  1901.                   )
  1902.                 (setq Horline (entlast))
  1903.                 )
  1904.                   )
  1905.                )
  1906.               (progn
  1907.                 (entmake
  1908.                   (list
  1909.                     '(0 . "line")
  1910.                     '(100 . "AcDbEntity")
  1911.                     '(67 . 0)
  1912.                     (cons 8 Blayer)
  1913.                     (cons 62 *defaultColor*)
  1914.                     '(100 . "AcDbLine")
  1915.                     (cons 10 p1)
  1916.                     (cons 11 p2)
  1917.                     '(210 0.0 0.0 1.0)
  1918.                     )
  1919.                   )
  1920.                 (setq Horline (entlast))
  1921.                 )
  1922.               )
  1923.             (if VerLines
  1924.               (progn
  1925.                 (if (not
  1926.                       (vl-some
  1927.                       (Function
  1928.                       (lambda (Line)
  1929.                          (if (equal p1 (gxl-dxf Line 11) 1e-3)
  1930.                            (gxl-ch_ent Line 11 p0) ;_ 更新垂直直线末端点
  1931.                            )
  1932.                          )
  1933.                       )
  1934.                       VerLines
  1935.                       )
  1936.                     )
  1937.                   (progn
  1938.                     (entmake
  1939.                       (list
  1940.                         '(0 . "line")
  1941.                         '(100 . "AcDbEntity")
  1942.                         '(67 . 0)
  1943.                         (cons 8 Blayer)
  1944.                         (cons 62 *defaultColor*)
  1945.                         '(100 . "AcDbLine")
  1946.                         (cons 10 p1)
  1947.                         (cons 11 p0)
  1948.                         '(210 0.0 0.0 1.0)
  1949.                         )
  1950.                       )
  1951.                     (setq VerLines (cons (entlast) VerLines))
  1952.                     )
  1953.                   )
  1954.                 )
  1955.               (progn
  1956.                 (entmake
  1957.                   (list
  1958.                     '(0 . "line")
  1959.                     '(100 . "AcDbEntity")
  1960.                     '(67 . 0)
  1961.                     (cons 8 Blayer)
  1962.                     (cons 62 *defaultColor*)
  1963.                     '(100 . "AcDbLine")
  1964.                     (cons 10 p1)
  1965.                     (cons 11 p0)
  1966.                     '(210 0.0 0.0 1.0)
  1967.                     )
  1968.                   )
  1969.                 (setq VerLines (cons (entlast) VerLines))
  1970.                 )
  1971.               )
  1972.             )
  1973.           (entmake
  1974.             (list
  1975.               '(0 . "LWPOLYLINE")
  1976.               '(100 . "AcDbEntity")
  1977.               '(67 . 0)
  1978.               (cons 8 BLayer)
  1979.               (cons 62 *defaultColor*)
  1980.               '(100 . "AcDbPolyline")
  1981.               '(90 . 4)
  1982.               '(70 . 1)
  1983.               '(43 . 0.0)
  1984.               '(38 . 0.0)
  1985.               '(39 . 0.0)
  1986.               (cons 10 p0)
  1987.               (cons 10 p1)
  1988.               (cons 10 p2)
  1989.               (cons 10 p3)
  1990.               '(210 0.0 0.0 1.0)
  1991.               )
  1992.             )
  1993.           )
  1994.         (if *CellColor* ;_ 绘制背景颜色
  1995.           (progn
  1996.             (if        (/= -4142
  1997.                     (setq Interiorcolor
  1998.                            (VLXLS-GET-PROPERTY
  1999.                              range
  2000.                              "Interior.ColorIndex"
  2001.                            )
  2002.                     )
  2003.                 )
  2004.               (progn
  2005.                 (setq Interiorcolor        (VLXLS-COLOR-ECI->ACI Interiorcolor)
  2006.                       Interiortruecolor        (VLXLS-COLOR-ECI->TRUECOLOR
  2007.                                           Interiorcolor
  2008.                                         )
  2009.                 )
  2010.                 (entmake
  2011.                   (vl-remove
  2012.                     nil
  2013.                     (list
  2014.                       '(0 . "SOLID")
  2015.                       '(100 . "AcDbEntity")
  2016.                       '(67 . 0)
  2017.                       (cons 8 BLayer)
  2018.                       (cons 62 Interiorcolor)
  2019.                       ;|(if (not (or (= 256 Interiorcolor)
  2020.                                    (= 0 Interiortruecolor)
  2021.                                )
  2022.                           )
  2023.                         (cons 420 Interiortruecolor)
  2024.                       )|;
  2025.                       '(100 . "AcDbTrace")
  2026.                       (cons 10 p0)
  2027.                       (cons 11 p1)
  2028.                       (cons 12 p3)
  2029.                       (cons 13 p2)
  2030.                       '(210 0.0 0.0 1.0)
  2031.                     )
  2032.                   )
  2033.                 )
  2034.               )
  2035.             )
  2036.           )
  2037.         )
  2038.         (if (/= "" text)
  2039.           (progn
  2040.             (setq textpt (nth (1- DXF71) (Get9JustPts p0 p2)))
  2041.             (cond ((= 0 HorizontalAlignment) ;_ 左对齐
  2042.                    (setq textpt (polar textpt 0 (* height 0.1)))
  2043.                   )
  2044.                   ((= 2 HorizontalAlignment) ;_ 右对齐
  2045.                    (setq textpt (polar textpt pi (* height 0.1)))
  2046.                   )
  2047.             )
  2048.             (cond
  2049.               ((= 0 VerticalAlignment) ;_ 上对齐
  2050.                (setq textpt (polar textpt (* 1.5 pi) (* height 0.1)))
  2051.               )
  2052.               ((= 2 VerticalAlignment) ;_ 下对齐
  2053.                (setq textpt (polar textpt (* 0.5 pi) (* height 0.1)))
  2054.               )
  2055.             )
  2056.             (entmake
  2057.               (vl-remove
  2058.                 nil
  2059.                 (list
  2060.                   (cons 0 "MTEXT")
  2061.                   '(100 . "AcDbEntity")
  2062.                   '(67 . 0)
  2063.                   (cons 8 TLayer)
  2064.                   (if *AnnoColor*
  2065.                     (cons 62 dxf62)
  2066.                     (cons 62 *defaultColor*)
  2067.                   )
  2068.                   ;|(if (and *AnnoColor*
  2069.                            (not (or (= 256 dxf62) (= 0 dxf420)))
  2070.                       )
  2071.                     (cons 420 dxf420)
  2072.                   )|;
  2073.                   '(100 . "AcDbMText")
  2074.                   (cons 10 textpt)
  2075.                   (cons 40 defaultHeight)
  2076.                   (cons 41 width1)
  2077.                   ;(cons 50 0)
  2078.                   ;;'(46 . 0.0)
  2079.                   (cons 71 DXF71)
  2080.                   (cons 72 5)
  2081.                   (cons 1 text)
  2082.                   (cons 7 "Standard")
  2083.                   '(210 0.0 0.0 1.0)
  2084.                   '(11 1.0 0.0 0.0)
  2085.                   '(50 . 0.0)
  2086.                   '(73 . 1)
  2087.                 )
  2088.               )
  2089.             )
  2090.           )
  2091.         )
  2092.       )
  2093.     )
  2094.     (setq Curpt (polar Curpt 0 width))
  2095.     )
  2096.       )
  2097.     ) ;_ t
  2098.      ) ;_ cond
  2099.   )
  2100. (GXL-SYS-PROGRESS-DONE)
  2101. (if *Merge*
  2102.    (progn
  2103.      (if *pageSetUp*
  2104.        (setq dd (* PageMargin (* (length HPAGEBREAKS))))
  2105.        (setq dd 0)
  2106.        )
  2107.             (entmake
  2108.               (list
  2109.                 '(0 . "line")
  2110.                 '(100 . "AcDbEntity")
  2111.                 '(67 . 0)
  2112.                 (cons 8 Blayer)
  2113.                 (cons 62 *defaultColor*)
  2114.                 '(100 . "AcDbLine")
  2115.                 (if *pageSetUp*
  2116.                   (cons 10 (setq p0 RightTopPt))
  2117.                   (cons        10
  2118.                         (setq
  2119.                           p0 (polar BasePoint
  2120.                                     0
  2121.                                     (* defaultHeight GridScale Totalwide)
  2122.                              )
  2123.                         )
  2124.                   )
  2125.                 )
  2126.                 (cons 11 p3)
  2127.                 ;(cons 11 (setq p1 (polar p0 (* 1.5 pi) (+ dd (* defaultHeight GridScale Totalheight)))))
  2128.                 '(210 0.0 0.0 1.0)
  2129.                 )
  2130.               )
  2131.             (entmake
  2132.               (list
  2133.                 '(0 . "line")
  2134.                 '(100 . "AcDbEntity")
  2135.                 '(67 . 0)
  2136.                 (cons 8 Blayer)
  2137.                 (cons 62 *defaultColor*)
  2138.                 '(100 . "AcDbLine")
  2139.                 (cons 10 (polar p3 pi (* defaultHeight GridScale Totalwide)))
  2140.                 (cons 11 p3)
  2141.                 '(210 0.0 0.0 1.0)
  2142.                 )
  2143.               )
  2144.             (setq p3 (polar p2 (* 1.5 pi) height1))
  2145.             )
  2146.    )
  2147.    ;;输出页脚代吗
  2148.     (if *pageSetUp* (DrawPageSetUp pagesetup StartPoint nil))
  2149. (setq ss (GXL-SEL-ENTNEXTALL endent))
  2150. (if *CellColor*
  2151.    (progn
  2152.      (command "_select" ss "")
  2153.      (setq s1 (ssget "_p" '((0 . "solid"))))
  2154.      (if s1
  2155.        (gxl-MovetoBottom s1)
  2156.        )
  2157.      )
  2158.    )
  2159. (cond
  2160.      ((= 1 *Oprate*)
  2161.       (gxl-AX:AddUnNameGroup ss)
  2162.       )
  2163.      ((= 2 *Oprate*)
  2164.       (gxl-BLK-UnBlockBase ss 4)
  2165.       )
  2166.      )
  2167.      (vlax-release-object *xlapp*)
  2168.      )
  2169.     )
  2170.   (reerr)
  2171. (princ)
  2172. )

本帖子中包含更多资源

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

x

点评

版主就是版主,不服不行!!  发表于 2017-3-30 22:25
很給力  发表于 2013-10-17 21:11

评分

参与人数 14明经币 +16 金钱 +95 收起 理由
JUN1 + 1 很给力!
iiAmethyst + 5 &amp;lt;font style=&amp;quot;vertical-align: inh
Michael527 + 1 很给力!
zctao1966 + 1 赞一个!
linshiyin2 + 1 操作太复杂,最好能简化一点,选择什么就写.
kwok + 1 很给力!
自贡黄明儒 + 1 很给力!
wowan1314 + 1 赞一个!
jicqj + 1 很给力!
【KAIXIN】 + 1 赞一个!

查看全部评分

"觉得好,就打赏"
    共1人打赏

本帖被以下淘专辑推荐:

发表于 2013-6-9 13:43 | 显示全部楼层
G版的东西一定要顶
回复 支持 0 反对 1

使用道具 举报

发表于 2013-6-9 14:43 | 显示全部楼层
G版的强贴,收藏关注中
回复 支持 1 反对 0

使用道具 举报

发表于 2016-6-20 15:14 | 显示全部楼层
正在学习 excel和cad的交互操作,可惜没权限下载这个附件。。。
回复 支持 1 反对 0

使用道具 举报

发表于 2013-6-9 13:58 | 显示全部楼层
暂时发现两个问题,1.表头没有合并居中的话会全部挤在第一个单元格,没有表格线的单元格全部加入了边框线. 2.表格较长时无法绘制完成,直接跳出了,显示如下
X2C
放置位置:
输入表格宽度<25733.01>:
参数类型错误: numberp: nil
现附上测试的表格和图片

本帖子中包含更多资源

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

x

评分

参与人数 1明经币 +1 收起 理由
Gu_xl + 1 认真测试奖!

查看全部评分

回复 支持 1 反对 0

使用道具 举报

发表于 2013-6-9 13:42 | 显示全部楼层
看起来很牛,支持分享,谢谢!
发表于 2013-6-9 13:44 | 显示全部楼层
不错,学习了
发表于 2013-6-9 13:47 | 显示全部楼层
精华帖 首页留名。 好像用处不大,研究还可以
发表于 2013-6-9 13:52 | 显示全部楼层
好工具,好长的代码。
发表于 2013-6-9 13:59 | 显示全部楼层
对了,还有上标好像不支持
 楼主| 发表于 2013-6-9 14:20 | 显示全部楼层
hao3ren 发表于 2013-6-9 13:58
暂时发现两个问题,1.表头没有合并居中的话会全部挤在第一个单元格,没有表格线的单元格全部加入了边框线.  ...

本程序没有考虑表格的边框情况,所有单元格均加边框!
单元格文字的局部样式,也没有考虑!
出错的Bug已修改!

点评

晕,Range对象的Characters属性有时行,有时不行。今天测试了三次,只有一次出现Automation错误,不知道是我程序的问题,还是不稳定的原因。G版,你测试下。  发表于 2013-6-9 20:27
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-3 21:29 , Processed in 0.343987 second(s), 32 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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