You need to sign in to do that
Don't have an account?
Visualforce , Excel and line breaks
Problem:
You have a VF page that you want to output as Excel but the line breaks in your TextArea fields cause Excel to create new rows at each line break rather than preserve the line breaks within the cell as if you had used ALT-ENTER (or your line breaks are lost altogether and the text is run on with no breaks)
Example:
SFDC TextArea field contains:
"Line 1
Line 2"
(or "Line 1\nLine 2")
Your output in Excel should be one row with the cell preserving the line breaks but you either:
a) get two rows, broken at the line break
b) one row but the line break is lost and the text is run-on
Solution follows in the next post
Here's the solution:
1. If using a VF controller, replace your \n in strings with <br/> as in:
2. Use a VF page similar to this one. Note the style for the br tag. The example also shows how to get UTF-8 output
If you do a web search on mso-data-placement you'll see many references on HTML -> EXCEL discussing this topic. I just applied it to VF.
All Answers
Here's the solution:
1. If using a VF controller, replace your \n in strings with <br/> as in:
2. Use a VF page similar to this one. Note the style for the br tag. The example also shows how to get UTF-8 output
If you do a web search on mso-data-placement you'll see many references on HTML -> EXCEL discussing this topic. I just applied it to VF.
Eric,
Thanx a lot. Your solution works gr8 for the line breaks but the columns still have problem.
Do you have nay idea, how to set the values in separate columns? Currently am using \t and it not working as intended.
Thanx in advance for ur help.
Thanx
Cheers
Here is a fairly general way to do this, especially if you have more than 1000 rows to output. It relies on VF controller code to build a List of Lists of your output data so you don't run afoul of the 1000 element collection size limit. You may run into other limits like HeapSize if you have a huge output file
For the columns thing I have been using CSS (as a static resource) to stylize my PDF but you might be able to use it for andthing else.