Forum Discussion

kbgriggs's avatar
kbgriggs
Copper Contributor
Jun 25, 2020

Pasting SQL formatted code into Excel cell

Is there a way to paste formatted SQL code into a single Excel cell and retain the formatting?  If I paste directly into the cell, the code spans multiple rows and keeps formatting but if I try to paste into a single cell by pasting into the format bar, it strips the formatting.

 

Here is a dummy sample of formatted code I am trying to paste:

SELECT DISTINCT field
FROM tablename (NOLOCK)
WHERE field Like 'L%' --Reasons starting with "L", per J.Doe

5 Replies

  • Bennadeau's avatar
    Bennadeau
    Iron Contributor

    Hi kbgriggs,

    If this is what you want ...

    The solution I have is to first get in edit mode of the cell (F2 or double click) and paste the first line followed by "Alt+Enter", paste the second line followed by "Alt+Enter", and so on until you're done.

    "Alt+Enter" will create a new line in your cell.

    This can take a while if you have hundreds of line to put in a cell though. Hopefully someone knows of a quicker solution.

     

    Ben

     

    • kbgriggs's avatar
      kbgriggs
      Copper Contributor

      Hi Bennadeau 

      Unfortunately no, that is not what I am trying to get to.  Please see my response to a previous reply.

    • kbgriggs's avatar
      kbgriggs
      Copper Contributor

      Hi SergeiBaklan!  Thank you for your response.  I am able to paste into the cell.  What I am trying to figure out is a way to paste it so that my formatting stays.  Here is an example of what I want it to look like in Excel.  Currently, I am having to reformat word by word to get the colors I need for the code.

       

      • SergeiBaklan's avatar
        SergeiBaklan
        Diamond Contributor

        kbgriggs 

        I see. Here to copy/paste from the site I used Paste as HTML, another sample is copy/pasting as HTML from Word

        Not sure how it will work with other sources.

Resources