473,545 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cell Formatting

10 New Member
Hi
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. }
  15.  
  16. $data .= "</Table></Worksheet></Workbook>";
  17.  
Thanks in advance for the help
Jan 14 '09 #1
3 8586
jkmyoung
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>
  16.  
Jan 14 '09 #2
wolfjmt
10 New Member
Thanks for the help, the code you posted helped loads, thanks very much
Jan 15 '09 #3
wolfjmt
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

1
4931
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
2
36239
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...
2
11698
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...
2
3519
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,...
0
2518
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? ---------------------------------...
2
2886
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.
1
1734
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...
2
3808
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...
2
3986
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: ...
2
9701
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)
0
7473
marktang
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...
0
7660
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7813
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7431
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...
0
5976
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5337
isladogs
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...
0
4949
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...
0
3444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
709
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.