jbreard Posted October 24, 2017 Posted October 24, 2017 Hello, Maybe this question has been answered a thousand time but if it's the case I can't find the answer. I would like to display code snippets in MSWord without loosing the IDE formatting (I have to write a comprehensive description of a large programm we use at work). I could always settle for some "printscreen" option but this is really ugly. Does anybody has a workaround for this issue ? Thanks a lot and best regards, Jacques Quote
Lee Mac Posted October 24, 2017 Posted October 24, 2017 If you must use MS Word, perhaps use a fixed width font (e.g. "Courier New")? Or do you mean the syntax colouring that the IDE provides? Quote
David Bethel Posted October 24, 2017 Posted October 24, 2017 Can you insert HTML code into the word DOC ? -David Quote
ronjonp Posted October 24, 2017 Posted October 24, 2017 Can you insert HTML code into the word DOC ? -David Yes .. Lee's code here should do the trick for the OP. defun.docx Quote
jbreard Posted October 24, 2017 Author Posted October 24, 2017 Hello, Thanks to you all for your replies. I'm not quite sure I fully understand them yet but I will try to work around my problem with your hints ! To Lee Mac : yes I want to emulate the color and formatting that the IDE provide. I guess your formatting programm do just that. I will try it. Thanks and best regards, Jacques Quote
Grrr Posted October 24, 2017 Posted October 24, 2017 Ron, What arguments you passed to Lee's routine? With ".doc" works just fine, but not with ".docx": (LM:LISPStyler file '( ("" "") ;; Container ("" "") ;; Quotes/Dots ("" "") ;; Brackets ("" "") ;; Multiline Comments ("" "") ;; Single Comments ("" "") ;; Strings ("" "") ;; Protected Symbols ("" "") ;; Integers ("" "") ;; Reals ) ".doc" nil ) Quote
marko_ribar Posted October 24, 2017 Posted October 24, 2017 @Grrr, I am now just guessing, but I think you didn't understood usage of LispStyler routine... Output should be "htm" or "html", and when file is created you should see to insert html file into Word... Finally you save as doc, or docx... Quote
Grrr Posted October 24, 2017 Posted October 24, 2017 @Marko, I tried your suggestion but I wasn't able to replicate Ron's result. Quote
marko_ribar Posted October 24, 2017 Posted October 24, 2017 @Grrr, you start Word, then instead of new file, you go to open, then browse to *.html and then accept option Word asks you... I know that formatting is somewhat bad, but then again it's colored like it is in html file you preview with your browser... Quote
BIGAL Posted October 25, 2017 Posted October 25, 2017 There may be another way depending on how far you want to go with styling you can use macros inside Word these are VBA code I just had a quick play about making "(" red in colour, not really tested as I don't do lots of macros in word. With Selection.Find .Text = "(" .Replacement.Text = "" .Forward = True .Wrap = wdFindAsk .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Selection.Font.Color = wdColorRed Selection.Find.ClearFormatting Quote
marko_ribar Posted October 25, 2017 Posted October 25, 2017 @Grrr, you start Word, then instead of new file, you go to open, then browse to *.html and then accept option Word asks you... I know that formatting is somewhat bad, but then again it's colored like it is in html file you preview with your browser... Grrr, If you are using older versions of MS Office, you can alternatively do like this... Make *.html file with LispStyler, open *.html in your browser, select all content, press ctrl+C, start MS Word, press ctrl+V... So copy+paste works, you should get colored texts like in *.html file... Quote
jbreard Posted October 25, 2017 Author Posted October 25, 2017 Hello, I tried Lee Mac's formatting programm and managed to get an output in .html. The result is clearly correct (I mean it's proper html) as I can open it in Firefox but I have no color and no particular formatting. After some research, it is my understanding that Lee's code refers to a separate .css file containing the description of all the styles. So if that's correct, I have to understand how to make such a .style to do wathever I want with the .html display. Is that right ? Sorry if I'm not very clear. All this is totally new to me Jacques Quote
Grrr Posted October 25, 2017 Posted October 25, 2017 Grrr, If you are using older versions of MS Office, you can alternatively do like this... Make *.html file with LispStyler, open *.html in your browser, select all content, press ctrl+C, start MS Word, press ctrl+V... So copy+paste works, you should get colored texts like in *.html file... Marko, I'm using MS Office 2013 Pro - and still not able to display correctly the code inside word (I tried various paste special options), it literally displays like this (sample code) : <pre> <span class="brkt">(</span><span class="func">defun</span> C:test <span class="brkt">(</span> <span class="func">/</span> SS i e enx o <span class="brkt">)</span> <span class="brkt">(</span><span class="func">if</span> <span class="brkt">(</span><span class="func">setq</span> SS <span class="brkt">(</span><span class="func">ssget</span> <span class="str">"_:L"</span><span class="brkt">))</span> <span class="brkt">(</span><span class="func">repeat</span> <span class="brkt">(</span><span class="func">setq</span> i <span class="brkt">(</span><span class="func">sslength</span> SS<span class="brkt">))</span> <span class="brkt">(</span><span class="func">setq</span> e <span class="brkt">(</span><span class="func">ssname</span> SS <span class="brkt">(</span><span class="func">setq</span> i <span class="brkt">(</span><span class="func">1-</span> i<span class="brkt">))))</span> <span class="brkt">(</span><span class="func">setq</span> enx <span class="brkt">(</span><span class="func">entget</span> e<span class="brkt">))</span> <span class="brkt">(</span><span class="func">setq</span> o <span class="brkt">(</span><span class="func">vlax-ename->vla-object</span> e<span class="brkt">))</span> <span class="brkt">(</span><span class="func">cond</span> <span class="brkt">(</span> <span class="brkt">(</span><span class="func">vl-some</span> <span class="quot">'</span><span class="brkt">(</span><span class="func">lambda</span> <span class="brkt">(</span>x<span class="brkt">)</span> <span class="brkt">(</span><span class="func">=</span> x <span class="quot">'</span><span class="brkt">(</span><span class="int">0</span> <span class="quot">.</span> <span class="str">"INSERT"</span><span class="brkt">)))</span> enx<span class="brkt">)</span> <span class="brkt">(</span><span class="func">alert</span> <span class="brkt">(</span><span class="func">vla-get-EffectiveName</span> o<span class="brkt">))</span> <span class="brkt">)</span> <span class="brkt">(</span> <span class="brkt">(</span><span class="func">vl-some</span> <span class="brkt">(</span><span class="func">function</span> <span class="brkt">(</span><span class="func">lambda</span> <span class="brkt">(</span>x<span class="brkt">)</span> <span class="brkt">(</span><span class="func">=</span> x <span class="quot">'</span><span class="brkt">(</span><span class="int">0</span> <span class="quot">.</span> <span class="str">"TEXT"</span><span class="brkt">))</span> <span class="brkt">)</span> <span class="brkt">)</span> enx <span class="brkt">)</span> <span class="brkt">(</span><span class="func">alert</span> <span class="brkt">(</span><span class="func">vla-get-TextString</span> o<span class="brkt">))</span> <span class="brkt">)</span> <span class="brkt">)</span> <span class="brkt">)</span> <span class="brkt">)</span> <span class="brkt">(</span><span class="func">princ</span><span class="brkt">)</span> <span class="brkt">)</span> </pre> Or just the clean code, without formatting (no color, no row indexing) - atleast the tabbing is retained, literally like this: (defun C:test ( / SS i e enx o ) (if (setq SS (ssget "_:L")) (repeat (setq i (sslength SS)) (setq e (ssname SS (setq i (1- i)))) (setq enx (entget e)) (setq o (vlax-ename->vla-object e)) (cond ( (vl-some '(lambda (x) (= x '(0 . "INSERT"))) enx) (alert (vla-get-EffectiveName o)) ) ( (vl-some (function (lambda (x) (= x '(0 . "TEXT")) ) ) enx ) (alert (vla-get-TextString o)) ) ) ) ) (princ) ) Quote
marko_ribar Posted October 25, 2017 Posted October 25, 2017 Hmm... Exactly what I don't have... Copy+paste works on MS Office 2010, and pure open file on MS Office 2016... So I don't know how to investigate further more... Notice that I get the same as you when I use pure open file in MS Office 2010... Quote
Grrr Posted October 25, 2017 Posted October 25, 2017 Maybe I got wrong html output from LSP2HTML, since inside the .html file the code looks exactly like the second one I posted: no color, no row indexing, just tabbing retained. Thats why I asked Ron what arguments he used for Lee's LISPStyler. Else I would just blame my MS office 2013. Quote
ronjonp Posted October 25, 2017 Posted October 25, 2017 Ron,What arguments you passed to Lee's routine? With ".doc" works just fine, but not with ".docx": (LM:LISPStyler file '( ("" "") ;; Container ("" "") ;; Quotes/Dots ("" "") ;; Brackets ("" "") ;; Multiline Comments ("" "") ;; Single Comments ("" "") ;; Strings ("" "") ;; Protected Symbols ("" "") ;; Integers ("" "") ;; Reals ) ".doc" nil ) Grrr, I just quickly hardcoded color values like so: (lm:lispstyler file '(("<pre>" "</pre>") ;; Container ("<font color=\"black\">" "</font>") ;; Quotes/Dots ("<font color=\"red\">" "</font>") ;; Brackets ("<font color=\"gray\">" "</font>") ;; Multiline Comments ("<font color=\"gray\">" "</font>") ;; Single Comments ("<font color=\"DarkOrchid\">" "</font>") ;; Strings ("<font color=\"blue\">" "</font>") ;; Protected Symbols ("<font color=\"green\">" "</font>") ;; Integers ("<font color=\"darkgreen\">" "</font>") ;; Reals ) ".html" t ) Then copy paste to Word 2016 Quote
jbreard Posted October 25, 2017 Author Posted October 25, 2017 Thanks a lot Ronjonp. That did the trick for me ! And thanks a lot to Lee Mac too for his formatting programm : quite a useful (and impressive) piece of LISP ! Regards, Jacques Quote
ronjonp Posted October 25, 2017 Posted October 25, 2017 Thanks a lot Ronjonp. That did the trick for me ! And thanks a lot to Lee Mac too for his formatting programm : quite a useful (and impressive) piece of LISP ! Regards, Jacques You might read HERE too .. the way I approached this is probably not the best way to go about it. Quote
jbreard Posted October 25, 2017 Author Posted October 25, 2017 I'm relieved to have a functionnal solution though. I will study your link and others but for the moment I'm quite happy ! Regards, Jacques Quote
Grrr Posted October 25, 2017 Posted October 25, 2017 Thanks Ron, now I managed to replicate the result you got - the code inside the .html output file is colored and tabbed and when I copy it into word it appears the same way. Only the row numbering is missing - can you see it inside your .html output file or thats just an option of MS word? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.