Author Topic: How to put a lot's text figures (that's in excel) into the pure digital format?  (Read 18271 times)

0 Members and 1 Guest are viewing this topic.

jxphklibin

  • Guest
I have a procedure to put the coordinates Export to EXCEL, but the coordinate values are text values, rather than a purely digital format, this issue has confused me a long time.

How to use vlisp/lisp procedures to puting a lot's text figures (that it is in excel) into the pure digital format?

Who can help me, very grateful!

Now, put attachment affixed below for reference:
« Last Edit: February 25, 2009, 04:13:02 AM by jxphklibin »

FengK

  • Guest
i think you'll need to show (part of) your procedure so others can tell you where to modify instead of the excel file.

Atook

  • Swamp Rat
  • Posts: 1029
  • AKA Tim
If I understand correctly, you want the cells to be numbers instead of text?

Guessing that the lisp you're using is running VLX stuff, you might try selecting the range that includes your point data and doing something like:

 range.NumberFormat = "#,##0.00"

If that doesn't help, post your procedure as xycadd indicated.

jxphklibin

  • Guest
Hi,Atook

You understand that almost, but not entirely correct.

Here is my codes:

Code: [Select]
;| Output the center coordinates of Circle to EXCEL Project
 Copyright(C) 2007-2010 by libin (小李子 MuziCAD 木子CAD). All rights reserved.
 Permission to use, copy, modify, and distribute this software for any purpose and without fee is hereby granted, provided that the above copyright notice appears in all copies and that both that copyright notice and the limited warranty and restricted rights notice below appear in all supporting documentation.
|;

;; Start Sub-Functions ;;
(defun GetMyDocumentsDir ()
  (vlax-invoke-method
    (vlax-get-property
      (vlax-create-object "wscript.shell")
      'SpecialFolders
    )
    'Item
    "MyDocuments"
  )
)

(defun ZbOut_getfile (/ Rtn)
  (setq Rtn (getfiled "Save the Coordinate file"
      (strcat (GetMyDocumentsDir)
      "\\"
      (vl-filename-base (getvar "dwgname"))
      "_ZB.xls"
      )
      "xls"
      9
    )
  )
  Rtn
)

;|
Following is the pre-define part of VLXLS project, VLXLS need a global variable named as *xls-color* to contain all color matching list. Syntax as (ECI ACI TrueColor), sorted as ECI number.
As VLXLS support two languages: English as international and Simplified Chinese as local. In Default, VLXLS will go to seek if global variable *Chinese* is true, if so, VLXLS will prompt Chinese, or VLXLS will display English as default.
|;
(if vl-load-com
  (vl-load-com)
)
(if vl-arx-import
  (foreach item '(ACAD_COLORDLG      ACAD_truecolordlg
  ACAD_STRLSORT      INITDIA
  ACAD-POP-DBMOD     ACAD-PUSH-DBMOD
  STARTAPP      layoutlist
)
    (vl-arx-import item)
  )
)
(setq item nil
      *Chinese* nil
)

;; Excel Application Session Progress Function
(Defun vlxls-app-Init (/ OSVar GGG Olb8 Olb9 Olb10 TLB Out msg msg1 msg2)
  (if *Chinese*
    (setq msg  "\n 初始化微软Excel "
  msg1 "\042初始化Excel错误\042"
  msg2 (strcat
"\042 警告"
"\n ===="
"\n 无法在您的计算机上检测到微软Excel软件"
"\n 如果您确认已经安装Excel, 请发送电子邮"
"\n 件到GuXiaolin@hxch.com.cn获取更多的解决方案\042"
)
    )
    (setq msg  "\n Initializing Microsoft Excel "
  msg1 "\042Initialization Error\042"
  msg2 (strcat
"\042 WARNING" "\n ======="
"\n Can NOT detect Excel97/200X/XP in your computer"
"\n If you already have Excel installed, please email"
"\n us to get more solution via GuXiaolin@hxch.com.cn\042")
    )
  )
  (if (null msxl-xl24HourClock)
    (progn
      (if (and (setq GGG
      (vl-registry-read
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\Excel.EXE"
"Path"
      )
       )
       (setq GGG (strcase (strcat GGG "Excel.EXE")))
  )
(progn
  (foreach OSVar (list "SYSTEMROOT" "WINDIR"
       "WINBOOTDIR" "SYSTEMDRIVE"
       "USERNAME" "COMPUTERNAME"
       "HOMEDRIVE" "HOMEPATH"
       "PROGRAMFILES"
      )
    (if (vl-string-search (strcat "%" OSVar "%") GGG)
      (setq GGG (vl-string-subst
  (strcase (getenv OSVar))
  (strcat "%" OSVar "%")
  GGG
)
      )
    )
  )
  (setq Olb8  (findfile (vl-string-subst "EXCEL8.OLB" "EXCEL.EXE" GGG)
      )
Olb9  (findfile (vl-string-subst "EXCEL9.OLB" "EXCEL.EXE" GGG)
      )
Olb10 (findfile
(vl-string-subst "EXCEL10.OLB" "EXCEL.EXE" GGG)
      )
  )
  (cond ((= (vl-filename-base (vl-filename-directory GGG))

    "OFFICE11"
)
(setq TLB GGG
       Out "2003"
)
)
((= (vl-filename-base (vl-filename-directory GGG))
    "OFFICE10"
)
(setq TLB GGG
       Out "XP"
)
)
(Olb9
(setq TLB Olb9
       Out "2000"
)
)
(Olb8
(setq TLB Olb8
       Out "97"
)
)
(t (setq Out "Version Unknown"))
  )
  (if TLB
    (progn
      (princ (strcat MSG Out "..."))
      (vlax-import-type-library
:tlb-filename   TLB     :methods-prefix
"msxl-"   :properties-prefix
"msxl-"   :constants-prefix "msxl-"
       )
    )
  )
)
(progn
  (if vldcl-msgbox
    (vldcl-msgbox "x" msg1 msg2)
    (alert (read msg2))
  )
  (exit)
)
      )
    )
  )
  msxl-xl24HourClock
)

