Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a Visual page which offers the capability of exporting a data table to Excel.

There is a text field called Account number. Some account numbers are more than 12 digits long. When such numbers are exported to Excel, they are shown by default in the scientific format.

12345678912345 becomes 1.23457E+13

Currently my code for this column is:

  <apex:column headerValue="Account Number">                   
            <apex:outputText value="{!mt.Account_Number__c}"/>                                     

I tried using different formatting options but they didn't work. Also tried using Apex:OutputField without success.

I tried some solutions like adding css but that did not help either.

I know this is Excel's default behavior with numbers with 12 digits or more. Any ideas as to how I can force it to display them as Strings in my Visual force page?


share|improve this question
Are you sure the field is text and not a number? – Mike Chale Feb 21 '13 at 17:30
Yes the field type is text as some account numbers can be numeric or alphanumeric. – Richard N Feb 21 '13 at 17:31
up vote 9 down vote accepted

Try to insert html blanks to the start and end of the string:

<apex:column headerValue="Account Number">                   
    <apex:outputText value="&nbsp;{!mt.Account_Number__c}&nbsp;" escape="false"/>
share|improve this answer
Superb...I did try blank spaces but not HTML blanks..This worked perfectly my friend...thanks! – Richard N Feb 21 '13 at 17:57

If you want more fine-grained control over the number formats when they are exported to Excel, you can use a combination of a dynamic style parameter in the VForce page, and associated property in your controller.

eg. in this case I'm formatting a dynamic length text field (of numbers) as a number in Excel using 0's as the format type (ie no scientific display).

In the VForce page:

<td style="width:160px; line-height:13px;{!GTINCodeFormat[p]}" class="ean">{!productListByParentProductName[parentProd][p].Product__r.GTIN_pfi__c}</td>

(the style class is using embedded controller property based on current list element)

In controller:

public Map<String, String> GTINCodeFormat {get; protected set;}

if (p.Product__r.GTIN_pfi__c != null) {
s = '';
codeLen = p.Product__r.GTIN_pfi__c.length();
for (Integer i=1;i<=codeLen;i++) {
    s += '0';
GTINCodeFormat.put(p.Product__r.Oracle_Item_Code_pfi__c, s);
}  else {
GTINCodeFormat.put(p.Product__r.Oracle_Item_Code_pfi__c, '@');
share|improve this answer
Very interesting. Thanks for sharing. – Richard N Mar 4 '13 at 16:12

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.