(defun out_put (/	 rep	  ent	   replst   entlst   entn
		mxb_count	  all_set  k	    dir	     fn
		ent_rep	 ent_qty  ent_chin ent_desc ent_mat  ent_cot
		ent_obv	 qty	  chin	   desc	    mat	     cot
		obv
	       )
  (load "ai_utils")
  (setq all_set (ssget "X" '((0 . "INSERT") (2 . "MXB_TAB_L"))))
  (if all_set
    (progn
      (setq mxb_count (sslength all_set))
      (setq k 0)
      (while (< k mxb_count)
	(setq entn (ssname all_set k))
	(setq rep (cdr (assoc 1 (entget (entnext entn)))))
	(setq ent (cdr (assoc 5 (entget entn))))
	(maklst rep ent)
	(setq k (+ k 1))
      )
      (setq fn (open "c:\\acadlxy.TMP" "w"))
      (write-line (get_mold_num) fn)
      (setq ent_count (length entlst))
      (setq k 0)
      (while (< k ent_count)
	(setq ent (handent (nth k entlst)))
	(setq ent_rep  (entnext ent)
	      ent_qty  (entnext ent_rep)
	      ent_chin (entnext ent_qty)
	      ent_desc (entnext ent_chin)
	      ent_mat  (entnext ent_desc)
	      ent_cot  (entnext ent_mat)
	      ent_obv  (entnext ent_cot)
	)
	(setq rep  (cdr (assoc '1 (entget ent_rep)))
	      qty  (cdr (assoc '1 (entget ent_qty)))
	      chin (cdr (assoc '1 (entget ent_chin)))
	      desc (cdr (assoc '1 (entget ent_desc)))
	      mat  (cdr (assoc '1 (entget ent_mat)))
	      cot  (cdr (assoc '1 (entget ent_cot)))
	      obv  (cdr (assoc '1 (entget ent_obv)))
	)
	(progn
	  (if (= "" qty)
	    (setq qty " ")
	  )
	  (if (= "" chin)
	    (setq chin " ")
	  )
	  (if (= "" desc)
	    (setq desc " ")
	  )
	  (if (= "" mat)
	    (setq mat " ")
	  )
	  (if (= "" cot)
	    (setq cot " ")
	  )
	  (if (= "" obv)
	    (setq obv " ")
	  )
	)
	(progn
	  (write-line rep fn)
	
	  (write-line qty fn)
	
	  (write-line chin fn)

	  (write-line desc fn)

	  (write-line mat fn)

	  (write-line cot fn)

	  (write-line obv fn)
	)
	(setq k (+ k 1))
      )
      (close fn)
     (startapp "DataToExcel.exe")
    )
    (alert "未发现明细表数据!")
  )
  (prin1)
)


(defun maklst (item1 item2 / i lst_count reptmp enttmp)
  (setq item1 (ai_strtrim item1))
  (setq item2 (ai_strtrim item2))
  (if (and (= 1 (strlen item1))
	   (and (<= 49 (ascii item1)) (>= 57 (ascii item1)))
      )
    (setq item1 (strcat " " item1))
  )
  (if replst
    (progn
      (setq lst_count (length replst)
	    i	      0
      )
      (while (< i lst_count)
	(if (< item1 (nth i replst))
	  (progn
	    (if	(not reptmp)
	      (progn
		(setq reptmp (list item1))
		(setq enttmp (list item2))
	      )
	      (progn
		(setq reptmp (append reptmp (list item1)))
		(setq enttmp (append enttmp (list item2)))
	      )
	    )
	    (progn
	      (setq
		reptmp (append reptmp (member (nth i replst) replst))
	      )
	      (setq
		enttmp (append enttmp (member (nth i entlst) entlst))
	      )
	      (setq i lst_count)
	    )
	  )
	  (progn
	    (if	reptmp
	      (setq reptmp (append reptmp (list (nth i replst)))
		    enttmp (append enttmp (list (nth i entlst)))
	      )
	      (setq reptmp (list (nth i replst))
		    enttmp (list (nth i entlst))
	      )
	    )
	    (if	(= (- lst_count 1) i)
	      (setq reptmp (append reptmp (list item1))
		    enttmp (append enttmp (list item2))
	      )
	    )
	    (setq i (+ i 1))
	  )
	)
      )
      (setq replst reptmp)
      (setq entlst enttmp)
    )
    (setq replst (list item1)
	  entlst (list item2)
    )
  )
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;insert lisp****ok(输出模号）
(defun get_mold_num (/ ent_btl ent_num) ;;;;;;;;;;
  (setq mold_num " ")
  (setq ent_btl (ssget "x" '((0 . "INSERT") (2 . "BTL_BTL"))))
  (if ent_btl
    (progn
      (setq ent_num (ssname ent_btl 0))
      (setq mold_num (cdr (assoc 1
				 (entget
				   (entnext
				     (entnext
				       (entnext
					 (entnext
					   (entnext ent_num)
					 )
				       )
				     )
				   )
				 )
			  )
		     )
      )
    )
  )
  mold_num
)