;;New Excel document  T for display, nil for hide
(Defun vlxls-app-New (UnHide / Rtn)
  (if (vlxls-app-init)
    (progn
      (if *Chinese*
(princ "\n 新建微软Excel工作表...")
(princ "\n Creating new Excel Spreadsheet file...")
      )
      (if (setq Rtn (vlax-get-or-create-object "Excel.Application"))
(progn
  (vlax-invoke-method
    (vlax-get-property Rtn 'WorkBooks)
    'Add
  )
  (if UnHide
    (vla-put-visible Rtn 1)
    (vla-put-visible Rtn 0)
  )
)
      )
    )
  )
  Rtn
)

;;; Import data ton the cells
(Defun vlxls-cell-put-value (xl id Data / vllist-explode idx xx yy ary Rtn)
  (Defun vllist-explode (lst)
    (cond
      ((not lst) nil)
      ((atom lst) (list lst))
      ((append (vllist-explode (car lst))
       (vllist-explode (cdr lst))
       )
      )
    )
  )
  (if (null id)
    (setq id "A1")
  )
  (if (= (type id) 'list)
    (setq id (vlxls-rangeid id))
  )
  (if (= (type (car Data)) 'LIST)
    (setq ARY (vlax-make-safearray
vlax-vbstring
(cons 0 (1- (length Data)))
(cons 1 (length (car Data)))
      )
  XX  (1- (length (car Data)))
  YY  (1- (length Data))
    )
    (setq
      ARY (vlax-make-safearray
    vlax-vbstring
    (cons 0 1)
    (cons 1 (length Data))
  )
      XX  (1- (length Data))
      YY  0
    )
  )
  (if (= xx yy 0)
    (MSXL-PUT-VALUE2
      (setq Rtn (msxl-get-range xl id))
      (car (vllist-explode data))
    )
    (progn
      (setq id (vlxls-cellid-calc id xx yy))
      (MSXL-PUT-VALUE2
(setq Rtn (msxl-get-range xl id))
(vlax-safearray-fill ary data)
      )
    )
  )
  Rtn
)

(Defun vlxls-rangeid (id / str->list list->str xid->str Rtn)
  (Defun str->list (str / ii xk xv rr pos x y)
    (setq rr (strlen str))
    (foreach ii '("0" "1" "2" "3" "4" "5" "6" "7" "8" "9")
      (if (setq pos (vl-string-search ii str))
(setq rr (min pos rr))
      )
    )
    (setq x (substr str 1 rr)
  y (substr str (1+ rr))
    )
    (if (= (strlen x) 2)
      (setq xk (- (ascii (substr x 1 1)) 64)
    xv (- (ascii (substr x 2)) 64)
      )
      (setq xk 0
    xv (- (ascii x) 64)
      )
    )
    (list (+ (* xk 26) xv) (read y))
  )
  (Defun xid->str (IntNum / PosNum Nm-One)
    (setq Nm-One (1- IntNum)
  PosNum (/ Nm-One 26)
    )
    (if (= PosNum 0)
      (chr (+ 65 (rem Nm-One 26)))
      (strcat (chr (+ 64 PosNum)) (chr (+ 65 (rem Nm-One 26))))
    )
  )
  (Defun list->str (idr / x y)
    (setq x (car idr)
  y (cadr idr)
  x (xid->str x)
  y (itoa y)
    )
    (strcat x y)
  )
  (cond ((= (type id) 'str) (setq Rtn (str->list id)))
((= (type id) 'list) (setq Rtn (list->str id)))
  )
  Rtn
)

(Defun vlxls-cellid-calc (id x y / idx)
  (setq id  (car (vlxls-cellid id))
idx (vlxls-rangeid id)
x   (+ x (car idx))
x   (if (< x 1)
      1
      x
    )
y   (+ y (cadr idx))
y   (if (< y 1)
      1
      y
    )
idx (vlxls-rangeid (list x y))
id  (vlxls-cellid (strcat id ":" idx))
id  (strcat (car id) ":" (cadr id))
  )
  id
)

(Defun vlxls-cellid (id / xx id1 id2 Rtn)
  (if (= (type id) 'list)
    (setq id (vlxls-rangeid id))
  )
  (setq id (strcase id))
  (if (null (setq xx (vl-string-search ":" id)))
    (setq Rtn (list id ""))
    (setq id1 (substr id 1 xx)
  id2 (substr id (+ xx 2))
  id1 (vlxls-rangeid id1)
  id2 (vlxls-rangeid id2)
  Rtn (list (vlxls-rangeid
      (list (min (car id1) (car id2))
    (min (cadr id1) (cadr id2))
      )
    )
    (vlxls-rangeid
      (list (max (car id1) (car id2))
    (max (cadr id1) (cadr id2))
      )
    )
      )
    )
  )
  Rtn
)

;; Merge Cells
;; Run cell merge in Excel. Only 1st un-empty value will be left in merged cell
(Defun vlxls-cell-merge (xl id / vllist-explode Val Rtn)
  (Defun vllist-explode (lst)
    (cond
      ((not lst) nil)
      ((atom lst) (list lst))
      ((append (vllist-explode (car lst))
       (vllist-explode (cdr lst))
       )
      )
    )
  )
  (setq val (vllist-explode (vlxls-cell-get-value xl id)))
  (while (vl-position "" val)
    (setq val (vl-remove "" val))
  )
  (setq val (car val)
Rtn (msxl-get-range xl id)
  )
  (msxl-clear Rtn)
  (msxl-merge Rtn nil)
  (msxl-put-value2 Rtn Val)
  (msxl-put-HorizontalAlignment Rtn -4108)
  Rtn
)


;; Get value of certain Cell ID
(Defun vlxls-cell-get-value (xl id)
  (if (= (type id) 'list)
    (setq id (vlxls-rangeid id))
  )
  (vlxls-variant->list
    (msxl-get-value2 (msxl-get-range xl id))
  )
)

;; Convert a variant into normal Visual LISP LIST data, nested Variant and safearray will also be converted.
(Defun vlxls-variant->list (VarX / Run Item Rtn)
  (setq Run T)
  (while
    Run
     (cond ((= (type VarX) 'SAFEARRAY)
           (setq VarX (vlax-safearray->list VarX))
          )
          ((= (type VarX) 'VARIANT)
           (if    (member (vlax-variant-type VarX) (list 5 4 3 2))
             (setq VarX (vlax-variant-change-type Varx vlax-vbString))
           )
           (setq VarX (vlax-variant-value VarX))
          )
          (t (setq Run nil))
     )
  )
  (cond  ((= (type VarX) 'LIST)
        (foreach Item VarX
          (setq Item (vlxls-variant->list Item)
               Rtn  (append Rtn (list Item))
          )
        )
       )
       ((= VarX nil) (setq Rtn ""))
       (t (setq Rtn VarX))
  )
  Rtn
)

(defun vlxls-get-cell  (obj row col / item cells)
  (setq item (vlax-get-property
    (setq cells (vlax-get-property obj "Cells"))
    "Item"
    (vlax-make-variant row)
    (vlax-make-variant col)))
  (vlax-release-object cells)
  (vlax-variant-value item)
)

;; Set the font of text in the cell
(defun vlxls-Excel-cellfontname (xlapp row col name / sheet cell)
  (setq sheet (vlax-get-property xlapp "ActiveSheet"))
  (vlax-put-property (vlax-get-property (setq cell (vlxls-get-cell sheet row col)) "font") "name" name)
)

;; Change text size
(defun vlxls-Excel-textsize (xlapp row col size / sheet cell)
  (setq sheet (vlax-get-property xlapp "ActiveSheet"))
  (setq cell (vlxls-get-cell sheet row col))
  (vlax-put-property
    (vlax-get-property cell "font")
    "Size"
    size
  )
)

;; Change Text color
(defun vlxls-Excel-textcolor (xlapp row col color / sheet cell)
  (setq sheet (vlax-get-property xlapp "ActiveSheet"))
  (setq cell (vlxls-get-cell sheet row col))
  (vlax-put-property
    (vlax-get-property cell "font")
    "ColorIndex"
    color
  )
)

;; Adjust column widths
(defun vlxls-Excel-ColumnWidth (xlapp col width / sheet cell)
  (setq sheet (vlax-get-property xlapp "ActiveSheet"))
  (vlax-put-property (setq cell (vlxls-get-cell sheet 1 col)) "ColumnWidth" width)
)

;; Adjust row height
(defun vlxls-Excel-RowHeight (xlapp row height / sheet cell)
  (setq sheet (vlax-get-property xlapp "ActiveSheet"))
  (vlax-put-property (setq cell (vlxls-get-cell sheet row 1)) "RowHeight" height)
)

;; End Sub-Functions ;;

;; The beginning of the main program
(defun c:Getcen2Excel (/    Zbout_ss    Zbout_N    Zbout_ssNum
       RepNo1    RepNo2      *No1*    Coord_prec
       ZBOutpath   ExcelID     OutPutDLst  ent_name
       ent_data    Zbout_pt    *xlapp*    *Tmp*
      )
  (setvar "cmdecho" 0)
  ;;(vl-load-com)
  ;;(LOAD "vlxls.lsp") ;Call a function library file which is to operate excel
  (princ
    "\nplease select the circle so to output its center coordinates: "
  ) ;Please select the circle so to output the coordinates of its center
  (if (setq Zbout_ss (ssget '((0 . "circle"))))
    (progn
      (setq Zbout_N 0
    Zbout_ssNum
     (sslength Zbout_ss)
    RepNo1 0
    RepNo2 1
    *No1* 0
    Coord_prec 3
      )
      (if (setq ZBOutpath (ZbOut_getfile))
(progn
  (princ "正在输出到EXCEL,请不要进行其它操作......")
  (setq ExcelID    (strcat "A1:D" (itoa (+ Zbout_ssNum 2)))
OutPutDLst (list '("圆心坐标表(测量)" "" "" "")
'("序号" "X坐标" "Y坐标" "Z坐标")
   )
  )
  (repeat Zbout_ssNum
    (setq ent_name   (ssname Zbout_ss Zbout_N)
  ent_data   (entget ent_name)
  Zbout_pt   (cdr (assoc 10 ent_data))
  OutPutDLst (append
       OutPutDlst
       (list
(list (itoa (setq Zbout_N (1+ Zbout_N)))
       (rtos (cadr ZbOut_pt) 2 Coord_prec)
       (rtos (car ZbOut_pt) 2 Coord_prec)
       (rtos (caddr ZbOut_pt) 2 Coord_prec)
)
       )
     )
    )
  )
  (setq *xlapp* (vlxls-app-new t))
  (vlxls-cell-put-value *xlapp* ExcelID OutPutDLst) ; Output to Excel spreadsheet
  (vlxls-cell-merge *xlapp* "A1:D1") ; Merge Cells
  (msxl-put-HorizontalAlignment
    (msxl-get-range *xlapp* ExcelID)
    -4108
  ) ; Set the level of the middle
  (msxl-put-VerticalAlignment
    (msxl-get-range *xlapp* ExcelID)
    -4108
  ) ; Setting the vertical center
  (vlxls-Excel-cellfontname *xlapp* 1 1 "黑体") ;Set the font of cell
  (vlax-put-property
    (vlax-get-property (msxl-get-range *xlapp* "A2:D2") "font")
    "FontStyle"
    "Bold"
  ) ; Change the text in bold
  (vlxls-Excel-textsize *xlapp* 1 1 15) ; Change text size
  (vlxls-Excel-textcolor *xlapp* 1 1 18) ; Change Text color
  (repeat 4 ; Put the header row color settings 13
    (setq *No1* (1+ *No1*))
    (vlxls-Excel-textcolor *xlapp* 2 *No1* 10) ; Seting the color for "A2、B2、C2、D2" cells
    ;;(vlxls-Excel-fontstyle *xlapp* 2 *No1* "Bold") ; Change the text in bold
  )
  (repeat 4
    (setq RepNo1 (1+ RepNo1))
    (vlxls-Excel-ColumnWidth *xlapp* RepNo1 12) ; Adjust column widths
  )
  (vlxls-Excel-RowHeight *xlapp* 1 25) ;Setting hte height ot the first Row
  (repeat (+ Zbout_ssNum 2)
    (setq RepNo2 (1+ RepNo2)) ;Not the same as the first high-traffic, a separate set, so the initial value of RepNo2 begin 1
    (vlxls-Excel-RowHeight *xlapp* RepNo2 20) ; Adjust row height
  )
  (if (setq *Tmp* (findfile Zboutpath)) (vl-file-delete *Tmp*))
  (vlax-invoke-method
    (vlax-get-property *Xlapp* "ActiveWorkbook")
    "SaveAs"
    ZBOutpath
    msxl-xlNormal
    ""
    ""
    :vlax-False
    :vlax-False
    nil
  ) ;Save the file
  (vlax-release-object *xlapp*)
  (setq *xlapp* nil)
  (gc)
  ;;=============================================================
  (princ "\n ******  Procedures are completed! ******")
  (princ
    (strcat "\n ****** A total of " (itoa Zbout_N) "  sets of data output ******")
  )
  (vlr-beep-reaction)
  (alert (strcat "\nHave completed output the center coordinates of Circle, Please view!\n" ZBOutpath)
  )
) ;end prog
      ) ;end if
    ) ;end progn
    ;;else, If there is no choice, forced exit
    (vl-exit-with-error "\n*** no select any element ***")
  ) ;_ End if
  (setvar "cmdecho" 1)
  (princ)
)
(princ (strcat "\n Output the center coordinates of Circle to EXCEL Project."
       "\n Copyright(C) 2007-"
       (substr (rtos (getvar "cdate") 2 0) 1 4)
       "  by libin (小李子 MuziCAD 木子CAD). All rights reserved."
       )
)
(princ)

FengK

  • Guest
Judging by how the function vlxls-cell-put-value is defined and each number is converted into string as shown here:

Quote
(setq OutPutDLst (append
                OutPutDlst
                (list
             (list (itoa (setq Zbout_N (1+ Zbout_N)))
                   (rtos (cadr ZbOut_pt) 2 Coord_prec)
                   (rtos (car ZbOut_pt) 2 Coord_prec)
                   (rtos (caddr ZbOut_pt) 2 Coord_prec)
             )
                )
              )
       )

You're feeding those Excel cells string/text rather than numeric values and that explains why Excel treats those cells as "Text". How about using vlax-vbdouble instead of vlax-vbstring in your vlxls-cell-put-value function and in your main routine do not convert those numbers to strings?




« Last Edit: February 27, 2009, 12:38:39 AM by xycadd »

cjw

  • Guest
The VLxls function is too difficult.

Code: [Select]
;;Take a test! But also can't help you.

(defun C:TT (/ FILE FILE_NAME I PT SS)
  (defun CAI-SS-VALUES (SS ITEM / I VALUES)
    (repeat (setq I (sslength SS))
      (setq
VALUES
(cons
   (cdr (assoc ITEM (entget (ssname SS (setq I (1- I))))))
   VALUES
)
      )
    )
    VALUES
  )

  ;;Get the Center of circle and write into the CSV excel doc.
  ;;Open the CSV doc. with EXCEL
  (if (and (princ "\nSelect the circles")
   (setq SS (ssget '((0 . "CIRCLE"))))
   (setq FILE_NAME (getfiled "Save it"
     (if **FILE_NAME
       **FILE_NAME
       ""
     )
     "csv"
     1
   )
   )
   (setq **FILE_NAME FILE_NAME)
      )
    (progn
      (setq I 0)
      (setq FILE (open FILE_NAME "W"))
      (write-line "圆心坐标表(测量)" FILE)
      (write-line "序号,X坐标,Y坐标,Z坐标" FILE)
      (mapcar '(lambda (PT)
(write-line
   (strcat (strcat "ZK" (itoa (setq I (1+ I))))
   ","
   (rtos (nth 0 PT) 2 3)
   ","
   (rtos (nth 1 PT) 2 3)
   ","
   (rtos (nth 2 PT) 2 3)
   )
   FILE
)
       )
      (CAI-SS-VALUES SS 10)
      )
      (close FILE)
    )
  )
  (princ)
)
« Last Edit: February 26, 2009, 01:56:29 AM by cjw »

jxphklibin

  • Guest
Hi,xycadd

Thank you for your advice!

Now, I put this code be amended as follows:

However, still the same problem is still not resolved, do not believe you can try

Code: [Select]
(setq OutPutDLst (append
       OutPutDlst
       (list
(list (setq Zbout_N (1+ Zbout_N))
       (cadr ZbOut_pt)
       (car ZbOut_pt)
       (caddr ZbOut_pt)
)
       )
)
)






[/quote]

jxphklibin

  • Guest
The VLxls function is too difficult.

Code: [Select]
;;Take a test! But also can't help you.

(defun C:TT (/ FILE FILE_NAME I PT SS)
  (defun CAI-SS-VALUES (SS ITEM / I VALUES)
    (repeat (setq I (sslength SS))
      (setq
VALUES
(cons
   (cdr (assoc ITEM (entget (ssname SS (setq I (1- I))))))
   VALUES
)
      )
    )
    VALUES
  )

  ;;Get the Center of circle and write into the CSV excel doc.
  ;;Open the CSV doc. with EXCEL
  (if (and (princ "\nSelect the circles")
   (setq SS (ssget '((0 . "CIRCLE"))))
   (setq FILE_NAME (getfiled "Save it"
     (if **FILE_NAME
       **FILE_NAME
       ""
     )
     "csv"
     1
   )
   )
   (setq **FILE_NAME FILE_NAME)
      )
    (progn
      (setq I 0)
      (setq FILE (open FILE_NAME "W"))
      (write-line "圆心坐标表(测量)" FILE)
      (write-line "序号,X坐标,Y坐标,Z坐标" FILE)
      (mapcar '(lambda (PT)
(write-line
   (strcat (strcat "ZK" (itoa (setq I (1+ I))))
   ","
   (rtos (nth 0 PT) 2 3)
   ","
   (rtos (nth 1 PT) 2 3)
   ","
   (rtos (nth 2 PT) 2 3)
   )
   FILE
)
       )
      (CAI-SS-VALUES SS 10)
      )
      (close FILE)
    )
  )
  (princ)
)


I know, save it as a csv file is yes, but not the same as the format of the document.

Is it really would be no solution yet?

FengK

  • Guest
However, still the same problem is still not resolved, do not believe you can try

Did you also try changing vlax-vbString to vlax-vbDouble in your vlxls-cell-put-value function?

(setq ARY (vlax-make-safearray
      vlax-vbstring
      (cons 0 (1- (length Data)))
      (cons 1 (length (car Data)))
         )
     XX  (1- (length (car Data)))
     YY  (1- (length Data))
    )

(setq
      ARY (vlax-make-safearray
       vlax-vbstring
       (cons 0 1)
       (cons 1 (length Data))
     )
      XX  (1- (length Data))
      YY  0
    )

jxphklibin

  • Guest
However, still the same problem is still not resolved, do not believe you can try

Did you also try changing vlax-vbString to vlax-vbDouble in your vlxls-cell-put-value function?

(setq ARY (vlax-make-safearray
      vlax-vbstring
      (cons 0 (1- (length Data)))
      (cons 1 (length (car Data)))
         )
     XX  (1- (length (car Data)))
     YY  (1- (length Data))
    )

(setq
      ARY (vlax-make-safearray
       vlax-vbstring
       (cons 0 1)
       (cons 1 (length Data))
     )
      XX  (1- (length Data))
      YY  0
    )

I tried, but the error happened:

jxphklibin

  • Guest
Hi,xycadd:

Now I have found where the problem lies.

Changing vlax-vbString to vlax-vbDouble in your vlxls-cell-put-value function,and changing the structure of variables OutPutDLst,

It works Correctly!

xycadd,Ttanks you very much!

FengK

  • Guest
My pleasure. And welcome to TheSwamp.

jxphklibin

  • Guest
Hi,xycadd

Now, I have a question, that is, without changing the structure of OutPutDLst variables, how to modify the vlxls-cell-put-value function such as to meet in front of what I talking about?

;;=============================================

In other words, the structure of OutPutDLst variables such as:
Code: [Select]
      (list  '("圆心坐标表(测量)" "" "" "")
             '("序号" "X坐标" "Y坐标" "Z坐标")
             '("ZK1" "152.236" "562.362" "0.000")
             '("ZK2" "564.251" "4587.236" "0.000")
              ...
      )
And than,  just to change in vlxls-cell-put-value function:
Code: [Select]
(Defun vlxls-cell-put-value (xl id Data / vllist-explode idx xx yy ary Rtn)
  (Defun vllist-explode (lst)
    (cond
      ((not lst) nil)
      ((atom lst) (list lst))
      ((append (vllist-explode (car lst))
       (vllist-explode (cdr lst))
       )
      )
    )
  )
  (if (null id)
    (setq id "A1")
  )
  (if (= (type id) 'list)
    (setq id (vlxls-rangeid id))
  )
  (if (= (type (car Data)) 'LIST)
    (setq ARY (vlax-make-safearray
vlax-vbstring
(cons 0 (1- (length Data)))
(cons 1 (length (car Data)))
      )
  XX  (1- (length (car Data)))
  YY  (1- (length Data))
    )
    (setq
      ARY (vlax-make-safearray
    vlax-vbstring
    (cons 0 1)
    (cons 1 (length Data))
  )
      XX  (1- (length Data))
      YY  0
    )
  )
  (if (= xx yy 0)
    (MSXL-PUT-VALUE2
      (setq Rtn (msxl-get-range xl id))
      (car (vllist-explode data))
    )
    (progn
      (setq id (vlxls-cellid-calc id xx yy))
      (MSXL-PUT-VALUE2
(setq Rtn (msxl-get-range xl id))
(vlax-safearray-fill ary data)
      )
    )
  )
  Rtn
)

To deal with the text-strings and the text-figure.
How can we do that?

FengK

  • Guest
Now, I have a question, that is, without changing the structure of OutPutDLst variables

May i ask why do you want to keep the data in OutPutDLst as string? But to answer your question, I think you need to fill the range three times, i.e., call the vlxls-cell-put-value function three times: 1st time to fill the A1:D2 range with the row header info (shoud be list (car OutPutDLst) (cadr OutPutDLst)), using vlax-vbString in vlax-make-safearray function; 2nd time to fill the A3:An+2 range, where n is the number of points, with point IDs ZK1, ZK2 ,etc. (should be (mapcar 'car (caddr OutPutDLst))), use vlax-vbString in vlax-make-safearray function as well; 3rd time to fill the B3:Dn+2 range with those coordinates (should be (mapcar 'cdr (caddr OutPutDLst))) and use vlax-vbDouble in vlax-make-safearray function this time. Hope this helps.

jxphklibin

  • Guest
Now, I have a question, that is, without changing the structure of OutPutDLst variables

May i ask why do you want to keep the data in OutPutDLst as string? But to answer your question, I think you need to fill the range three times, i.e., call the vlxls-cell-put-value function three times: 1st time to fill the A1:D2 range with the row header info (shoud be list (car OutPutDLst) (cadr OutPutDLst)), using vlax-vbString in vlax-make-safearray function; 2nd time to fill the A3:An+2 range, where n is the number of points, with point IDs ZK1, ZK2 ,etc. (should be (mapcar 'car (caddr OutPutDLst))), use vlax-vbString in vlax-make-safearray function as well; 3rd time to fill the B3:Dn+2 range with those coordinates (should be (mapcar 'cdr (caddr OutPutDLst))) and use vlax-vbDouble in vlax-make-safearray function this time. Hope this helps.


Yes, I also began to do so, but Some times (mapcar 'car (caddr OutPutDLst))), that is ZK1, ZK2 ,etc. is no prefix "ZK", so I modified the codes as follows,I do not know whether it has properly:

Code: [Select]
(defun c:Getcen2Excel (/    Zbout_ss    Zbout_N    Zbout_ssNum
       RepNo1    RepNo2      *No1*    Coord_prec
       ZBOutpath   ExcelID     OutPutDLst  ent_name
       ent_data    Zbout_pt    *xlapp*    *Tmp*
       Prefix Tableheader SerNumLst
      )
  (setvar "cmdecho" 0)
  ;;(vl-load-com)
  ;;(LOAD "vlxls.lsp") ;Call a function library file which is to operate excel
  (princ
    "\nplease select the circle so to output its center coordinates: "
  ) ;Please select the circle so to output the coordinates of its center
  (if (setq Zbout_ss (ssget '((0 . "circle"))))
    (progn
      (setq Zbout_N 0
    Prefix "" ;"ZK"
    Zbout_ssNum (sslength Zbout_ss)
    RepNo1 0
    RepNo2 1
    *No1* 0
    Coord_prec 3
      )
      (if (setq ZBOutpath (ZbOut_getfile))
(progn
  (princ "正在输出到EXCEL,请不要进行其它操作......")
  (if Prefix ; 这个or 条件有问题(or (/= Prefix "") (/= Prefix nil))
    ;;(if (/= Prefix "")
      (progn
(setq ExcelID   (strcat "B3:D" (itoa (+ Zbout_ssNum 2)))
      ;;ExcelID (strcat "A1:D" (itoa (+ Zbout_ssNum 2)))
      ;;OutPutDLst (list '("圆心坐标表(测量)" "" "" "") '("序号" "X坐标" "Y坐标" "Z坐标"))
      Tableheader (list '("圆心坐标表(测量)" "" "" "")
'("序号" "X坐标" "Y坐标" "Z坐标")
  )
)
(repeat Zbout_ssNum
  (setq ent_name   (ssname Zbout_ss Zbout_N)
ent_data   (entget ent_name)
Zbout_pt   (cdr (assoc 10 ent_data))
SerNumLst  (append
     SerNumLst
     (list
       (strcat Prefix (itoa (setq Zbout_N (1+ Zbout_N))))
     )
   )
OutPutDLst (append
     OutPutDlst
     (list
       (list ;;(if (or (/= Prefix "") (/= Prefix nil))
     ;;  (strcat Prefix (itoa (setq Zbout_N (1+ Zbout_N))))
     ;;  (itoa (setq Zbout_N (1+ Zbout_N)))
     ;;)
     ;;(itoa (setq Zbout_N (1+ Zbout_N)))
     (rtos (cadr ZbOut_pt) 2 Coord_prec)
     (rtos (car ZbOut_pt) 2 Coord_prec)
     (rtos (caddr ZbOut_pt) 2 Coord_prec)
       )
     )
   )
  )
)
      )
      ;; else Prefix is nil or ""(空或全为空格)
      (progn
(setq ExcelID   (strcat "A3:D" (itoa (+ Zbout_ssNum 2)))
      Tableheader (list '("圆心坐标表(测量)" "" "" "")
'("序号" "X坐标" "Y坐标" "Z坐标")
  )
)
(repeat Zbout_ssNum
  (setq ent_name   (ssname Zbout_ss Zbout_N)
ent_data   (entget ent_name)
Zbout_pt   (cdr (assoc 10 ent_data))
OutPutDLst (append
     OutPutDlst
     (list
       (list (itoa (setq Zbout_N (1+ Zbout_N)))
     (rtos (cadr ZbOut_pt) 2 Coord_prec)
     (rtos (car ZbOut_pt) 2 Coord_prec)
     (rtos (caddr ZbOut_pt) 2 Coord_prec)
       )
     )
   )
  )
)
      )
    ;;)
    ;; else Prefix is nil
    ;;()
  )
  (setq *xlapp* (vlxls-app-new t))
  ;;(vlxls-put-row-value *xlapp* "A1:D1" (list "圆心坐标表(测量)" "" "" ""))
  ;;(vlxls-put-row-value *xlapp* "A2:D2" (list "序号" "X坐标" "Y坐标" "Z坐标"))
  (msxl-put-HorizontalAlignment (vlxls-cell-put-value-str *xlapp* "A1:D2" Tableheader) -4108)
  (if SerNumLst ;(or (/= Prefix "") (/= Prefix nil))
    (msxl-put-HorizontalAlignment (vlxls-put-column-value *xlapp* "A3" SerNumLst) -4108)
  )
  (vlxls-cell-put-value-num *xlapp* ExcelID OutPutDLst) ; Output to Excel spreadsheet
  (vlxls-cell-merge *xlapp* "A1:D1") ; Merge Cells
  (msxl-put-HorizontalAlignment (msxl-get-range *xlapp* ExcelID) -4108) ; Set the level of the middle
  ;;(msxl-put-VerticalAlignment (msxl-get-range *xlapp* ExcelID) -4108) ; Setting the vertical center,The default is the vertical center, so here is no need for setting
  (vlxls-Excel-cellfontname *xlapp* 1 1 "黑体") ;Set the font of cell
  (vlax-put-property (vlax-get-property (msxl-get-range *xlapp* "A2:D2") "font") "FontStyle" "Bold"); Change the text in bold
  (vlxls-Excel-textsize *xlapp* 1 1 15) ; Change text size
  (vlxls-Excel-textcolor *xlapp* 1 1 18) ; Change Text color
  (repeat 4 ; Put the header row color settings 13
    (setq *No1* (1+ *No1*))
    (vlxls-Excel-textcolor *xlapp* 2 *No1* 10) ; Seting the color for "A2、B2、C2、D2" cells
    ;;(vlxls-Excel-fontstyle *xlapp* 2 *No1* "Bold") ; Change the text in bold
  )
  (repeat 4
    (setq RepNo1 (1+ RepNo1))
    (vlxls-Excel-ColumnWidth *xlapp* RepNo1 12) ; Adjust column widths
  )
  (vlxls-Excel-RowHeight *xlapp* 1 25) ;Setting hte height ot the first Row
  (repeat (+ Zbout_ssNum 2)
    (setq RepNo2 (1+ RepNo2)) ;Not the same as the first high-traffic, a separate set, so the initial value of RepNo2 begin 1
    (vlxls-Excel-RowHeight *xlapp* RepNo2 20) ; Adjust row height
  )
  (if (setq *Tmp* (findfile Zboutpath))
    (vl-file-delete *Tmp*)
  )
  (vlax-invoke-method (vlax-get-property *Xlapp* "ActiveWorkbook") "SaveAs" ZBOutpath msxl-xlNormal "" "" :vlax-False :vlax-False nil);Save the file
  (vlax-release-object *xlapp*)
  (setq *xlapp* nil)
  (gc)
  ;;=============================================================
  (princ "\n ******  Procedures are completed! ******")
  (princ
    (strcat "\n ****** A total of "
    (itoa Zbout_N)
    "  sets of data output ******"
    )
  )
  (vlr-beep-reaction)
  (alert
    (strcat
      "\nHave completed output the center coordinates of Circle, Please view!\n"
      ZBOutpath
    )
  )
) ;end prog
      ) ;end if
    ) ;end progn
    ;;else, If there is no choice, forced exit
    (vl-exit-with-error "\n*** no select any element ***")
  ) ;_ End if
  (setvar "cmdecho" 1)
  (princ)
)

jxphklibin

  • Guest
Now, I used another method, Only use this function, it can be very simple to solve my problem, the text figures can be automatically converted to the pure digital format, without changing the structure of OutPutDLst variables. Of course, there was no need to modify the vlxls-cell-put-value function, this function has no use.

The following is my code:
Code: [Select]
(defun Vlxls-Put-RowList (xlapp startrow startcol lst / sheet)
  (setq sheet (vlax-get-property xlapp "ActiveSheet"))
  (foreach itm lst
    (msxl-put-value2
      (vlxls-get-cell sheet startrow startcol)
      itm
    )
    (setq startcol (1+ startcol))
  )
)

(foreach item OutPutDlst (Vlxls-Put-RowList *xlapp* (1+ (vl-position  item outputdlst)) 1 item))

The code below and above the effect of equivalent:

(repeat   (length OutPutDlst)
  (setq   col  0
   item (nth *Tmp* OutPutDlst)
  )
    (Vlxls-Put-RowList *xlapp* (setq *Tmp* (1+ *Tmp*)) 1 item)
)