<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: How to create a stylesheet in Excel Open XML</title>
	<atom:link href="http://polymathprogrammer.com/2009/11/09/how-to-create-stylesheet-in-excel-open-xml/feed/" rel="self" type="application/rss+xml" />
	<link>http://polymathprogrammer.com/2009/11/09/how-to-create-stylesheet-in-excel-open-xml/</link>
	<description>Mathematics. Programming. Entrepreneurship.</description>
	<lastBuildDate>Fri, 27 Jan 2012 12:15:54 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Vincent</title>
		<link>http://polymathprogrammer.com/2009/11/09/how-to-create-stylesheet-in-excel-open-xml/comment-page-1/#comment-34524</link>
		<dc:creator>Vincent</dc:creator>
		<pubDate>Wed, 21 Jul 2010 03:33:46 +0000</pubDate>
		<guid isPermaLink="false">http://polymathprogrammer.com/?p=1645#comment-34524</guid>
		<description>Hi Sebastien, I&#039;m afraid using the builtin styles aren&#039;t as straightforward as you think (I was surprised too). From the MSDN:

&quot;The built-in cell styles are written here by name, but the corresponding formatting records are assumed rather than explicitly written.&quot;

What they mean is that setting some variable to index 26 or 27 is not enough to make that style the &quot;Good&quot; version or the &quot;Bad&quot; version. You still have to set the individual font, border, background colour and so on.

For example, you still have to create the (by default) Calibri font, green background colour for the &quot;Good&quot; builtin style. And then, you add this part:

CellStyles css = new CellStyles();
CellStyle cs = new CellStyle();
cs.Name = &quot;Normal&quot;;
cs.FormatId = 0;
cs.BuiltinId = 0;
css.Append(cs);

cs = new CellStyle();
cs.Name = &quot;Good&quot;;
cs.FormatId = 1;
cs.BuiltinId = 26;
css.Append(cs);

css.Count = (uint)css.ChildElements.Count;
ss.Append(css);


And then going back to the individual CellFormat with your &quot;Good&quot; styles (in particular, the background colour), set:

cf.FormatId = 1;

