1

I have a field that has a number of line breaks in it, and I want to have the field exported with the line breaks retained in a report. The fields themselves should look something like this

Full name, Title, \r\n
Full name, Title, \r\n

I used a trigger to populate the field, and simply added on the \r\n to the end of the "Full name, Title" string. When I tried to export the report using the "export details" button, the new lines are forgotten about, and the xls document shows this:

Full name, Title, \r\nFull name, Title, \r\n

Which is not what I want. I tried using the "printable view" button, but all that did was separate the cell into multiple cells according to the line breaks, which rendered it unusable.

What I'd like to know is whether or not there is an alternative to '\r\n' that I can put into the field, such that the "export details" button will keep the line breaks, and what this alternative is.

Thanks!

7
  • Have you tried using only \n ? Commented Aug 16, 2013 at 2:32
  • 1
    It may be as simple as highlighting the cells in Excel and clicking "Wrap Text." I believe excel displays all contents on one line, even if there are line breaks, unless that option is selected.
    – Benj
    Commented Aug 16, 2013 at 2:57
  • @e-bacho2.0, I did and it didn't change anything. I was thinking that maybe the carriage return would have caused the problem, but sadly, no. Commented Aug 16, 2013 at 3:00
  • @Benj, no go on that one--the text was already wrapping. Commented Aug 16, 2013 at 3:00
  • 1
    Too bad. Looks like there's an old idea on the ideaexchange to fix this: success.salesforce.com/ideaView?id=087300000007DRw
    – Benj
    Commented Aug 16, 2013 at 3:04

1 Answer 1

2

The "Export to Excel" XLS format is actually an HTML file disguised with an XLS ending (so that your computer will automatically open the file in Excel instead of a web browser). HTML, by its very nature, usually collapses multiple whitespaces into a single whitespace. For example, given the following HTML:

<p>The Quick Brown
        Fox Jumps Over
   The Lazy Dog</p>

Will be rendered as:

The Quick Brown Fox Jumps Over The Lazy Dog

Since HTML doesn't insert line breaks as a matter of course (except for very specific conditions), there is usually a tag that is used known as the break tag (<br/>). This instructs an HTML parser to insert a literal line break at the indicated position.

Getting back to Excel, when its HTML parser observes a line break, it will ignore it, just as it is supposed to. That means that if your source looks like:

<td>John Doe
Jane Doe
Mary Jane</td>

Excel will dutifully render it as:

John Doe Jane Doe Mary Jane

To fix this, salesforce.com would need to patch their export engine to change \n into a <br/>. You cannot insert a literal <br/>, because it would be encoded as &lt;br/&gt;, which Excel would render back into <br/> upon HTML parsing.

The current workaround is to export as CSV. CSV honors whitespace and is therefore suitable for properly exporting line delimited data. You should note that this will strip all formatting from the file, but retain the line breaks.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .