[SalesForce] Render page as excel, default output is without gridlines

It seems that every page that I rendered as excel the downloaded file is by default without gridlines.

I can go to the excel properties and check the option 'Gridlines', the I'm able to see the gridlines, but I'm checking how it can be automatically set to checked.

See example:

<apex:page StandardController="Account"  cache="true" 
        contentType="application/vnd.ms-excel#SalesForceExport.xls"
        showHeader="false" sidebar="false" standardStylesheets="false">

<apex:pageBlock >    
    <apex:pageBlockSection columns="1">
        <apex:pageBlockSectionItem >
            <apex:outputLabel value="Account Name" />
            <apex:outputText value="{!Account.Name}" />
        </apex:pageBlockSectionItem>


    </apex:pageBlockSection>


</apex:pageBlock>

</apex:page>

enter image description here

Best Answer

When we download Excel using default code(Like your) we don't get much styling and also the gridlines are missing as well.

To handle this you need to modify your code and need to create excel in visualforce using tag. You need to use Row, Call, Data tag to get proper style and gridlines.

<apex:repeat value="{!opportunities}" var="opp">
   <Row>
    <Cell ><Data ss:Type="String">{!opp.Name}</Data>
        <NamedCell ss:Name="Name_Column"/></Cell>
    <Cell ><Data ss:Type="String">{!opp.StageName}</Data>
        <NamedCell ss:Name="Stage_Column"/></Cell>
    <Cell ><Data ss:Type="Number">{!opp.Amount}</Data>
        <NamedCell ss:Name="Amount_Column"/></Cell>
    <Cell ss:StyleID="s75" ss:Formula="=IFERROR(RC[-1]/Total_Amount_Cell,0)"><Data
      ss:Type="Number"></Data>
        <NamedCell ss:Name="Percentage_of_Total_Column"/></Cell>
   </Row>
</apex:repeat>

Using these tag you can easily get output like

enter image description here

Reference : Stylish Spreadsheets From a Visualforce Page