Search code examples
htmlms-wordoutlookeditortrim

Microsoft Word / Outlook trims leading space


I send SQL to interested parties via Outlook as HTML, with Word as the editor.

I like to format my SQL using spaces, rather than tabs.

When I paste the SQL into the editor, formatting is spot on. But the 'sent' version removes leading spaces.

For example:

Select
 *
From
 Employees

becomes

Select
*
From
Employees

Is there an option to prevent this?


Solution

  • I didn't find solution but found workaround - to replace all (and only) leading spaces to Nonbreaking Spaces. No needs to replace all ever spaces, only leading ones. This way Outlook will not trim them automatically while sending email.

    Before send an email need to

    1. select the text, you want to keep leading spaces, and run Find and Replace (Ctrl+H)
    2. put into Find what: "^p " (caret, p, space) or click at the bottom [Special] button and choose Paragraph Mark and just a space character
    3. put into Replace with: "^p^s" (caret, p, caret, s) or click at the bottom [Special] button and choose Paragraph Mark and Nonbreaking Space
    4. now press [Replace All] - it will replace leading spaces with Nonbreaking Spaces only in selected text, leaving all the rest text unchanged.

    Result with leading spaces:

    First without leading spaces
    One leading space in this row
    No leading spaces again
    One leading space in this row
      Two leading spaces here
    One leading space in this row
    No leading spaces again
    One leading space in this row
      Two leading spaces here
      Two leading spaces here
    One leading space in this row
      Two leading spaces here
      Two leading spaces here
       Three leading spaces here
    

    With leading nonbreaking spaces:

    First without leading spaces
     One leading space in this row
    No leading spaces again
     One leading space in this row
      Two leading spaces here
     One leading space in this row
    No leading spaces again
     One leading space in this row
      Two leading spaces here
      Two leading spaces here
     One leading space in this row
      Two leading spaces here
      Two leading spaces here
       Three leading spaces here