lisp创建一种既支持offece又要兼容所有浏览器的表格文件
没有安装office的电脑上是否可以打开xls文件?答案是肯定的,一起见证下面这段代码带来的奇迹吧(defun $make-xls&web-table$(data-jz save-f lst /
$<col/>$ $<th>$ $<td>$ str
*error* f $pin-jie$
$yi-dui-shu-zi$
)
(defun *error* (err)
(if(wcmatch (strcase err t) "*break,*cancel*,*exit*,*取消*")
(PROGN
(princ "\n用户按了<Esc>强制退出")
)
(princ (strcat "\n<" err ">\n"))
)
(and f (close f))
(print "error in c:web line 777: ")
(princ)
)
(defun $yi-dui-shu-zi$ (len / ss i)
;返回从数字0开始的一堆list数据
(if(and len (= (type len) 'int))
(progn
(setq ss nil)
(setq i 0)
(while (< i len) (setq ss (cons i ss)) (setq i (1+ i)))
(setq ss (reverse ss))
)
)
ss
)
(defun $pin-jie$ (strlst bar / str len bars str-last)
(if(and strlst
bar
(= (type strlst) 'list)
(setq strlst (vl-remove nil strlst))
(= (type (CAR strlst)) 'STR)
(= (type bar) 'str)
)
(progn
(setq str-last (last strlst))
(setq str-bar
(mapcar
(function (lambda (a)
(or (and a (= (type a) 'str)) (setq a ""))
(strcat a bar)
)
)
(reverse (cdr (reverse strlst)))
)
)
(setq str (apply 'strcat str-bar))
(setq str (strcat str str-last))
)
)
str
)
(defun $<col/>$ (head / col)
(setq col "<colgroup>")
(mapcar (function (lambda (a)
(set 'col (strcat col "<col/>"))
)
)
($yi-dui-shu-zi$ (length head))
)
(setq col (strcat col "<colgroup>"))
)
(defun $<th>$(head)
(strcat "<tr>"
"<th>"
($pin-jie$ head "</th><th>")
"</th>"
"<tr>"
)
)
(defun $<td>$(data)
(mapcar (function (lambda (a)
(strcat"<tr>"
"<td>"
($pin-jie$ a "</td><td>")
"</td>"
"<tr>"
)
)
)
data
)
)
(if (and data-jz
(= (type data-jz) 'list)
(= (type (car data-jz)) 'list)
(= (type (car (car data-jz))) 'str)
)
(progn
(if (findfile save-f)
(vl-file-delete save-f)
)
(setq f (open save-f "a"))
(write-line
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=GB2312\" />
<head>
<style>body{white-space:nowrap} table,td,th{border-collapse:collapse;border:1px solid #000000;text-align:center}</style>
</head><body>
<table>"
f
)
(write-line ($<col/>$ (car data-jz)) f)
(write-line ($<th>$ (car data-jz)) f)
(mapcar (function (lambda (a) (write-line a f)))
($<td>$ (cdr data-jz))
)
(write-line
"</table>
</body></html>"
f
)
(and f (close f))
(startapp "explorer" save-f)
)
)
str
)
;调用示例
(setq jz '(("块名""线号" "线种""线径" "UL线径"
"颜色""位置" "孔位""剥皮" "导线备注"
"对应簧片""级联" "防水栓""范围" "辅助"
"E1""L" "E2""短路线号""左端线号"
"右端线号""搭接" "加余量""绝缘" "绝缘长度"
"选项""组号" "序号""名称" "功能"
"编码""供应商" "供方编码""规格" "开口"
"数量""长" "类别""外径" "内径"
"工位""客户线号""备注""单位" "自带线"
"宽度""标识管内容" "剪短尺寸""回折"
"回折长""外被剥皮""父级辅助""外被颜色""父编码"
"标识管编码" "印字内容""字体规格""标记色"
"绞距""分叉" "英文功能""额定电流""角度"
"产品编码""线束名称""线束编号""项目" "项目代号"
"车型""版本"
)
("连接器" "" """" "" "" "P01"
"" "" "" """" "" "" ""
"" "" "" """" "" "" ""
"" "" "V1/V5""" "" "插座护套"
"接一号背门线束2" "NS06MW/bss""" "NS06MW"
"" "" "1" """" "" "" ""
"" "" "" """" "" "" ""
"" "" "" """" "" "" ""
"" "" "" """" "" "" ""
"" "" "" """"
)
("连接器""" "" "" """" "P02" "" ""
"" """" "" "" """" "" "" ""
"" """" "" "" """ALL" "" ""
"插座护套""接后除霜正极" "PP0311701" "" "0311701"
"" """1" "" "" """" "" "" ""
"" """" "" "" """" "" "" ""
"" """" "" "" """" "" "" ""
"" """" "" "" """"
)
("连接器""" "" "" """" "P09" "" ""
"" """" "" "" """" "" "" ""
"" """" "" "" """ALL" "" ""
"插座护套""接后除霜正极" "PP0311701" "" "0311701"
"" """1" "" "" """" "" "" ""
"" """" "" "" """" "" "" ""
"" """" "" "" """" "" "" ""
"" """" "" "" """"
)
("连接器""" "" "" """" "P03" "" ""
"" """" "" "" """" "" "" ""
"" """" "" "" """ALL" "" ""
"插座护套""接左牌照灯" "CN-2BHX" "" "CN-2BHX"
"" """1" "" "" """" "" "" ""
"" """" "" "" """" "" "" ""
"" """" "" "" """" "" "" ""
"" """" "" "" """"
)
("连接器""" "" "" """" "P06" "" ""
"" """" "" "" """" "" "" ""
"" """" "" "" """ALL" "" ""
"插座护套""接左牌照灯" "CN-2BHX" "" "CN-2BHX"
"" """1" "" "" """" "" "" ""
"" """" "" "" """" "" "" ""
"" """" "" "" """" "" "" ""
"" """" "" "" """"
)
("连接器""" "" "" """" "P05" "" ""
"" """" "" "" """" "" "" ""
"" """" "" "" """ALL" "" ""
"插座护套""接背门闭锁器" "TS03FW" "" "TS03FW"
"" """1" "" "" """" "" "" ""
"" """" "" "" """" "" "" ""
"" """" "" "" """" "" "" ""
"" """" "" "" """"
)
("连接器""" "" "" """" "P08" "" ""
"" """" "" "" """" "" "" ""
"" """" "" "" """ALL" "" ""
"插座护套""接倒车灯""PP0413903""" "0413903" ""
"" "1""" "" "" """" "" "" ""
"" """" "" "" """" "" "" ""
"" """" "" "" """" "" "" ""
"" """" "" "" ""
)
("连接器""" "" "" """" "P07" "" ""
"" """" "" "" """" "" "" ""
"" """" "" "" """ALL" "" ""
"插座护套""接后雨刮电机" "PP0427201" "" "0427201"
"" """1" "" "" """" "" "" ""
"" """" "" "" """" "" "" ""
"" """" "" "" """" "" "" ""
"" """" "" "" """"
)
("连接器""" "" "" """" "P04" "" ""
"" """" "" "" """" "" "" ""
"" """" "" "" """ALL" "" ""
"插座护套""倒车摄像头" "917319-4""" "917319-4"
"" """1" "" "" """" "" "" ""
"" """" "" "" """" "" "" ""
"" """" "" "" """" "" "" ""
"" """" "" "" """"
)
("连接器""" "" "" """" "P10" "" ""
"" """" "" "" """" "" "" ""
"" """" "" "" """ALL" "" ""
"插座护套""接一号背门线束""TK08MW" "" "TK08MW"
"" """1" "" "" """" "" "" ""
"" """" "" "" """" "" "" ""
"" """" "" "" """" "" "" ""
"" """" "" "" """"
)
("电线7" "DF01""AVSS" "2.00" "" "Lg" "P01"
"1" "剥皮" """" "" "" "" "" "" "" ""
"" "" "" """" "" "" "V1/V2" "" "" ""
"" "" "" """" "" "" "" "" "" "" ""
"" "" "" """" "" "" "" "" "" "" ""
"" "" "" """" "" "" "" "" "" "" ""
"" "" "" """"
)
("电线7" "DF02""AVSS" "2.0" "" "B""P01"
"2" "剥皮" """" "" "" "" "" "" "" ""
"" "" "" """" "" "" "V4" "" "" "" ""
"" "" "" """" "" "" "" "" "" "" ""
"" "" "" """" "" "" "" "" "" "" ""
"" "" "" """" "" "" "" "" "" "" ""
"" "" "" ""
)
("电线7" "RW05""AVSS" "1.25" "" "W/B" "P01"
"3" "剥皮" """" "" "" "" "" "" "" ""
"" "" "" """" "" "" "ALL" "" "" ""
"" "" "" """" "" "" "" "" "" "" ""
"" "" "" """" "" "" "" "" "" "" ""
"" "" "" """" "" "" "" "" "" "" ""
"" "" "" """"
)
("电线7" "RW06""AVSS" "1.25" "" "B""P01"
"4" "剥皮" """" "" "" "" "" "" "" ""
"" "" "" """" "" "" "ALL" "" "" ""
"" "" "" """" "" "" "" "" "" "" ""
"" "" "" """" "" "" "" "" "" "" ""
"" "" "" """" "" "" "" "" "" "" ""
"" "" "" """"
)
("电线7" "RW04""AVSS" "1.25" "" "Bl" "P01"
"5" "剥皮" """" "" "" "" "" "" "" ""
"" "" "" """" "" "" "ALL" "" "" ""
"" "" "" """" "" "" "" "" "" "" ""
"" "" "" """" "" "" "" "" "" "" ""
"" "" "" """" "" "" "" "" "" "" ""
"" "" "" """"
)
)
)
($make-xls&web-table$ jz(strcat (vl-filename-mktemp "神奇" (getvar 'dwgprefix)) ".html")nil)
(alert "文件创建完成了,你可以双击该文件,默认浏览器打开,您也可以右键用office打开,默认是xls文件\n\n见证奇迹吧!")
在我电脑上测试,网页版打开很完美。
Excel打开,可能是我用了精简版的原因,表格不够完美。
很好的想法。感谢分享!
12楼说的很对啊
如果光是输出,那意义不大,关键要输出后还能方便读入到lisp。 如果光是输出,那意义不大,关键要输出后还能方便读入到lisp。 牛叉!学习了 入门了 怎么用啊???? 确实牛逼,真的学习了 插眼,收藏 我装了office运行会怎样 确实很神奇,谢谢楼主分享 这个厉害了,对树形系统搭建有很大用处,留名备用
页:
[1]
2