function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Naveen AdminNaveen Admin 

Can anyone tell How to coloring a Cell based on Condition in XML Spread sheet using Visualforce?

Hi,
     I am using XML Spread sheet code in visual force page which generates Multisheets,there is a requirement i should put color for cell based on condition,For ex:if cell contains property 10% the put RED color,If it contains Property 20% then put BLUE color.But i din get the approach to put condition in Visualforce page.I tried to achieve this taking an example program that i have written below,

<apex:page controller="ExcelControllerCheck2" contentType="txt/xml#myTest.xls" cache="true">
<apex:outputText value="{!xlsHeader}"/> 

<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
    xmlns:o="urn:schemas-microsoft-com:office:office"
    xmlns:x="urn:schemas-microsoft-com:office:excel"
     xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
    xmlns:html="http://www.w3.org/TR/REC-html40"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">  
  <Styles>
   <Style ss:ID="s1">
   <Alignment/>
   <Borders/>
   <Font ss:Bold="1" ss:Color="RED"/>
   <Interior ss:Pattern='Solid' ss:Color="#B8B8B8"/>
    <NumberFormat/>
    <Protection/>
  </Style>
   
   <Style ss:ID="s2">
   <Alignment/>
   <Borders/>
   <Font ss:Color="BLUE"/>
    <NumberFormat/>
    <Protection/>
   </Style>
    
   
     <!--
     <Style ss:ID="s2">
   <Alignment/>
   <Borders/>
   <Font ss:Bold="1" />

   <Interior ss:Color="Gray75"/>
    <NumberFormat/>
    <Protection/>
     </Style>
     -->
   </Styles>
  
<Worksheet ss:Name="Accounts">
  <Table x:FullColumns="1" x:FullRows="1">
  <Column ss:Width="170"/>
  <Row>
<Cell ss:StyleID="s1"><Data ss:Type="String" >Account Name</Data></Cell>
</Row>
  <apex:repeat value="{!accountList}" var="account">
  <Row>
<Cell><Data ss:Type="String">{!account.name}</Data></Cell>
</Row>
</apex:repeat>
</Table>
</Worksheet>

<Worksheet ss:Name="Contacts">

<WorksheetOptions
xmlns="urn:schemas-microsoft-com:office:excel">
<Selected/>
<FreezePanes/>
<FrozenNoSplit/>

<!--- Right-most column number of left pane. --->
<SplitVertical>1</SplitVertical>
<SplitVertical>2</SplitVertical>
<!---
Offset column of right frame. This is not the actual
column number of the overall Excel document, but rather
the index of the available column for this pane. This
number cannot exclude columns, it can merely set the
offset scroll of this pane. (1) scrolls to the left of
the frame (first column).
--->
<LeftColumnRightPane>1</LeftColumnRightPane>
<LeftColumnRightPane>2</LeftColumnRightPane>
</WorksheetOptions>

<Table x:FullColumns="1" x:FullRows="1">
  <Column ss:Width="170"/>
  <Column ss:Width="280"/>
  <Column ss:Width="330"/>
  <Column ss:Width="550" />
  <Row>
  <Cell ss:StyleID="s1"><Data ss:Type="String">Contact Name</Data></Cell>
   <Cell ss:StyleID="s1"><Data ss:Type="String" >Last Name</Data></Cell>
   <Cell ss:StyleID="s1"><Data ss:Type="String" >Account Name</Data></Cell>
   <Cell ss:StyleID="s1" ><Data ss:Type="String" >Created Date</Data></Cell>
  </Row>
  <apex:repeat value="{!contactList}" var="contact">
  <Row>
  <Cell ss:StyleID="s2"><Data ss:Type="String">{!contact.name}</Data></Cell>
<Cell><Data ss:Type="String">{!contact.lastName}</Data></Cell>
  <Cell><Data ss:Type="String">{!contact.account.name}</Data></Cell>
   <Cell><Data ss:Type="String"><apex:outputText value=" {0,date,M/d/yyy, h:mm a}">
    <apex:param value="{!contact.CreatedDate}" />
</apex:outputText></Data></Cell>
   </Row>
</apex:repeat>
</Table>

</Worksheet>
</Workbook>

</apex:page>



And also  i need to put color for <Worksheet ss:Name="Account"> .Please if anyone knows post the answer,It will help a lot.

Thanks.