刚注册账号,发一个做表格的小程序,还不完善,用来纪念一下。
想做一个文字统计的程序,目前只做出一个表格,想知道怎么把文字统计出来,可以按顺序排列名称然后统计数量。表格中 row_ori (list 5 5 15 15 15 20 5)中的数字为表格每个横向单元的宽度,修改可以改变表格,行高设置为 col_L 4
觉得我编的有点用的可以拿去,主要还是求大神指导一下。
; =============================================
; | 表格自动生成软件 |
; | 板本: V1.1 作者: 尉迟俊岭 |
; =============================================
(defun C:bg(/ rows colu rows1 rows2 ly lx i ii propt colu1 co coo
dx dy dxx dyy str with ptp1 ptp2 ptp3 ptp4 os)
(setvar "CMDECHO" 0)
(setq lay (getvar "clayer"))
(setq os (getvar "OSMODE"))
(setvar "OSMODE" 0)
(command "color" "bylayer")
(command "layer" "m" "bg" "c" "y" "bg" "")
(initget 7)
(setq rows (getint "\n表格总行数: "))
(initget 7)
(setq colu (getint "\n表格总列数: "))
(initget 7)
(setq rows1 (getreal "\n表格第一行行距: "))
(initget 7)
(setq rows2 (getreal "\n表格其它行行距: "))
(setq ly (+ rows1 (* rows2 (1- rows))))
(setq lx 0)
(setq i 1)
(repeat colu
(initget 7)
(setq ii (itoa i))
(setq propt (strcat "表格第" ii "列列距: "))
(setq colu1 (getreal propt))
(setq lx (+ lx colu1))
(if (= 1 i) (setq co (list colu1))
(progn
(setq coo (list colu1))
(setq co (append cocoo))
)
)
(setq i (1+ i))
)
(setq pt1 (getpoint "\n表格左上角点: "))
(setq ptp1 pt1)
(setq dy (cadr pt1))
(setq dx (car pt1))
(setq dxx (+ dx lx))
(setq pt2 (list dxx dy))
(command "line" pt1 pt2 "")
(setq dy (- dy rows1))
(setq pt1 (list dx dy))
(setq pt2 (list dxx dy))
(command "line" pt1 pt2 "")
(repeat (1- rows)
(setq dy (- dy rows2))
(setq pt1 (list dx dy))
(setq pt2 (list dxx dy))
(command "line" pt1 pt2 "")
)
(setq dyy (+ dy ly))
(setq pt2 (list dx dyy))
(command "line" pt1 pt2 "")
(setq i 0)
(repeat colu
(setq c (nth i co))
(setq dx (+ dx c))
(setq pt1 (list dx dy))
(setq pt2 (list dx dyy))
(command "line" pt1 pt2 "")
(setq i (1+ i))
)
(initget "Yes No")
(setq str (getkword "\n表格边框是否加粗: 不加粗:No / <加粗:Yes> "))
(if (or (= str nil) (= (strcase str) "YES"))
(progn
(initget 6)
(setq with (getreal "\n表格边框线宽<0.6>: "))
(if (= with nil) (setq with 0.6))
(setq dy (cadr ptp1))
(setq dx (car ptp1))
(setq dxx (+ dx lx))
(setq ptp2 (list dxx dy))
(setq dyy (- dy ly))
(setq ptp3 (list dxx dyy))
(setq ptp4 (list dx dyy))
(command "PLINE" ptp1 "w" with with ptp2 ptp3 ptp4 "c")
)
)
(setvar "OSMODE" os)
(command "layer" "s" lay "")
(princ)(princ)
)
这是我下载的一个绘制表格软件,供您参考,可惜表格插入点不是左下角 (defun c:dt(/ old_osm old_clayer old_cmdecho
col_L row_ori row_L N
pt_00 pt_0n i pt_i0 pt_in rev_lst
row_len pt_0j pt_nj)
(vl-load-com)
(setq old_osm (getvar "osmode")
old_clayer (getvar "clayer")
old_cmdecho (getvar "cmdecho"))
(setvar "clayer" "0")
(setvar "osmode" 0)
(setvar "cmdecho" 0)
(setq col_L 4
row_ori (list 5 5 15 15 15 20 5)
row_L (apply '+ row_ori)
N (getreal "\n指定列数<以后用其他程序引用>:"))
(setq pt_00 (getpoint "\n指定表格插入点:"))
(setq pt_0n (list (+ (car pt_00) row_L) (cadr pt_00) 0))
(vl-cmdf "line" pt_00pt_0n "")
(setq i 1)
(while (<= i N)
(setq pt_i0 (list (car pt_00) (- (cadr pt_00) (* col_L i)) 0))
(setq pt_in (list (+ (car pt_00) row_L) (- (cadr pt_00) (* col_L i)) 0))
(vl-cmdf "line" pt_i0 pt_in "")
(setq i (+ i 1)))
(setq rev_lst (reverse row_ori))
(repeat (+ (length row_ori) 1)
(setq row_len (apply '+ rev_lst))
(setq pt_0j (list (+ (car pt_00) row_len) (cadr pt_00) 0)
pt_nj (list (car pt_0j) (- (cadr pt_0j) (* col_L N)) 0))
(vl-cmdf "line" pt_0j pt_nj "")
(setq rev_lst (cdr rev_lst)))
(setvar "osmode" old_osm)
(setvar "clayer" old_clayer)
(setvar "cmdecho" old_cmdecho)
(princ)) 按要求写了一段代码,但是这个表格比较中规中矩,由于行高列宽是自己定义的,不如用文字自高来限定方便,所以
一开始你可能自己也不清楚行高和列宽定为多少合适,在这里就简单写了一下,真正具体问题,就具体对待了,这里
提供一个画表格的思路,如果有好的思路,可以互相交流。
(defun c:dt(/ row col h v pt0 pt1 pt2 osm m n)
(setq row (getint "\n请输入行数:")
col (getint "\n请输入列数:")
h (getreal "\n请输入行高:")
v (getreal "\n请输入列宽:"))
(defun dr_hl(pt len);;根据距离画水平线
(entmake (list '(0 . "Line")(cons 10 pt)(cons 11 (list (+ (car pt) len) (cadr pt) 0) ))))
(defun dr_vl(pt len);;根据距离画水平线
(entmake (list '(0 . "Line")(cons 10 pt)(cons 11 (list (car pt) (- (cadr pt) len) 0) ))))
(setq pt0 (getpoint "\n指定表格左上角点:"))
(setq osm (getvar "osmode"))
(if (< 0 osm 16384)
(setq osm (+ osm 16384)))
(dr_hl pt0 (* col v));;画第一条横线
(dr_vl pt0 (* row h));;画第一条竖线
(setq m 1 n 1)
(repeat row
(setq pt1 (list (car pt0) (- (cadr pt0) (* m h)) 0))
(dr_hl pt1 (* col v))
(setq m (1+ m)))
(repeat col
(setq pt2 (list (+ (car pt0) (* n v)) (cadr pt0) 0))
(dr_vl pt2 (* row h))
(setq n (1+ n)))
(setvar "osmode" osm)
(princ))
谢谢分享啊 烟盒迷唇 发表于 2019-7-2 11:05
谢谢分享啊
大佬明显觉得很简单,还是支持了我一下,谢谢了 多谢楼主分享。要是能直接在命令行输入列数、行数、列宽、行宽就更方便了 sunny_8848 发表于 2019-10-26 17:18
多谢楼主分享。要是能直接在命令行输入列数、行数、列宽、行宽就更方便了
可以,有时候编写东西就需要看别人有啥需求,不然都没有思路,我有时间再写一个贴这里 本帖最后由 sunny_8848 于 2019-10-27 10:08 编辑
WWYYBB1015 发表于 2019-10-26 22:14
按要求写了一段代码,但是这个表格比较中规中矩,由于行高列宽是自己定义的,不如用文字自高来限定方便,所 ...
非常感谢,这么晚了还在写代码。能帮忙改成指定表格左下角点吗,昨晚弄了很久实在不会改.我们一般制作明细表是这样的步骤:指定行数,列数。指定第一行表头行高,指定第二行高,第三行起的行高和第二行等高;分别指定各列的列宽(各列一般不等宽)。表格插入点在左下角
sunny_8848 发表于 2019-10-27 09:47
非常感谢,这么晚了还在写代码。能帮忙改成指定表格左下角点吗,昨晚弄了很久实在不会改.我们一般制作明 ...
如果你的表每次都是固定格式的列宽,可以把这个列宽的形式告诉我
像 (a,b,c,d,e,f)这种形式,a,b,c,d,e,f...表示列宽
页:
[1]
2