Pasting SQL formatted code into Excel cell

%3CLINGO-SUB%20id%3D%22lingo-sub-1489723%22%20slang%3D%22en-US%22%3EPasting%20SQL%20formatted%20code%20into%20Excel%20cell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1489723%22%20slang%3D%22en-US%22%3E%3CP%3EIs%20there%20a%20way%20to%20paste%20formatted%20SQL%20code%20into%20a%20single%20Excel%20cell%20and%20retain%20the%20formatting%3F%26nbsp%3B%20If%20I%20paste%20directly%20into%20the%20cell%2C%20the%20code%20spans%20multiple%20rows%20and%20keeps%20formatting%20but%20if%20I%20try%20to%20paste%20into%20a%20single%20cell%20by%20pasting%20into%20the%20format%20bar%2C%20it%20strips%20the%20formatting.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHere%20is%20a%20dummy%20sample%20of%20formatted%20code%20I%20am%20trying%20to%20paste%3A%3C%2FP%3E%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3ESELECT%3C%2FFONT%3E%20DISTINCT%20field%3CBR%20%2F%3E%3CFONT%20color%3D%22%230000FF%22%3EFROM%3C%2FFONT%3E%20tablename%20(%3CFONT%20color%3D%22%230000FF%22%3ENOLOCK%3C%2FFONT%3E)%3CBR%20%2F%3E%3CFONT%20color%3D%22%230000FF%22%3EWHERE%3C%2FFONT%3E%20field%20%3CFONT%20color%3D%22%23808080%22%3ELike%3C%2FFONT%3E%20'%3CFONT%20color%3D%22%23FF0000%22%3EL%25%3C%2FFONT%3E'%20%3CFONT%20color%3D%22%23339966%22%3E--Reasons%20starting%20with%20%22L%22%2C%20per%20J.Doe%3C%2FFONT%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1489723%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1489813%22%20slang%3D%22en-US%22%3ERe%3A%20Pasting%20SQL%20formatted%20code%20into%20Excel%20cell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1489813%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F710373%22%20target%3D%22_blank%22%3E%40kbgriggs%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThat%20could%20be%20like%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22image.png%22%20style%3D%22width%3A%20756px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F201134iC6F9388D80F280E7%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22image.png%22%20alt%3D%22image.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3Eif%20apply%20Wrap%20text%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1489829%22%20slang%3D%22en-US%22%3ERe%3A%20Pasting%20SQL%20formatted%20code%20into%20Excel%20cell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1489829%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F710373%22%20target%3D%22_blank%22%3E%40kbgriggs%3C%2FA%3E%2C%3C%2FP%3E%3CP%3EIf%20this%20is%20what%20you%20want%20...%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Bennadeau_0-1593104507712.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F201137i0A07416276AE5D78%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20title%3D%22Bennadeau_0-1593104507712.png%22%20alt%3D%22Bennadeau_0-1593104507712.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EThe%20solution%20I%20have%20is%20to%20first%20get%20in%20edit%20mode%20of%20the%20cell%20(F2%20or%20double%20click)%20and%20paste%20the%20first%20line%20followed%20by%20%22Alt%2BEnter%22%2C%20paste%20the%20second%20line%26nbsp%3Bfollowed%20by%20%22Alt%2BEnter%22%2C%20and%20so%20on%20until%20you're%20done.%3C%2FP%3E%3CP%3E%22Alt%2BEnter%22%20will%20create%20a%20new%20line%20in%20your%20cell.%3C%2FP%3E%3CP%3EThis%20can%20take%20a%20while%20if%20you%20have%20hundreds%20of%20line%20to%20put%20in%20a%20cell%20though.%20Hopefully%20someone%20knows%20of%20a%20quicker%20solution.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBen%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1489896%22%20slang%3D%22en-US%22%3ERe%3A%20Pasting%20SQL%20formatted%20code%20into%20Excel%20cell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1489896%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F521%22%20target%3D%22_blank%22%3E%40Sergei%20Baklan%3C%2FA%3E!%26nbsp%3B%20Thank%20you%20for%20your%20response.%26nbsp%3B%20I%20am%20able%20to%20paste%20into%20the%20cell.%26nbsp%3B%20What%20I%20am%20trying%20to%20figure%20out%20is%20a%20way%20to%20paste%20it%20so%20that%20my%20formatting%20stays.%26nbsp%3B%20Here%20is%20an%20example%20of%20what%20I%20want%20it%20to%20look%20like%20in%20Excel.%26nbsp%3B%20Currently%2C%20I%20am%20having%20to%20reformat%20word%20by%20word%20to%20get%20the%20colors%20I%20need%20for%20the%20code.%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22kbgriggs_0-1593106262204.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F201146i10E6D8E803B929D9%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20title%3D%22kbgriggs_0-1593106262204.png%22%20alt%3D%22kbgriggs_0-1593106262204.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1489899%22%20slang%3D%22en-US%22%3ERe%3A%20Pasting%20SQL%20formatted%20code%20into%20Excel%20cell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1489899%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F703724%22%20target%3D%22_blank%22%3E%40Bennadeau%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EUnfortunately%20no%2C%20that%20is%20not%20what%20I%20am%20trying%20to%20get%20to.%26nbsp%3B%20Please%20see%20my%20response%20to%20a%20previous%20reply.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1490215%22%20slang%3D%22en-US%22%3ERe%3A%20Pasting%20SQL%20formatted%20code%20into%20Excel%20cell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1490215%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F710373%22%20target%3D%22_blank%22%3E%40kbgriggs%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20see.%20Here%20to%20copy%2Fpaste%20from%20the%20site%20I%20used%20Paste%20as%20HTML%2C%20another%20sample%20is%20copy%2Fpasting%20as%20HTML%20from%20Word%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22image.png%22%20style%3D%22width%3A%20468px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F201179iA2E82FCE5C7ED5F2%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22image.png%22%20alt%3D%22image.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3ENot%20sure%20how%20it%20will%20work%20with%20other%20sources.%3C%2FP%3E%3C%2FLINGO-BODY%3E
New 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.