5

I am trying to set the color for a specific word in a cell using Spreadsheet_Excel_Writer but did not found any way in the documentation.

I have to set the red color for the first word of a cell but not for the whole text in it.

Is there a way to do this with Spreadsheet_Excel_Writer?

Shakti Singh
  • 84,385
  • 21
  • 134
  • 153
  • 9
    I don't think that Spreadsheet_Excel_Writer can do that as I remember reading source code and they operate on cell level. I think you should try http://phpexcel.codeplex.com/ - it supports rich text. – XzKto Aug 03 '11 at 14:47
  • @Xzkto: Thanks, I think this can not be accomplished using Spreadsheet_Excel_Writer. Will try anything else – Shakti Singh Aug 04 '11 at 12:20
  • Another clunky possibility would be coloring two cells separately and merging them, if that keeps their original colors. – Halil Özgür Aug 18 '11 at 07:47
  • Did you ever happen to figure this one out? – hafichuk Oct 29 '11 at 01:05

2 Answers2

1

The XMLSS spec allows you to use tags, which you can use to change the colour of the font. See http://msdn.microsoft.com/en-us/library/aa140066(v=office.10).aspx#odc_xmlss_ss:data

Spreadsheet_Excel_Writer won't work for you in this case, however if you want to save the document as XML, you can then wrap your first word in a font tag as per the example below.

<?xml version="1.0" encoding="UTF-8"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:c="urn:schemas-microsoft-com:office:component:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:x2="http://schemas.microsoft.com/office/excel/2003/xml" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <ss:Worksheet ss:Name="Sheet1">
  <Table>
   <Column/>
   <Row>
    <Cell>
     <ss:Data xmlns="http://www.w3.org/TR/REC-html40" ss:Type="String">
      <Font html:Color="#00ff00">green</Font>
      <Font html:Size="48" html:Color="#ff0000">red</Font>
      <Font html:Color="#0000ff">blue</Font>
     </ss:Data>
    </Cell>
   </Row>
  </Table>
 </ss:Worksheet>
</Workbook>

Just make note that this is XML not HTML so they must be well formed.

hafichuk
  • 10,351
  • 10
  • 38
  • 53
0

you can set color in any row or column by using inline CSS like style="background"

Vishnu Sharma
  • 1,357
  • 12
  • 11