<?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: Improved NPOI ExportToExcel Function</title>
	<atom:link href="http://www.zachhunter.com/2010/06/improved-npoi-exportdatatabletoexcel-function/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.zachhunter.com/2010/06/improved-npoi-exportdatatabletoexcel-function/</link>
	<description>Random Brain Drool</description>
	<lastBuildDate>Thu, 02 Feb 2012 20:52:19 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Zach</title>
		<link>http://www.zachhunter.com/2010/06/improved-npoi-exportdatatabletoexcel-function/comment-page-1/#comment-510</link>
		<dc:creator>Zach</dc:creator>
		<pubDate>Thu, 23 Jun 2011 22:05:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.zachhunter.com/?p=330#comment-510</guid>
		<description>Matt,

I think most things can be done via NPOI, I usually use the POI Java Docs when I&#039;m looking for something because I find them easier to search/navigate.

http://poi.apache.org/apidocs/overview-summary.html

I&#039;ve also ported over a few bug fixes to NPOI, but in general Tony, the NPOI project creator is getting the bug fixes applied really quick and is always watching the forum/bug reports.  If you find something broken, posting in the discussion/bug thread on NPOI CodePlex page is a good place to report it.  You can also look at POI forums, cause you might see it was also found and fixed there.  I was on my own custom build of NPOI for awhile, but as of 1.2.3 I&#039;m back on the official build.  I don&#039;t think I have any changes in my current production built, but I tweak things so often it&#039;s hard to remember what I did in weeks prior.</description>
		<content:encoded><![CDATA[<p>Matt,</p>
<p>I think most things can be done via NPOI, I usually use the POI Java Docs when I&#8217;m looking for something because I find them easier to search/navigate.</p>
<p><a href="http://poi.apache.org/apidocs/overview-summary.html" rel="nofollow">http://poi.apache.org/apidocs/overview-summary.html</a></p>
<p>I&#8217;ve also ported over a few bug fixes to NPOI, but in general Tony, the NPOI project creator is getting the bug fixes applied really quick and is always watching the forum/bug reports.  If you find something broken, posting in the discussion/bug thread on NPOI CodePlex page is a good place to report it.  You can also look at POI forums, cause you might see it was also found and fixed there.  I was on my own custom build of NPOI for awhile, but as of 1.2.3 I&#8217;m back on the official build.  I don&#8217;t think I have any changes in my current production built, but I tweak things so often it&#8217;s hard to remember what I did in weeks prior.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt</title>
		<link>http://www.zachhunter.com/2010/06/improved-npoi-exportdatatabletoexcel-function/comment-page-1/#comment-509</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Thu, 23 Jun 2011 21:53:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.zachhunter.com/?p=330#comment-509</guid>
		<description>Hi Zach, sorry I wasn&#039;t more specific. I was referring to Excel&#039;s AutoFilter feature as found in Excel&#039;s menu:  Data &gt; Filter &gt; AutoFilter.  Using an excel template that has column names already entered in the spreadsheet, you can turn on the AutoFilter feature in the template, and then it works as expected after you use NPOI to fill the rows beneath the header. But if you&#039;re building your header via NPOI, then can you use NPOI to generate Excel&#039;s AutoFilter feature? I see NPOI has an HSSFAutoFilter...wait...just looking again, and it appears you can call a &quot;SetAutoFilter()&quot; function by passing a CellRangeAddress. I haven&#039;t read the &quot;how to&quot; for these...</description>
		<content:encoded><![CDATA[<p>Hi Zach, sorry I wasn&#8217;t more specific. I was referring to Excel&#8217;s AutoFilter feature as found in Excel&#8217;s menu:  Data &gt; Filter &gt; AutoFilter.  Using an excel template that has column names already entered in the spreadsheet, you can turn on the AutoFilter feature in the template, and then it works as expected after you use NPOI to fill the rows beneath the header. But if you&#8217;re building your header via NPOI, then can you use NPOI to generate Excel&#8217;s AutoFilter feature? I see NPOI has an HSSFAutoFilter&#8230;wait&#8230;just looking again, and it appears you can call a &#8220;SetAutoFilter()&#8221; function by passing a CellRangeAddress. I haven&#8217;t read the &#8220;how to&#8221; for these&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zach</title>
		<link>http://www.zachhunter.com/2010/06/improved-npoi-exportdatatabletoexcel-function/comment-page-1/#comment-508</link>
		<dc:creator>Zach</dc:creator>
		<pubDate>Thu, 23 Jun 2011 19:56:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.zachhunter.com/?p=330#comment-508</guid>
		<description>Matt, what do you mean by AutoFilter?  I commonly filter my results by applying filters/sorts on my DataTable.DefaultView, which then gets sent to my ExportToExcel() function.  This way I can chop up and display the same results in a few different ways, without have to re-query the DB (e.g. DataTable.DefaultView.RowFilter = &quot;Column1 = &#039;Apple&#039;&quot;;).  Don&#039;t forget, when you apply filters/sorts, you want to then use the DataTable.DefaultView.ToTable() to get the new slice/view of data.</description>
		<content:encoded><![CDATA[<p>Matt, what do you mean by AutoFilter?  I commonly filter my results by applying filters/sorts on my DataTable.DefaultView, which then gets sent to my ExportToExcel() function.  This way I can chop up and display the same results in a few different ways, without have to re-query the DB (e.g. DataTable.DefaultView.RowFilter = &#8220;Column1 = &#8216;Apple&#8217;&#8221;;).  Don&#8217;t forget, when you apply filters/sorts, you want to then use the DataTable.DefaultView.ToTable() to get the new slice/view of data.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt</title>
		<link>http://www.zachhunter.com/2010/06/improved-npoi-exportdatatabletoexcel-function/comment-page-1/#comment-507</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Thu, 23 Jun 2011 19:02:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.zachhunter.com/?p=330#comment-507</guid>
		<description>Is it possible to add AutoFilter to the function?</description>
		<content:encoded><![CDATA[<p>Is it possible to add AutoFilter to the function?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt</title>
		<link>http://www.zachhunter.com/2010/06/improved-npoi-exportdatatabletoexcel-function/comment-page-1/#comment-476</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Sat, 11 Jun 2011 21:15:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.zachhunter.com/?p=330#comment-476</guid>
		<description>Thanks; this will be good to refer back to if the database hits are too heavy. 

Another issue worth noting: while filing the excel template using NPOI&#039;s &quot;Get...&quot; syntax, an issue arose where the cell format in the XLS template, which started out as &quot;General&quot;, was not being treated as a number after data-fill. The cells with integers were generating Excel&#039;s little cell formatting &quot;green triangle&quot; warning. And the charts relying on those integers were then failing to display. As a result, I tweaked the CASE statement for System.Int to convert back to Int, as opposed to string. 
After that, no more cell warning messages appeared, and the charts loaded.


[code]

        Public Shared Sub ExcelUpdateRow(ByVal _myDataTable As DataTable, ByVal _sheet As HSSFSheet)

            Dim rowIndex As Integer = 1

            For Each row As DataRow In _myDataTable.Rows

                Dim dataRow As HSSFRow = CType(_sheet.GetRow(rowIndex), HSSFRow)
                For Each column As DataColumn In _myDataTable.Columns

                    &#039; dataRow.GetCell(column.Ordinal).SetCellValue(row(column).ToString())

                    Select Case column.DataType.FullName
                        Case &quot;System.String&quot;
                            dataRow.GetCell(column.Ordinal).SetCellValue(row(column).ToString())
                            Exit Select
                        Case &quot;System.Double&quot;, &quot;System.Decimal&quot;
                            dataRow.GetCell(column.Ordinal).SetCellValue([Double].Parse(row(column).ToString()))
                            [Double].Parse(row(column).ToString())
                            Exit Select
                        Case &quot;System.Int&quot;, &quot;System.Int32&quot;, &quot;System.Int64&quot;
                            dataRow.GetCell(column.Ordinal).SetCellValue(CInt(row(column).ToString()))
                            Exit Select
                        Case Else
                            dataRow.GetCell(column.Ordinal).SetCellValue(row(column).ToString())
                            Exit Select
                    End Select
                Next
                rowIndex += 1
            Next

        End Sub
[/code]</description>
		<content:encoded><![CDATA[<p>Thanks; this will be good to refer back to if the database hits are too heavy. </p>
<p>Another issue worth noting: while filing the excel template using NPOI&#8217;s &#8220;Get&#8230;&#8221; syntax, an issue arose where the cell format in the XLS template, which started out as &#8220;General&#8221;, was not being treated as a number after data-fill. The cells with integers were generating Excel&#8217;s little cell formatting &#8220;green triangle&#8221; warning. And the charts relying on those integers were then failing to display. As a result, I tweaked the CASE statement for System.Int to convert back to Int, as opposed to string.<br />
After that, no more cell warning messages appeared, and the charts loaded.</p>
<pre class="brush: plain; title: ; notranslate">

        Public Shared Sub ExcelUpdateRow(ByVal _myDataTable As DataTable, ByVal _sheet As HSSFSheet)

            Dim rowIndex As Integer = 1

            For Each row As DataRow In _myDataTable.Rows

                Dim dataRow As HSSFRow = CType(_sheet.GetRow(rowIndex), HSSFRow)
                For Each column As DataColumn In _myDataTable.Columns

                    ' dataRow.GetCell(column.Ordinal).SetCellValue(row(column).ToString())

                    Select Case column.DataType.FullName
                        Case &quot;System.String&quot;
                            dataRow.GetCell(column.Ordinal).SetCellValue(row(column).ToString())
                            Exit Select
                        Case &quot;System.Double&quot;, &quot;System.Decimal&quot;
                            dataRow.GetCell(column.Ordinal).SetCellValue([Double].Parse(row(column).ToString()))
                            [Double].Parse(row(column).ToString())
                            Exit Select
                        Case &quot;System.Int&quot;, &quot;System.Int32&quot;, &quot;System.Int64&quot;
                            dataRow.GetCell(column.Ordinal).SetCellValue(CInt(row(column).ToString()))
                            Exit Select
                        Case Else
                            dataRow.GetCell(column.Ordinal).SetCellValue(row(column).ToString())
                            Exit Select
                    End Select
                Next
                rowIndex += 1
            Next

        End Sub
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zach</title>
		<link>http://www.zachhunter.com/2010/06/improved-npoi-exportdatatabletoexcel-function/comment-page-1/#comment-475</link>
		<dc:creator>Zach</dc:creator>
		<pubDate>Sat, 11 Jun 2011 17:17:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.zachhunter.com/?p=330#comment-475</guid>
		<description>Good question, personally I cache all my hits to the db for a few minutes... This way I can load the XLS file without pulling the data from the DB again.  The only time this could be an issue, is when there is LOTS of data.  When this happens, I limit the web based query to only provide the top 500 results and force the user to use the download button to access all the rows.  Most people prefer to use EXCEL to review lots of data (1K+ rows).

As for why your DataTable results aren&#039;t matching... I&#039;m not sure without a little more information, but here is what I normally do when I pull the data and want to use it multiple times.

This example is simplified, normally I would pass criteria to the GetData() and use the criteria in the &quot;cacheKey&quot; variable.

[sourcecode language=&quot;c-sharp&quot;]

        private DataTable GetData()
        {
            DataTable dt;

            string cacheKey = &quot;Key Based on Criteria&quot;;

            if (Cache[cacheKey] != null)
            {
                dt = (DataTable)Cache[cacheKey];
            }
            else
            {
                // Get Your DataTable Here
                Cache.Add(cacheKey, dt, null, DateTime.Now.AddMinutes(5), Cache.NoSlidingExpiration,
                          CacheItemPriority.Low, null);
            }

            return dt;
        }
    
    // Here is how I call this method and use the DataTable that came from DB or Cache if it has previously been queried.
    DataTable dt = GetData();

[/sourcecode]


Hope this helps, let me know if you have questions.</description>
		<content:encoded><![CDATA[<p>Good question, personally I cache all my hits to the db for a few minutes&#8230; This way I can load the XLS file without pulling the data from the DB again.  The only time this could be an issue, is when there is LOTS of data.  When this happens, I limit the web based query to only provide the top 500 results and force the user to use the download button to access all the rows.  Most people prefer to use EXCEL to review lots of data (1K+ rows).</p>
<p>As for why your DataTable results aren&#8217;t matching&#8230; I&#8217;m not sure without a little more information, but here is what I normally do when I pull the data and want to use it multiple times.</p>
<p>This example is simplified, normally I would pass criteria to the GetData() and use the criteria in the &#8220;cacheKey&#8221; variable.</p>
<pre class="brush: csharp; title: ; notranslate">

        private DataTable GetData()
        {
            DataTable dt;

            string cacheKey = &quot;Key Based on Criteria&quot;;

            if (Cache[cacheKey] != null)
            {
                dt = (DataTable)Cache[cacheKey];
            }
            else
            {
                // Get Your DataTable Here
                Cache.Add(cacheKey, dt, null, DateTime.Now.AddMinutes(5), Cache.NoSlidingExpiration,
                          CacheItemPriority.Low, null);
            }

            return dt;
        }

    // Here is how I call this method and use the DataTable that came from DB or Cache if it has previously been queried.
    DataTable dt = GetData();
</pre>
<p>Hope this helps, let me know if you have questions.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt</title>
		<link>http://www.zachhunter.com/2010/06/improved-npoi-exportdatatabletoexcel-function/comment-page-1/#comment-474</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Sat, 11 Jun 2011 06:03:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.zachhunter.com/?p=330#comment-474</guid>
		<description>These functions are very useful. I&#039;m wondering what your strategies are for implementing them? If I&#039;m using a DataSet and  multiple DataTables, do these functions always have to be called on the Page_Load event? 

For instance, if you have a web page, and then a report version of that same web page, do you re-query the database and open a new page, or do you work with a copy of the DataTable that&#039;s part of the web page? 

Independent of NPOI, I&#039;m running into an issue where the DataTable from the Page_Load event pulls all the correct data, but a DataTable from a DataTable variable in code behind isn&#039;t putting out the data correctly.  (Sorry for yet another question... )</description>
		<content:encoded><![CDATA[<p>These functions are very useful. I&#8217;m wondering what your strategies are for implementing them? If I&#8217;m using a DataSet and  multiple DataTables, do these functions always have to be called on the Page_Load event? </p>
<p>For instance, if you have a web page, and then a report version of that same web page, do you re-query the database and open a new page, or do you work with a copy of the DataTable that&#8217;s part of the web page? </p>
<p>Independent of NPOI, I&#8217;m running into an issue where the DataTable from the Page_Load event pulls all the correct data, but a DataTable from a DataTable variable in code behind isn&#8217;t putting out the data correctly.  (Sorry for yet another question&#8230; )</p>
]]></content:encoded>
	</item>
</channel>
</rss>

