snipt

Ctrl+h for KB shortcuts

C#

Hide Entire Column/Row in Excel using VSTO

1
2
3
4
5
6
7
8
9
//Microsoft.Office.Interop.Excel.Worksheet & Microsoft.Office.Tools.Excel.Worksheet are different.

Microsoft.Office.Interop.Excel.Worksheet activeSheet = (Microsoft.Office.Interop.Excel.Worksheet)Globals.ThisWorkbook.ActiveSheet;

activeSheet.get_Range("A1", System.Type.Missing).EntireColumn.Hidden = true;

//or

Microsoft.Office.Tools.Excel.Worksheet.InnerObject.get_Range("A1", System.Type.Missing).EntireRow.Hidden = true;
https://snipt.net/embed/645aec84b3c61af89c0f43a8161be280/
/raw/645aec84b3c61af89c0f43a8161be280/
645aec84b3c61af89c0f43a8161be280
csharp
C#
9
2019-06-18T10:38:07
True
False
False
/api/public/snipt/38043/
hide-entire-columnrow-using-vsto
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a> <a href="#L-8">8</a> <a href="#L-9">9</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="c1">//Microsoft.Office.Interop.Excel.Worksheet &amp; Microsoft.Office.Tools.Excel.Worksheet are different.</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="n">Microsoft</span><span class="p">.</span><span class="n">Office</span><span class="p">.</span><span class="n">Interop</span><span class="p">.</span><span class="n">Excel</span><span class="p">.</span><span class="n">Worksheet</span> <span class="n">activeSheet</span> <span class="p">=</span> <span class="p">(</span><span class="n">Microsoft</span><span class="p">.</span><span class="n">Office</span><span class="p">.</span><span class="n">Interop</span><span class="p">.</span><span class="n">Excel</span><span class="p">.</span><span class="n">Worksheet</span><span class="p">)</span><span class="n">Globals</span><span class="p">.</span><span class="n">ThisWorkbook</span><span class="p">.</span><span class="n">ActiveSheet</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a><span class="n">activeSheet</span><span class="p">.</span><span class="n">get_Range</span><span class="p">(</span><span class="s">&quot;A1&quot;</span><span class="p">,</span> <span class="n">System</span><span class="p">.</span><span class="n">Type</span><span class="p">.</span><span class="n">Missing</span><span class="p">).</span><span class="n">EntireColumn</span><span class="p">.</span><span class="n">Hidden</span> <span class="p">=</span> <span class="k">true</span><span class="p">;</span> </span><span id="L-6"><a name="L-6"></a> </span><span id="L-7"><a name="L-7"></a><span class="c1">//or</span> </span><span id="L-8"><a name="L-8"></a> </span><span id="L-9"><a name="L-9"></a><span class="n">Microsoft</span><span class="p">.</span><span class="n">Office</span><span class="p">.</span><span class="n">Tools</span><span class="p">.</span><span class="n">Excel</span><span class="p">.</span><span class="n">Worksheet</span><span class="p">.</span><span class="n">InnerObject</span><span class="p">.</span><span class="n">get_Range</span><span class="p">(</span><span class="s">&quot;A1&quot;</span><span class="p">,</span> <span class="n">System</span><span class="p">.</span><span class="n">Type</span><span class="p">.</span><span class="n">Missing</span><span class="p">).</span><span class="n">EntireRow</span><span class="p">.</span><span class="n">Hidden</span> <span class="p">=</span> <span class="k">true</span><span class="p">;</span> </span></pre></div> </td></tr></table>
excel, vsto