<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>The Woes of Excel's Optional Parameters and C# ... a (potential) Workaround </title><link>http://blogs.msdn.com/gabhan_berry/archive/2008/02/06/excel-s-optional-parameters-and-missing-value-a-c-workaround.aspx</link><description>When coding in C# with Excel, it doesn't take long before you encounter the dreaded 'optional parameter' issue. If you have ever copied-and-pasted numerous System.Reflection. Missing .Value statements then you've probably wondered a few things. Firstly,</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: The Woes of Excel's Optional Parameters and C# ... a (potential) Workaround </title><link>http://blogs.msdn.com/gabhan_berry/archive/2008/02/06/excel-s-optional-parameters-and-missing-value-a-c-workaround.aspx#7517929</link><pubDate>Thu, 07 Feb 2008 18:04:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7517929</guid><dc:creator>XL-Dennis</dc:creator><description>&lt;p&gt;Nice solution which I noew have implemented in my own C# managed add-in template.&lt;/p&gt;
&lt;p&gt;Thanks and keep up the good level,&lt;/p&gt;
&lt;p&gt;Dennis&lt;/p&gt;
</description></item><item><title>re: The Woes of Excel's Optional Parameters and C# ... a (potential) Workaround </title><link>http://blogs.msdn.com/gabhan_berry/archive/2008/02/06/excel-s-optional-parameters-and-missing-value-a-c-workaround.aspx#7537163</link><pubDate>Fri, 08 Feb 2008 12:05:01 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7537163</guid><dc:creator>Johan Nordberg</dc:creator><description>&lt;p&gt;It not just the Type.Missing. It's all the ref parameters as well. You can't just have true/false as a parameter, you have to have that as a variable and use &amp;quot;ref myVar&amp;quot;. Yuck!&lt;/p&gt;
&lt;p&gt;It's too sad that a good fix for this isn't in the PIA or in some other way included in VSTO. The C# templates could have overloaded methods. I'm sure you could generate this from the typelibraries and included it in VSTO.&lt;/p&gt;
&lt;p&gt;Atleast for the common things like Workbook.Open, Save, Application.Intersect, Union, many range methods etc. &lt;/p&gt;
&lt;p&gt;If it's to bloated with 32 overloads on a single method, maybe you could have 2 overload, one with the most common scenario, like Workbook.Open(filename) and one with Workbook.Open(filename, paramarray[] params)&lt;/p&gt;
&lt;p&gt;I love C#, but for Office development I use VB.Net because it's impossible to write clean code with this ref Type.Missing madness.&lt;/p&gt;
&lt;p&gt;If the Office platform should be a professional developer platform I think you must target C# developers in a better way than today. As I see it, Office developments needs VB.Net today. But I like C# alot better than VB.&lt;/p&gt;</description></item><item><title>re: The Woes of Excel's Optional Parameters and C# ... a (potential) Workaround </title><link>http://blogs.msdn.com/gabhan_berry/archive/2008/02/06/excel-s-optional-parameters-and-missing-value-a-c-workaround.aspx#7537188</link><pubDate>Fri, 08 Feb 2008 12:06:04 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7537188</guid><dc:creator>Johan Nordberg</dc:creator><description>&lt;p&gt;Btw... The really bad thing with reflection is that you don't get IntelliSense and compile time error checking. And isn't relection alot slower since it's evaluated at runtime?&lt;/p&gt;</description></item><item><title>Using C# 3.0 Extension Methods to make life easier when using optional parameters in Office PIAs</title><link>http://blogs.msdn.com/gabhan_berry/archive/2008/02/06/excel-s-optional-parameters-and-missing-value-a-c-workaround.aspx#7953189</link><pubDate>Fri, 29 Feb 2008 20:11:26 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7953189</guid><dc:creator>Noticias externas</dc:creator><description>&lt;p&gt;Gabhan Berry (read his blog - he has lots of Excel programmability related information in there!) wrote&lt;/p&gt;
</description></item><item><title>Analysing Column Data using C# (... with a little Custom Drawing thrown in for fun) </title><link>http://blogs.msdn.com/gabhan_berry/archive/2008/02/06/excel-s-optional-parameters-and-missing-value-a-c-workaround.aspx#8156962</link><pubDate>Tue, 11 Mar 2008 21:24:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8156962</guid><dc:creator>Gabhan Berry: Excel Programming  </dc:creator><description>&lt;p&gt;When presented with a table of data in Excel, sometimes it is useful to be able to learn some quick facts&lt;/p&gt;</description></item><item><title>re: The Woes of Excel's Optional Parameters and C# ... a (potential) Workaround </title><link>http://blogs.msdn.com/gabhan_berry/archive/2008/02/06/excel-s-optional-parameters-and-missing-value-a-c-workaround.aspx#8375300</link><pubDate>Thu, 10 Apr 2008 18:59:20 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8375300</guid><dc:creator>Gabhan Berry</dc:creator><description>&lt;p&gt;Johan, yes ... reflection is slow so we should avoid (if we can) using reflection too often. Gauging what is too often and what is not is something I think we each need to decide ourselves, based on our own application's requirements. &lt;/p&gt;
</description></item><item><title>How to code a .NET RefEdit Control</title><link>http://blogs.msdn.com/gabhan_berry/archive/2008/02/06/excel-s-optional-parameters-and-missing-value-a-c-workaround.aspx#8649550</link><pubDate>Wed, 25 Jun 2008 01:57:13 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8649550</guid><dc:creator>Excel Programming  </dc:creator><description>&lt;p&gt;One of the controls frequently used by Excel is the reference edit box. This control is used to gather&lt;/p&gt;
</description></item><item><title>re: The Woes of Excel's Optional Parameters and C# ... a (potential) Workaround </title><link>http://blogs.msdn.com/gabhan_berry/archive/2008/02/06/excel-s-optional-parameters-and-missing-value-a-c-workaround.aspx#8671770</link><pubDate>Mon, 30 Jun 2008 19:53:58 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8671770</guid><dc:creator>Mark Southern</dc:creator><description>&lt;p&gt;Thank you! This will come in very handy!&lt;/p&gt;
&lt;p&gt;There are also situations where you might not want to have a reference to Microsoft.Office.Interop.Excel in your code. In these circumstances, the following code could be a useful addition (in which case, your &amp;quot;Address&amp;quot; example comes down to:&lt;/p&gt;
&lt;p&gt;string addr = ExcelUtility.RangeInvoke&amp;lt;string&amp;gt;(excelApp.Selection, &amp;quot;Address&amp;quot;, null, null, ExcelUtility.FieldValue(&amp;quot;XlReferenceStyle&amp;quot;,&amp;quot;xlA1&amp;quot;));&lt;/p&gt;
&lt;p&gt;)&lt;/p&gt;
&lt;p&gt;//...&lt;/p&gt;
&lt;p&gt;public static Type ExcelType(String name)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Type t = System.Reflection.Assembly.Load(&amp;quot;Microsoft.Office.Interop.Excel&amp;quot;).GetType(&amp;quot;Microsoft.Office.Interop.Excel.&amp;quot; + name, true, true);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return t;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public static object FieldValue(string typeName, string fieldName)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Type t = ExcelType(typeName);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;FieldInfo fi = t.GetField(fieldName);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return fi.GetValue(t);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public static TRet Invoke&amp;lt;TRet&amp;gt;(object Obj, string TypeName, string MethodName, params object[] CallerParams) where TRet : class&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return Invoke&amp;lt;TRet&amp;gt;(Obj, ExcelType(TypeName), MethodName, CallerParams);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;</description></item></channel></rss>