本帖最后由 作者 于 2007-12-15 23:53:44 编辑
继续:- ;|
- 获取DOCS集ID
- |;
- (defun nbtf-vldoc-get-DOCS ()
- (setq *WordApp-Docs*(VLA-GET-DOCUMENTS *WordApp*))
- ) ;_ 结束defun
- ;|
- 获取当前DOCID
- |;
- (Defun nbtf-vldoc-get-Doc()
- (setq *WordApp-Doc*(vlax-get-property *WordApp* "ActiveDocument"))
- )
- ;;; 获取文档的 paragraphs(进行格式设置)
- (Defun nbtf-vldoc-get-paragraphs (doc)
- (if(null doc)(setq doc(nbtf-vldoc-get-Doc)))
- (MSWdP-GET-PARAGRAPHS doc)
- ) ;_ 结束Defun
- (Defun nbtf-vlDoc-Add-text
- (range text / stylename texth BOLD UNDERLINE obj)
- ;; 获取文档的 paragraphs(进行格式设置)
- (cond ((and (= (type text) 'LIST)
- (setq stylename (cdr (assoc 7 text)) ;_字体
- texth (cdr (assoc 40 text)) ;_字高
- BOLD (cdr (assoc 2 text)) ;_加粗.
- UNDERLINE (cdr (assoc 3 text));_下线
- text (cdr (assoc 1 text)) ;_文字
- ) ;_ 结束setq
- (not text)
- ) ;_ 结束and
- )
- ((vl-catch-all-error-p
- (setq obj
- (vl-catch-all-apply
- 'MSWdm-INSERTAFTER
- (list
- range
- text
- ) ;_ 结束list
- ) ;_ 结束vl-catch-all-apply
- ) ;_ 结束setq
- ) ;_ 结束vl-catch-all-error-p
- (princ (vl-catch-all-error-message obj))
- nil
- )
- (T
- (and BOLD (MSWdP-PUT-BOLD range 1)) ;_粗体.
- (and texth (mswdp-put-size(mswdp-get-font range )texth)) ;_字高.
- (and UNDERLINE(MSWdP-PUT-UNDERLINE range MSWdC-WDUNDERLINESINGLE)) ;下划线
- )
- ) ;_ 结束cond
- ) ;_ 结束Defun
示例:- (defun C:test (/ paragraphs pg font range)
- (setq *wordapp* (nbtf-vlDoc-app-new T))
- (setq paragraphs (nbtf-vldoc-get-paragraphs nil))
- (SETQ pg (MSWdP-GET-LAST paragraphs))
- (SETQ range (MSWdP-GET-RANGE pg))
- (nbtf-vlDoc-Add-text range (list(cons 1 "写了一个文本\n") '(40 . 24)))
- ) ;_ 结束defun
|