1

I am generating an excel file from VF page. I would need some help in formating the excel sheet. Can the width of the cells in the top row be different from the cells of the tables in the bottom. Something like we merge a few columns in Row A of excel sheet.

enter image description here

Here is my VF page

    <apex:page standardController="Quote" extensions="CVFE_GenerateExcelQuote" contentType="application/vnd.ms-excel#SalesForceExport.xls" cache="true" >
  <!--  contentType="application/vnd.ms-excel#SalesForceExport.xls" cache="true" -->


    <head>
          <style>
              .aligncenter
              {
                  text-align:center;
              }
          </style>
      </head>

      <table>
          <tr>
              <td colspan="2"> 
                <table>
                  <tr>
                      <td style="width:500px; height: 95px;">
                           <img src="{!url}" /> <br/>
                      </td>
                  </tr>
                  <tr>
                      <td>
                            Some Addrress
                      </td>
                  </tr>
                </table> 
              </td>
              <td width="100px">

              </td>
               <td width="100px">

              </td>
               <td width="100px">

              </td>
              <td>
                  <table>
                      <tr>


                          <td >John Doe</td>
                          <td >Billing</td>
                          <td >Traffic</td>
                          <td >Ad Ops</td>
                    </tr>
                    <tr>


                          <td >Vice President Sales</td>
                          <td >billing@a.com</td>
                          <td >Traffic@a.com</td>
                          <td >AdOps@a.com</td>
                    </tr>
                </table>
             </td>
          </tr>

      </table>
        <apex:repeat value="{!OptionsSet}" var="f">
            <apex:outputText value="{!f}" /><br/>
                <apex:dataTable value="{!MapOptionQLI[f]}" var="s" style="border: 1px solid black;">
                    <apex:column value="{!s.Placement_Name__c}" />
                    <apex:column value="{!s.Start_Date__c}" style=" text-align:center;"/>
                    <apex:column value="{!s.End_Date__c}" style=" text-align:center;"/>
                    <apex:column value="{!s.Ad_Format__c}" style=" text-align:center;"/>
                    <apex:column value="{!s.Targetting__c}" style=" text-align:center;"/>
                    <apex:column value="{!s.Additional_Targetting__c}" style=" text-align:center;"/>                

                    <apex:column style=" text-align:center;">
                        <apex:facet name="header">Rate</apex:facet>
                        <apex:outputfield value="{!s.UnitPrice}"/>

                    </apex:column>
                    <apex:column style=" text-align:center;">
                        <apex:facet name="header">Impressions</apex:facet>
                         <apex:outputfield value="{!s.Quantity}"/>

                    </apex:column>
                    <apex:column style=" text-align:center;">
                        <apex:facet name="header">CPM/CPC</apex:facet>
                        <apex:outputfield value="{!s.Rate_Type__c}"/>
                    </apex:column>

                    <apex:column value="{!s.Total_Investments__c}" style=" text-align:center;"/>
                    <apex:column value="{!s.Notes__c}" />
                </apex:dataTable>

        </apex:repeat>




    </apex:page>
2
  • 1
    Why not use an app from the appexchange for this? Something like conga composer has already solved these issues.
    – Nick Cook
    Feb 23 '16 at 7:28
  • 1
    yes, but they are not free. Its not something client is willing to pay as they dont have too much of creating documents
    – Prady
    Feb 23 '16 at 7:34
2

I haven't tried it, but take a look at this.

Instead of using HTML tags, it uses tags that are recognised by Excel.

In terms of XML markup, I think that page is slightly wrong, this seems like a good example of how to style columns:

<?xml version="1.0"?>
<ss:Workbook xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
    <ss:Worksheet ss:Name="Sheet1">
        <ss:Table>
            <ss:Column ss:Width="80"/>
           <ss:Column ss:Width="80"/>
           <ss:Column ss:Width="80"/>
            <ss:Row>
                <ss:Cell>
                    <ss:Data ss:Type="String">First Name</ss:Data>
                </ss:Cell>
                <ss:Cell>
                    <ss:Data ss:Type="String">Last Name</ss:Data>
                </ss:Cell>
                <ss:Cell>
                    <ss:Data ss:Type="String">Phone Number</ss:Data>
                </ss:Cell>
            </ss:Row>
        </ss:Table>
    </ss:Worksheet>
</ss:Workbook>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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