Why not Crtl A Ctrl C then Ctrl V in mtext its instant.
does it have to be word?
If not you could easily create a html file which you can view and print to pdf or hard copy as required? It would be a simple matter of setting up some simple html header markup, add you list data to table elements in a loop then add to closing markup and open in a browser.
I'd be happy to help out if you like.
Something along these lines will work, this is NOT WORKING and is only a rough outline (my Lisp Fu is weak :) )Code - Auto/Visual Lisp: [Select]
;; DATATOHTML --------------------------------------------------------- ;; ;; params: ;; data - a list of records to add to tablet ;; htmlFile - ptr to html file to save data to e.g. "C:\\datatest.html" ;; -------------------------------------------------------------------- ;; ;; create the html file pointer: ;; create the html5 header portion: "<!DOCTYPE html>" "\n<html lang=\"en\">" "\n<head>" "\n\t<meta charset=\"UTF-8\">" "\n\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">" "\n\t<meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\">" "\n\n\t<title>Document</title>" "\n</head>" "\n\t<body>" "\n\t\t<table>" ;; create/open table tag "\n\t\t\t<tr>")) ;; create/open row tag ;; create the html table header titles: "\n\t\t\t\t<th>" "Name" "</th>" ;; add column header "\n\t\t\t\t<th>" "Description" "</th>" ;; add column header "\n\t\t\t\t<th>" "Length" "</th>" ;; add column header "\n\t\t\t\t<th>" "Qty" "</th>" ;; add column header "\n\t\t\t</tr>")) ;; close row tag ;; loop through data records adding html table rows: ;; something like(foreach val (data "\n\t\t\t</tr>")) ;; open row tag "\n\t\t\t\t<td>" name-val "</td>" ;; add name column data "\n\t\t\t\t<td>" desc-val "</td>" ;; add desc column data "\n\t\t\t\t<td>" length-val "</td>" ;; add length column data "\n\t\t\t\t<td>" qty-val "</td>" ;; add qty column data "\n\t\t\t</tr>")) ;; close row tag ;;(princ val))) ;; close off table and add html footer to close all html tags: "\n\t\t\t</table>" ;; close table tag "\n\t\t\t\t<th>" ;; close body tag "\n\t\t\t\t<th>")) ;; close html tag ;; close the file: ;; open the file in the default web browser: ;; TODO )
Aside:
Is there a way to create 'literal' strings like using the '@' in C#??
I could see way of creating templates for this sort of thing if so ;)
C:\Program Files\Google\Chrome\Application> chrome.exe --headless --disable-gpu --print-to-pdf=file1.pdf http://www.example.com/
It takes around 3 mins for a 6 pages document.this is too much, i'm sure something is wrong with you code
Something like this might come in handy -> https://wkhtmltopdf.org/
Also note that you may want to style your tables and other output but it's really not that hard once you get going and you can embed the css styling in the html using <style> tags rather than importing a css file into the html but either way will work fine. It might sound like a bit of work but this way will be much more configurable than trying to automate styling etc through word and creating text files is pretty quick.
A simpler way may be to use Chrome as 'headless':QuoteC:\Program Files\Google\Chrome\Application> chrome.exe --headless --disable-gpu --print-to-pdf=file1.pdf http://www.example.com/
It takes around 3 mins for a 6 pages document.this is too much, i'm sure something is wrong with you code
we have not seen it and we can only guess
have you set "ScreenUpdating" property to false?
MickD's suggestion about html is quite good
i personally do it that way
yes it is very very fast, hundreds of pages are generated almost instantly
there's no need to convert html to pdf
just save you html file with 'doc' extension, msword will open it without questions
msword also supports 'XML Document' format
i use it for some 'sophisticated' documents, when html is not enough
Not sure if it's my scripts' problem or it is normal when using API.google some info on Word API performance
(defun word_escribir_texto_con_estilo (lis)
(foreach a lis
(mswm-Collapse *range* mswc-wdCollapseEnd)
(mswp-put-style *range* (car a))
(mswm-InsertAfter *range* (cadr a))
)
)
(setq lis (list
(list "Normal" "Normal text")
(list "Tittle 1" "In a tittle")
))
(word_escribir_texto_con_estilo lis)
(defun carga_word (dot / nombre)
(setq *msw* (vlax-get-or-create-object (vl-registry-read "HKEY_CLASSES_ROOT\\Word.Application\\CurVer")))
(if (null mswc-wd24hourclock)
(vlax-import-type-library
:tlb-filename (findfile (strcat (vla-get-path *msw*) "\\MSWORD.OLB")) ;posible error
:methods-prefix "mswm-"
:properties-prefix "mswp-"
:constants-prefix "mswc-")
)
(vla-put-visible *msw* :vlax-true) ;Cambiar por True
(setq *docs* (vla-get-documents *msw*)
*doc* (mswm-add *docs* dot ) ;Plantilla proyecto
*paragraphs* (mswp-get-paragraphs *doc*)
*pg* (mswp-get-last *paragraphs*)
*range* (mswp-get-range *pg*)
)
)
Not sure if it's my scripts' problem or it is normal when using API.google some info on Word API performance
something like this -> https://wordmvp.com/FAQs/TblsFldsFms/FastTables.htm
I use Word and it's faster than you say.
1-2 pages per second
I also use tables and combine cells and many different (sophisticated) methods and its more slowly.
Use range object and write and collapse.. write and collapse... and so on.
I use styles to format the document and the most frecuenty function is:Code: [Select](defun word_escribir_texto_con_estilo (lis)
(foreach a lis
(mswm-Collapse *range* mswc-wdCollapseEnd)
(mswp-put-style *range* (car a))
(mswm-InsertAfter *range* (cadr a))
)
)
from a list of listCode: [Select](setq lis (list
(list "Normal" "Normal text")
(list "Tittle 1" "In a tittle")
))
(word_escribir_texto_con_estilo lis)
To create a new document from a template (dot) use:Code: [Select](defun carga_word (dot / nombre)
(setq *msw* (vlax-get-or-create-object (vl-registry-read "HKEY_CLASSES_ROOT\\Word.Application\\CurVer")))
(if (null mswc-wd24hourclock)
(vlax-import-type-library
:tlb-filename (findfile (strcat (vla-get-path *msw*) "\\MSWORD.OLB")) ;posible error
:methods-prefix "mswm-"
:properties-prefix "mswp-"
:constants-prefix "mswc-")
)
(vla-put-visible *msw* :vlax-true) ;Cambiar por True
(setq *docs* (vla-get-documents *msw*)
*doc* (mswm-add *docs* dot ) ;Plantilla proyecto
*paragraphs* (mswp-get-paragraphs *doc*)
*pg* (mswp-get-last *paragraphs*)
*range* (mswp-get-range *pg*)
)
)
and
*range* is a global variable to write in the document.
It's one of the best things I've done to automate engineering reports.
Are these table objects you're formatting in CAD ? If so look into vla-put-RegenerateTableSuppressed and set it to true before making changes.