because the FormatId for the CellStyle is 1. I hope that&#039;s sufficient for you to work with.</description>
		<content:encoded><![CDATA[<p>Hi Sebastien, I&#8217;m afraid using the builtin styles aren&#8217;t as straightforward as you think (I was surprised too). From the MSDN:</p>
<p>&#8220;The built-in cell styles are written here by name, but the corresponding formatting records are assumed rather than explicitly written.&#8221;</p>
<p>What they mean is that setting some variable to index 26 or 27 is not enough to make that style the &#8220;Good&#8221; version or the &#8220;Bad&#8221; version. You still have to set the individual font, border, background colour and so on.</p>
<p>For example, you still have to create the (by default) Calibri font, green background colour for the &#8220;Good&#8221; builtin style. And then, you add this part:</p>
<p>CellStyles css = new CellStyles();<br />
CellStyle cs = new CellStyle();<br />
cs.Name = &#8220;Normal&#8221;;<br />
cs.FormatId = 0;<br />
cs.BuiltinId = 0;<br />
css.Append(cs);</p>
<p>cs = new CellStyle();<br />
cs.Name = &#8220;Good&#8221;;<br />
cs.FormatId = 1;<br />
cs.BuiltinId = 26;<br />
css.Append(cs);</p>
<p>css.Count = (uint)css.ChildElements.Count;<br />
ss.Append(css);</p>
<p>And then going back to the individual CellFormat with your &#8220;Good&#8221; styles (in particular, the background colour), set:</p>
<p>cf.FormatId = 1;</p>
<p>because the FormatId for the CellStyle is 1. I hope that&#8217;s sufficient for you to work with.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sebastien</title>
		<link>http://polymathprogrammer.com/2009/11/09/how-to-create-stylesheet-in-excel-open-xml/comment-page-1/#comment-34520</link>
		<dc:creator>Sebastien</dc:creator>
		<pubDate>Tue, 20 Jul 2010 13:55:49 +0000</pubDate>
		<guid isPermaLink="false">http://polymathprogrammer.com/?p=1645#comment-34520</guid>
		<description>Hello,

I have kind of same question as Vicky, but I would like to use the builtin styles.
According to MSDN (http://msdn.microsoft.com/en-us/library/documentformat.openxml.spreadsheet.cellstyle.aspx) there are pre-defined styles that could be used directly (unless I totally misunderstood...).
Basically, I would like to use styles at index 26 and 27 (Good and Bad) to quickly show correct and erroneous values I generate.

Infortunatly, settings the StyleIndex property of the Cell instances got me nowhere but to &quot;unreadable content&quot;.

If you understood, how to use builtins style, I would appreciate a lot some information.

Thanks in advance.</description>
		<content:encoded><![CDATA[<p>Hello,</p>
<p>I have kind of same question as Vicky, but I would like to use the builtin styles.<br />
According to MSDN (<a href="http://msdn.microsoft.com/en-us/library/documentformat.openxml.spreadsheet.cellstyle.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/documentformat.openxml.spreadsheet.cellstyle.aspx</a>) there are pre-defined styles that could be used directly (unless I totally misunderstood&#8230;).<br />
Basically, I would like to use styles at index 26 and 27 (Good and Bad) to quickly show correct and erroneous values I generate.</p>
<p>Infortunatly, settings the StyleIndex property of the Cell instances got me nowhere but to &#8220;unreadable content&#8221;.</p>
<p>If you understood, how to use builtins style, I would appreciate a lot some information.</p>
<p>Thanks in advance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vincent</title>
		<link>http://polymathprogrammer.com/2009/11/09/how-to-create-stylesheet-in-excel-open-xml/comment-page-1/#comment-34454</link>
		<dc:creator>Vincent</dc:creator>
		<pubDate>Fri, 25 Jun 2010 14:32:10 +0000</pubDate>
		<guid isPermaLink="false">http://polymathprogrammer.com/?p=1645#comment-34454</guid>
		<description>It&#039;s not *that* chim lah, Liu Lu...</description>
		<content:encoded><![CDATA[<p>It&#8217;s not *that* chim lah, Liu Lu&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: LIU LU</title>
		<link>http://polymathprogrammer.com/2009/11/09/how-to-create-stylesheet-in-excel-open-xml/comment-page-1/#comment-34452</link>
		<dc:creator>LIU LU</dc:creator>
		<pubDate>Fri, 25 Jun 2010 09:06:08 +0000</pubDate>
		<guid isPermaLink="false">http://polymathprogrammer.com/?p=1645#comment-34452</guid>
		<description>your code is too chim, must come to here, your blog, to understand how you create the custEBill logic. LOL</description>
		<content:encoded><![CDATA[<p>your code is too chim, must come to here, your blog, to understand how you create the custEBill logic. LOL</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vincent</title>
		<link>http://polymathprogrammer.com/2009/11/09/how-to-create-stylesheet-in-excel-open-xml/comment-page-1/#comment-34401</link>
		<dc:creator>Vincent</dc:creator>
		<pubDate>Fri, 11 Jun 2010 16:05:32 +0000</pubDate>
		<guid isPermaLink="false">http://polymathprogrammer.com/?p=1645#comment-34401</guid>
		<description>Hi Vicky, your

myCell.StyleIndex = 4;

means myCell gets the style given by the 5th CellFormat in the variable cfs (CellFormats class). So you should have at least 5 CellFormat class appended already. Then myCell will get the font style, border style and other styles in that 5th CellFormat.

Basically, you create a CellFormat class with all the styles you want. Then you set the StyleIndex property to the appropriate index of the CellFormats class (with all the CellFormat classes required).

Hope that helps.</description>
		<content:encoded><![CDATA[<p>Hi Vicky, your</p>
<p>myCell.StyleIndex = 4;</p>
<p>means myCell gets the style given by the 5th CellFormat in the variable cfs (CellFormats class). So you should have at least 5 CellFormat class appended already. Then myCell will get the font style, border style and other styles in that 5th CellFormat.</p>
<p>Basically, you create a CellFormat class with all the styles you want. Then you set the StyleIndex property to the appropriate index of the CellFormats class (with all the CellFormat classes required).</p>
<p>Hope that helps.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vicky</title>
		<link>http://polymathprogrammer.com/2009/11/09/how-to-create-stylesheet-in-excel-open-xml/comment-page-1/#comment-34400</link>
		<dc:creator>Vicky</dc:creator>
		<pubDate>Fri, 11 Jun 2010 14:07:59 +0000</pubDate>
		<guid isPermaLink="false">http://polymathprogrammer.com/?p=1645#comment-34400</guid>
		<description>Hi 

I am taking my first steps in Open XML Excel generation and I must say, it has not been easy to avoid &quot;unreadable content&quot;. Luckily with your site I  can get my content in there. But I am having trouble understanding the styling. How do you assign a specific style to a specific cell? What are the names/numbers of the styles? &#039;Cause if I try myCell.StyleIndex = 4; it just does not work. 

Thanks a lot in advance!</description>
		<content:encoded><![CDATA[<p>Hi </p>
<p>I am taking my first steps in Open XML Excel generation and I must say, it has not been easy to avoid &#8220;unreadable content&#8221;. Luckily with your site I  can get my content in there. But I am having trouble understanding the styling. How do you assign a specific style to a specific cell? What are the names/numbers of the styles? &#8216;Cause if I try myCell.StyleIndex = 4; it just does not work. </p>
<p>Thanks a lot in advance!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andy Cohen</title>
		<link>http://polymathprogrammer.com/2009/11/09/how-to-create-stylesheet-in-excel-open-xml/comment-page-1/#comment-6241</link>
		<dc:creator>Andy Cohen</dc:creator>
		<pubDate>Tue, 08 Dec 2009 17:56:46 +0000</pubDate>
		<guid isPermaLink="false">http://polymathprogrammer.com/?p=1645#comment-6241</guid>
		<description>Vince

Thanks so much that works great. I appreciate the help.  If you ever need a return favor drop an email.

Andy</description>
		<content:encoded><![CDATA[<p>Vince</p>
<p>Thanks so much that works great. I appreciate the help.  If you ever need a return favor drop an email.</p>
<p>Andy</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vincent</title>
		<link>http://polymathprogrammer.com/2009/11/09/how-to-create-stylesheet-in-excel-open-xml/comment-page-1/#comment-6238</link>
		<dc:creator>Vincent</dc:creator>
		<pubDate>Tue, 08 Dec 2009 15:02:32 +0000</pubDate>
		<guid isPermaLink="false">http://polymathprogrammer.com/?p=1645#comment-6238</guid>
		<description>Hi Andy, I plan to have a more sophisticated version of the stylesheet written some time later. If you&#039;re eager to know, you need to add one more border variable:

=====

Borders borders = new Borders();
Border border = new Border();
border.LeftBorder = new LeftBorder();
border.RightBorder = new RightBorder();
border.TopBorder = new TopBorder();
border.BottomBorder = new BottomBorder();
border.DiagonalBorder = new DiagonalBorder();
borders.Append(border);

border = new Border();
border.LeftBorder = new LeftBorder();
border.LeftBorder.Style = BorderStyleValues.Thin;
border.RightBorder = new RightBorder();
border.RightBorder.Style = BorderStyleValues.Thin;
border.TopBorder = new TopBorder();
border.TopBorder.Style = BorderStyleValues.Thin;
border.BottomBorder = new BottomBorder();
border.BottomBorder.Style = BorderStyleValues.Thin;
border.DiagonalBorder = new DiagonalBorder();
borders.Append(border);
borders.Count = UInt32Value.FromUInt32((uint)borders.ChildElements.Count);

=====

Then set the BorderId of the CellFormat you want to use to 1 (it&#039;s 0-based, so it takes on the border style of the second one). I set the top, right, bottom and left borders to &quot;thin&quot;. You can play around with the BorderStyleValues for more options.

cf.BorderId = 1;

As for the fill colour, try this when writing the &quot;Fill&quot; section:

=====
Fills fills = new Fills();
Fill fill;
PatternFill patternFill;

fill = new Fill();
patternFill = new PatternFill();
patternFill.PatternType = PatternValues.None;
fill.PatternFill = patternFill;
fills.Append(fill);

fill = new Fill();
patternFill = new PatternFill();
patternFill.PatternType = PatternValues.Gray125;
fill.PatternFill = patternFill;
fills.Append(fill);

fill = new Fill();
patternFill = new PatternFill();
patternFill.PatternType = PatternValues.Solid;
patternFill.ForegroundColor = new ForegroundColor();
patternFill.ForegroundColor.Rgb = HexBinaryValue.FromString(&quot;00c0c0c0&quot;);
patternFill.BackgroundColor = new BackgroundColor();
patternFill.BackgroundColor.Rgb = patternFill.ForegroundColor.Rgb;
fill.PatternFill = patternFill;
fills.Append(fill);

fills.Count = (uint)fills.ChildElements.Count;

=====
The third Fill is a solid colour, the foreground with a grey colour (hex ARGB 00c0c0c0), and the background colour is set to be the same as the foreground colour.

Then you set the FillId of the appropriate CellFormat you want as 2 (it&#039;s also 0-based).

cf.FillId = 2;


Just note that, the order of adding new borders and fills is important. Because it affects the index you&#039;re going to use for the respective property of the CellFormat.</description>
		<content:encoded><![CDATA[<p>Hi Andy, I plan to have a more sophisticated version of the stylesheet written some time later. If you&#8217;re eager to know, you need to add one more border variable:</p>
<p>=====</p>
<p>Borders borders = new Borders();<br />
Border border = new Border();<br />
border.LeftBorder = new LeftBorder();<br />
border.RightBorder = new RightBorder();<br />
border.TopBorder = new TopBorder();<br />
border.BottomBorder = new BottomBorder();<br />
border.DiagonalBorder = new DiagonalBorder();<br />
borders.Append(border);</p>
<p>border = new Border();<br />
border.LeftBorder = new LeftBorder();<br />
border.LeftBorder.Style = BorderStyleValues.Thin;<br />
border.RightBorder = new RightBorder();<br />
border.RightBorder.Style = BorderStyleValues.Thin;<br />
border.TopBorder = new TopBorder();<br />
border.TopBorder.Style = BorderStyleValues.Thin;<br />
border.BottomBorder = new BottomBorder();<br />
border.BottomBorder.Style = BorderStyleValues.Thin;<br />
border.DiagonalBorder = new DiagonalBorder();<br />
borders.Append(border);<br />
borders.Count = UInt32Value.FromUInt32((uint)borders.ChildElements.Count);</p>
<p>=====</p>
<p>Then set the BorderId of the CellFormat you want to use to 1 (it&#8217;s 0-based, so it takes on the border style of the second one). I set the top, right, bottom and left borders to &#8220;thin&#8221;. You can play around with the BorderStyleValues for more options.</p>
<p>cf.BorderId = 1;</p>
<p>As for the fill colour, try this when writing the &#8220;Fill&#8221; section:</p>
<p>=====<br />
Fills fills = new Fills();<br />
Fill fill;<br />
PatternFill patternFill;</p>
<p>fill = new Fill();<br />
patternFill = new PatternFill();<br />
patternFill.PatternType = PatternValues.None;<br />
fill.PatternFill = patternFill;<br />
fills.Append(fill);</p>
<p>fill = new Fill();<br />
patternFill = new PatternFill();<br />
patternFill.PatternType = PatternValues.Gray125;<br />
fill.PatternFill = patternFill;<br />
fills.Append(fill);</p>
<p>fill = new Fill();<br />
patternFill = new PatternFill();<br />
patternFill.PatternType = PatternValues.Solid;<br />
patternFill.ForegroundColor = new ForegroundColor();<br />
patternFill.ForegroundColor.Rgb = HexBinaryValue.FromString(&#8220;00c0c0c0&#8243;);<br />
patternFill.BackgroundColor = new BackgroundColor();<br />
patternFill.BackgroundColor.Rgb = patternFill.ForegroundColor.Rgb;<br />
fill.PatternFill = patternFill;<br />
fills.Append(fill);</p>
<p>fills.Count = (uint)fills.ChildElements.Count;</p>
<p>=====<br />
The third Fill is a solid colour, the foreground with a grey colour (hex ARGB 00c0c0c0), and the background colour is set to be the same as the foreground colour.</p>
<p>Then you set the FillId of the appropriate CellFormat you want as 2 (it&#8217;s also 0-based).</p>
<p>cf.FillId = 2;</p>
<p>Just note that, the order of adding new borders and fills is important. Because it affects the index you&#8217;re going to use for the respective property of the CellFormat.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andy Cohen</title>
		<link>http://polymathprogrammer.com/2009/11/09/how-to-create-stylesheet-in-excel-open-xml/comment-page-1/#comment-6231</link>
		<dc:creator>Andy Cohen</dc:creator>
		<pubDate>Mon, 07 Dec 2009 15:11:23 +0000</pubDate>
		<guid isPermaLink="false">http://polymathprogrammer.com/?p=1645#comment-6231</guid>
		<description>Vincent

This is a great spreadsheet and I got it up and running.  

The problem im having is I need to show bordered cells.  When I apply the sheet in your sample I get no borders?

Also I cannot seem to get the cells to fill wiht any color?

Any assistance would be greatly appreciated.

Thanks

Andy</description>
		<content:encoded><![CDATA[<p>Vincent</p>
<p>This is a great spreadsheet and I got it up and running.  </p>
<p>The problem im having is I need to show bordered cells.  When I apply the sheet in your sample I get no borders?</p>
<p>Also I cannot seem to get the cells to fill wiht any color?</p>
<p>Any assistance would be greatly appreciated.</p>
<p>Thanks</p>
<p>Andy</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vincent</title>
		<link>http://polymathprogrammer.com/2009/11/09/how-to-create-stylesheet-in-excel-open-xml/comment-page-1/#comment-6162</link>
		<dc:creator>Vincent</dc:creator>
		<pubDate>Wed, 02 Dec 2009 12:28:24 +0000</pubDate>
		<guid isPermaLink="false">http://polymathprogrammer.com/?p=1645#comment-6162</guid>
		<description>Hi Tim! It *did* take me a while to figure out all the stuff.

I know about the workbook template solution. My work just happens to deal with a lot of reports. Which will mean a lot of templates. Sometimes, an extra column needs to be added because the database schema changed. It&#039;s easier to make the change in code, than to find the template to change. In the long run, it&#039;s easier to maintain, since my experience tell me the developers in my office have difficulty working with non-code stuff, like Excel...

I have another article planned which takes the styling to a whole new level. You ain&#039;t see nothing yet... hahaha...

I will have a look at the ExtremeML. It might make my job easier. Thanks!</description>
		<content:encoded><![CDATA[<p>Hi Tim! It *did* take me a while to figure out all the stuff.</p>
<p>I know about the workbook template solution. My work just happens to deal with a lot of reports. Which will mean a lot of templates. Sometimes, an extra column needs to be added because the database schema changed. It&#8217;s easier to make the change in code, than to find the template to change. In the long run, it&#8217;s easier to maintain, since my experience tell me the developers in my office have difficulty working with non-code stuff, like Excel&#8230;</p>
<p>I have another article planned which takes the styling to a whole new level. You ain&#8217;t see nothing yet&#8230; hahaha&#8230;</p>
<p>I will have a look at the ExtremeML. It might make my job easier. Thanks!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

