Pasting SQL formatted code into Excel cell

Copper Contributor

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

@kbgriggs 

That could be like

image.png

if apply Wrap text 

Hi @kbgriggs,

If this is what you want ...

Bennadeau_0-1593104507712.png

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

 

Hi @Sergei Baklan!  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.

kbgriggs_0-1593106262204.png

 

Hi @Bennadeau 

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

@kbgriggs 

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

image.png

Not sure how it will work with other sources.