@bit_Cad2018 As I promised, here is my final solution.
After window selection it asks user to select name of output csv file and it opens it in Excel.
There record can be checked and finaly saved to desired file format and with final name.
For multiple sheets you can always overwrite single csv file, or keep them if your like.
(defun c:sef nil (sef))
(defun sef ( / data data1 data2 data3 p1 p2 ss i n ent dist cont e xcords a b c str f file1 path)
(setq p1 (getpoint "\nSelect first window point (down left) >"))
(setq p2 (getcorner p1 "\nSelect second window point (up right) >"))
(setq f (getfiled "Output csv:" (getvar "dwgprefix") "csv" 3))
(setq path f)
(setq file1 (open f "w"))
(setq ss (ssget "_W" p1 p2 '((0 . "TEXT"))))
(setq i -1 n (sslength ss))
(while (< (setq i (+ i 1)) n)
(setq ent (entget (ssname ss i)))
(setq dist (cadr (assoc 11 ent)))
(setq cont (cdr (assoc 1 ent)))
(setq data (cons (cons dist cont) data))
)
(setq i -1 )
(while (< (setq i (+ i 1)) n)
(setq e (nth i data))
(cond
((and (vl-string-position (ascii "+") (cdr e)) (vl-string-position (ascii ".") (cdr e))(< (strlen (cdr e)) 12 )) (setq data1 (cons e data1)))
((and (not(vl-string-position (ascii "+") (cdr e))) (< (strlen (cdr e)) 12 )) (setq data2 (cons e data2)))
((> (strlen (cdr e)) 12 ) (setq data3 (cons e data3)))
)
)
(setq data1 (vl-sort data1 '(lambda (a b) (< (car a)(car b)))))
(setq data2 (vl-sort data2 '(lambda (a b) (< (car a)(car b)))))
(setq data3 (vl-sort data3 '(lambda (a b) (< (car a)(car b)))))
(setq xcords (mapcar 'car data1))
(write-line "REQUIRED LIST;" file1)
(write-line (strcat "GROUND LEVELS(IN METRES)" ";" "CUMULATIVE CHAINAGE (KM METRES)(000 + 000)" ";" "CROSSING" ";" "TP" ";") file1)
(foreach x xcords
(setq del1 (- x 6) del2 (+ x 6) a nil b nil c nil)
(foreach entry data1 (if (and(> (car entry) del1)(< (car entry) del2)) (setq a entry)))
(foreach entry data2 (if (and(> (car entry) del1)(< (car entry) del2)) (setq b entry)))
(foreach entry data3 (if (and(> (car entry) del1)(< (car entry) del2)) (setq c entry)))
(if a (setq a (cdr a)))
(if b (setq b (cdr b)))
(if c (setq c (cdr c)))
(setq str "")
(if a (setq str (strcat str a ";")))
(if b (setq str (strcat str b ";")))
(if c (setq str (strcat str c ";")))
(write-line str file1)
)
(close file1)
(startapp "explorer" path)
(princ)
)
Now you have solution by @pbejse and my own sou you can use which better suites you.
If you need som changes now, just reply to this post.
Miljenko Hatlak

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.