473,573 Members | 2,733 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cell Formatting

10 New Member
I am currently writing excel(.xls) files using xml and would like to format the cells so that when the file is opened the cells are already formatted.Does anybody out there know how this is done

Expand|Select|Wrap|Line Numbers
  1. $data = "
  2.             <?xml version='1.0'?>
  3.             <?mso-application progid='Excel.Sheet'?>
  4.             <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'>
  5.             <Worksheet ss:Name='Investors'>
  6.             <Table>
  7.              ";
  8. $x = 0;
  9. for ($x = 0; $x < $resultCounter; $x++){
  10.         $data .= "<Row>";
  11.         $data .= "<Cell><Data ss:Type='Number'>".$numericField[$x]."</Data></Cell>";
  12.         $data .= "<Cell><Data ss:Type='String'>".$StringField[$x]."</Data></Cell>";
  13.        $data .= "</Row>";
  14. }
  16. $data .= "</Table></Worksheet></Workbook>";
Thanks in advance for the help
Jan 14 '09 #1
3 8591
2,057 Recognized Expert Top Contributor
What type of formatting? Bold, Italic, and Underline are easy: just add <b>,<i>, or <u> tags like in html. (note, this is not the microsoft office proper way, but is faster) eg:
Expand|Select|Wrap|Line Numbers
  1. <Cell><ss:Data ss:Type="String" xmlns="http://www.w3.org/TR/REC-html40">Partial <B>Bold</B></ss:Data></Cell>
gives you a cell:
Partial Bold

Another way is to define styles. Change your <Styles> node (or add one to your Workbook node if you don't already have it.)

Here we defined one style, and we are applying to a cell by using the cell's styleID attribute.
Expand|Select|Wrap|Line Numbers
  1. <Styles>
  2.   <Style ss:ID="Default" ss:Name="Normal">
  3.    <Alignment ss:Vertical="Bottom"/>
  4.    <Borders/>
  5.    <Font/>
  6.    <Interior/>
  7.    <NumberFormat/>
  8.    <Protection/>
  9.   </Style>
  10.    <Style ss:ID="s29">
  11.    <Alignment ss:Horizontal="Center" ss:Vertical="Bottom" ss:WrapText="1"/>
  12.    <Font ss:FontName="Arial Black" x:Family="Swiss" ss:Size="12" ss:Bold="1"/>
  13.   </Style>
  14.  </Styles>....
  15. <Cell ss:StyleID="s29"><Data ss:Type="String">formatted text</Data></Cell>
Jan 14 '09 #2
10 New Member
Thanks for the help, the code you posted helped loads, thanks very much
Jan 15 '09 #3
10 New Member
Hi rlejason

Thanks for the advice, I did manage to get the cells formated correctly (using XML). It was for a site the used PHP, thus the XML way of doing it was required ... I think

Thank anyway thou.
Aug 11 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

by: James | last post by:
wxpython 2.5.3 hi, anyone know how to make a multiline cell editor for wxgrid? thank you :) best regards, James
by: Paul E Collins | last post by:
I need to 'clip' text in a table cell instead of wrapping it, such that (i) the cell keeps its specified fixed width and (ii) any text that overflows the cell should be 'clipped' (hidden or truncated) rather than wrapping to create a new line in the cell. If the actual content of the clipped cell is "Hello world", it should look something...
by: DraguVaso | last post by:
Hi, I'm looking for a nice way to format the cell of my datagrid according to some predefined 'rules'. I found a lot on the site of George shepherd, but it wasn't really what I was looking for: I found there: How can I change the font used in a Gridcell on a cell by cell or row by row basis. Wih this code I am able to change the...
by: GV | last post by:
Hi all, I created 2 label controls and add them to a table cell the first one is fine left justified but i want to right justify the 2nd label control to the right of the cell? How to you programmically control where in the cell a control is placed? here is my code to create the controls Protected Sub Page_Load(ByVal sender As Object,...
by: urbancowboy | last post by:
Hi, I'm a complete noob to XSLT. My goal is to apply conditional formatting to the table-cell only so when the date = today, the entire table-cell background will highlight green (#00FF00) and not just the font itself. So far, I can only get the Font to change color/become highlighted. Any help please? ---------------------------------...
by: Brian Parker | last post by:
I need to format text in cell in an Excel worksheet and I need to do this using C#. I've seen code that will set the format for the whole cell, but I just need to format one character in that cell. Example: The cell has this text in it: H20 I need to use C# to change the "2" to be a subscript.
by: nickb34 | last post by:
I don't have much experience with VB and I have found Excel's conditional formatting very limited. I need a macro that will search through all the cells and when it finds a blank cell, it needs to be filled with white. The limitations of the conditional formatting are causing all of the cells to be filled with color because it sees the number 0 as...
by: Jukka K. Korpela | last post by:
Sub titulo "Re: DIV borders different in IE7 when in td" scripsit Ben C: This seems to be the heart of the matter, and I'm trying to get a real discussion started, by moving the discussion to the right group (c.i.w.a.stylesheets) and changing the Subject line. It seems to me that IE 7, specifically in "standards mode" (!), misbehaves...
by: laszlokenez | last post by:
Tested in IE7 and FF2. I have 2 frames, 2 similar tables in them, similar CSS. (I have 1px cellpadding, and 1px border aroud the cells. From one frame I read the offsetHeight of a cell (getElementById), and set the height of the corresponding cell in the other frame. Here: ...
by: patrick.waldo | last post by:
Hi all, I am trying to figure out a way to read colors with xlrd, but I did not understand the formatting.py module. Basically, I want to sort rows that are red or green. My initial attempt discovered that text:u'test1.txt' (XF:22) text:u'test2.txt' (XF:15) text:u'test3.txt' (XF:15) text:u'test4.txt' (XF:15) text:u'test5.txt' (XF:23)
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.