<?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/"
	xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments for Rashid's</title>
	<atom:link href="http://itsrashid.wordpress.com/comments/feed/" rel="self" type="application/rss+xml" />
	<link>http://itsrashid.wordpress.com</link>
	<description>I will be happy if anything from here helps someone...</description>
	<lastBuildDate>Mon, 09 Nov 2009 13:51:59 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>Comment on Export DataSet to Excel in C# by Neji</title>
		<link>http://itsrashid.wordpress.com/2007/05/14/export-dataset-to-excel-in-c/#comment-338</link>
		<dc:creator>Neji</dc:creator>
		<pubDate>Mon, 09 Nov 2009 13:51:59 +0000</pubDate>
		<guid isPermaLink="false">http://itsrashid.wordpress.com/2007/05/14/export-dataset-to-excel-in-c/#comment-338</guid>
		<description>C# Exporting a (full) Dataset to Excel (with worksheets and all)

Hi All.

I just thought I&#039;d past this code that is collected and modified.
It&#039;s from a whole lot of ppl that I can&#039;t really remember who actually made it, but it work (give credit to the dude(s) out there whose name(s) I can&#039;t remember. hehe)
(this code is just to help you get started, feel free to change and improve it as you see fit.) ^_^

Step 1: Create new Class and copy code below.

using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.IO;
using Microsoft.Office.Interop.Excel;
using System.Data;

namespace VGS
{
    class ClassExcel
    {
        private String m_sFileName;

        Application excelApp = null;
        Workbook workbook = null;
        Sheets sheets = null;
        Worksheet newSheet = null;

        public ClassExcel(String p_sFileName)
        {
            m_sFileName = p_sFileName;
        }

        public void ChangeFileName(String p_sFileName)
        {
            m_sFileName = p_sFileName;
        }

        public void SaveDatasetToExcel(DataSet p_dts)
        {
            try
            {
                if (File.Exists(m_sFileName))
                {
                    File.Delete(m_sFileName);
                }
                if (File.Exists(m_sFileName) == false)
                {
                    MakeTemp(m_sFileName);
                }
                

                if (File.Exists(m_sFileName))
                {
                    DataSet dts = new DataSet();
                    dts = p_dts;

                    excelApp = new Application();
                    workbook = excelApp.Workbooks.Open(m_sFileName, 0, false, 5, &quot;&quot;, &quot;&quot;,
                                                        false, XlPlatform.xlWindows, &quot;&quot;,
                                                        true, false, 0, true, false, false);

                    sheets = workbook.Sheets;

                    foreach (Worksheet sheet in sheets)
                    {
                        sheet.Select(Type.Missing);

                        System.Runtime.InteropServices.Marshal.ReleaseComObject(sheet);
                    }

                    
                    for (int iTable = 0; iTable  0)
                        {
                            newSheet = (Worksheet)sheets.Add(sheets[1], Type.Missing, Type.Missing, Type.Missing);
                            newSheet.Name = dts.Tables[iTable].TableName;
                            for (int cc = 0; cc &lt; dts.Tables[iTable].Columns.Count; cc++)
                            {
                                newSheet.Cells[1, cc + 1] = &quot;&#039;&quot; + dts.Tables[iTable].Columns[cc].ColumnName;
                            }

                            for (int cc = 0; cc &lt; dts.Tables[iTable].Columns.Count; cc++)
                            {
                                for (int rc = 0; rc &lt; dts.Tables[iTable].Rows.Count; rc++)
                                {
                                    if (dts.Tables[iTable].Rows[rc][cc] == null)
                                        newSheet.Cells[rc, cc] = &quot;&quot;;

                                    if (dts.Tables[iTable].Columns[cc].DataType == System.Type.GetType(&quot;System.String&quot;))
                                    {
                                        newSheet.Cells[rc + 2, cc + 1] = &quot;&#039;&quot; + dts.Tables[iTable].Rows[rc][cc];
                                    }
                                    else
                                    {
                                        newSheet.Cells[rc + 2, cc + 1] = dts.Tables[iTable].Rows[rc][cc];
                                    }
                                }
                            }
                        }
                    }

                    workbook.Save();
                    workbook.Close(null, null, null);
                    excelApp.Quit(); 
                } 
            }
            finally
            {
                newSheet = null;
                sheets = null;
                workbook = null;
                excelApp = null;

                GC.Collect();
            }
        }

        private void MakeTemp(string p_sTempFileName)
        {
            Application exc = null;
            try
            {
                exc = new Application();
                Workbooks workbooks = exc.Workbooks;
                _Workbook workbook = workbooks.Add(XlWBATemplate.xlWBATWorksheet);
                _Worksheet worksheet = (_Worksheet)workbook.Worksheets[1];
                Range range = worksheet.get_Range(&quot;A1&quot;, System.Reflection.Missing.Value);
                Object[] data = new Object[] { &quot;&quot; };
                range.GetType().InvokeMember(&quot;Value&quot;, System.Reflection.BindingFlags.SetProperty, null, range, data);
                workbook.Close(true, p_sTempFileName, null);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.ReadLine();
            }
            finally
            {
                if (exc != null)
                    exc.Quit();
            }
        }
    }
}

ps. remember to add the reference:
&quot;using Microsoft.Office.Interop.Excel;&quot;
to your project;

Step 2: Done. lol

cheers.</description>
		<content:encoded><![CDATA[<p>C# Exporting a (full) Dataset to Excel (with worksheets and all)</p>
<p>Hi All.</p>
<p>I just thought I&#8217;d past this code that is collected and modified.<br />
It&#8217;s from a whole lot of ppl that I can&#8217;t really remember who actually made it, but it work (give credit to the dude(s) out there whose name(s) I can&#8217;t remember. hehe)<br />
(this code is just to help you get started, feel free to change and improve it as you see fit.) ^_^</p>
<p>Step 1: Create new Class and copy code below.</p>
<p>using System;<br />
using System.Collections.Generic;<br />
using System.Text;<br />
using System.Reflection;<br />
using System.IO;<br />
using Microsoft.Office.Interop.Excel;<br />
using System.Data;</p>
<p>namespace VGS<br />
{<br />
    class ClassExcel<br />
    {<br />
        private String m_sFileName;</p>
<p>        Application excelApp = null;<br />
        Workbook workbook = null;<br />
        Sheets sheets = null;<br />
        Worksheet newSheet = null;</p>
<p>        public ClassExcel(String p_sFileName)<br />
        {<br />
            m_sFileName = p_sFileName;<br />
        }</p>
<p>        public void ChangeFileName(String p_sFileName)<br />
        {<br />
            m_sFileName = p_sFileName;<br />
        }</p>
<p>        public void SaveDatasetToExcel(DataSet p_dts)<br />
        {<br />
            try<br />
            {<br />
                if (File.Exists(m_sFileName))<br />
                {<br />
                    File.Delete(m_sFileName);<br />
                }<br />
                if (File.Exists(m_sFileName) == false)<br />
                {<br />
                    MakeTemp(m_sFileName);<br />
                }</p>
<p>                if (File.Exists(m_sFileName))<br />
                {<br />
                    DataSet dts = new DataSet();<br />
                    dts = p_dts;</p>
<p>                    excelApp = new Application();<br />
                    workbook = excelApp.Workbooks.Open(m_sFileName, 0, false, 5, &#8220;&#8221;, &#8220;&#8221;,<br />
                                                        false, XlPlatform.xlWindows, &#8220;&#8221;,<br />
                                                        true, false, 0, true, false, false);</p>
<p>                    sheets = workbook.Sheets;</p>
<p>                    foreach (Worksheet sheet in sheets)<br />
                    {<br />
                        sheet.Select(Type.Missing);</p>
<p>                        System.Runtime.InteropServices.Marshal.ReleaseComObject(sheet);<br />
                    }</p>
<p>                    for (int iTable = 0; iTable  0)<br />
                        {<br />
                            newSheet = (Worksheet)sheets.Add(sheets[1], Type.Missing, Type.Missing, Type.Missing);<br />
                            newSheet.Name = dts.Tables[iTable].TableName;<br />
                            for (int cc = 0; cc &lt; dts.Tables[iTable].Columns.Count; cc++)<br />
                            {<br />
                                newSheet.Cells[1, cc + 1] = &quot;&#039;&quot; + dts.Tables[iTable].Columns[cc].ColumnName;<br />
                            }</p>
<p>                            for (int cc = 0; cc &lt; dts.Tables[iTable].Columns.Count; cc++)<br />
                            {<br />
                                for (int rc = 0; rc &lt; dts.Tables[iTable].Rows.Count; rc++)<br />
                                {<br />
                                    if (dts.Tables[iTable].Rows[rc][cc] == null)<br />
                                        newSheet.Cells[rc, cc] = &quot;&quot;;</p>
<p>                                    if (dts.Tables[iTable].Columns[cc].DataType == System.Type.GetType(&quot;System.String&quot;))<br />
                                    {<br />
                                        newSheet.Cells[rc + 2, cc + 1] = &quot;&#039;&quot; + dts.Tables[iTable].Rows[rc][cc];<br />
                                    }<br />
                                    else<br />
                                    {<br />
                                        newSheet.Cells[rc + 2, cc + 1] = dts.Tables[iTable].Rows[rc][cc];<br />
                                    }<br />
                                }<br />
                            }<br />
                        }<br />
                    }</p>
<p>                    workbook.Save();<br />
                    workbook.Close(null, null, null);<br />
                    excelApp.Quit();<br />
                }<br />
            }<br />
            finally<br />
            {<br />
                newSheet = null;<br />
                sheets = null;<br />
                workbook = null;<br />
                excelApp = null;</p>
<p>                GC.Collect();<br />
            }<br />
        }</p>
<p>        private void MakeTemp(string p_sTempFileName)<br />
        {<br />
            Application exc = null;<br />
            try<br />
            {<br />
                exc = new Application();<br />
                Workbooks workbooks = exc.Workbooks;<br />
                _Workbook workbook = workbooks.Add(XlWBATemplate.xlWBATWorksheet);<br />
                _Worksheet worksheet = (_Worksheet)workbook.Worksheets[1];<br />
                Range range = worksheet.get_Range(&quot;A1&quot;, System.Reflection.Missing.Value);<br />
                Object[] data = new Object[] { &quot;&quot; };<br />
                range.GetType().InvokeMember(&quot;Value&quot;, System.Reflection.BindingFlags.SetProperty, null, range, data);<br />
                workbook.Close(true, p_sTempFileName, null);<br />
            }<br />
            catch (Exception ex)<br />
            {<br />
                Console.WriteLine(ex.Message);<br />
                Console.ReadLine();<br />
            }<br />
            finally<br />
            {<br />
                if (exc != null)<br />
                    exc.Quit();<br />
            }<br />
        }<br />
    }<br />
}</p>
<p>ps. remember to add the reference:<br />
&quot;using Microsoft.Office.Interop.Excel;&quot;<br />
to your project;</p>
<p>Step 2: Done. lol</p>
<p>cheers.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Export DataSet to Excel in C# by Laurent</title>
		<link>http://itsrashid.wordpress.com/2007/05/14/export-dataset-to-excel-in-c/#comment-336</link>
		<dc:creator>Laurent</dc:creator>
		<pubDate>Wed, 30 Sep 2009 06:16:40 +0000</pubDate>
		<guid isPermaLink="false">http://itsrashid.wordpress.com/2007/05/14/export-dataset-to-excel-in-c/#comment-336</guid>
		<description>hello, your code works fine and it&#039;s easy but he have tow BIG problem to use the data in excel :

1) ALL the data are in STRING, how to keep the type of the data ?

2) How to prevent the null values ?

Thanks</description>
		<content:encoded><![CDATA[<p>hello, your code works fine and it&#8217;s easy but he have tow BIG problem to use the data in excel :</p>
<p>1) ALL the data are in STRING, how to keep the type of the data ?</p>
<p>2) How to prevent the null values ?</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Export DataSet to Excel in C# by Jeff</title>
		<link>http://itsrashid.wordpress.com/2007/05/14/export-dataset-to-excel-in-c/#comment-335</link>
		<dc:creator>Jeff</dc:creator>
		<pubDate>Mon, 14 Sep 2009 15:57:13 +0000</pubDate>
		<guid isPermaLink="false">http://itsrashid.wordpress.com/2007/05/14/export-dataset-to-excel-in-c/#comment-335</guid>
		<description>If you&#039;re having trouoble with the Excel.xsl file, go to the original article here:
http://www.eggheadcafe.com/articles/20050404.asp 
(as per the link in the page above) and download teh source - it contains the Excel.xsl file.
Hint - it isn&#039;t blank</description>
		<content:encoded><![CDATA[<p>If you&#8217;re having trouoble with the Excel.xsl file, go to the original article here:<br />
<a href="http://www.eggheadcafe.com/articles/20050404.asp" rel="nofollow">http://www.eggheadcafe.com/articles/20050404.asp</a><br />
(as per the link in the page above) and download teh source &#8211; it contains the Excel.xsl file.<br />
Hint &#8211; it isn&#8217;t blank</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Export DataSet to Excel in C# by Naren</title>
		<link>http://itsrashid.wordpress.com/2007/05/14/export-dataset-to-excel-in-c/#comment-334</link>
		<dc:creator>Naren</dc:creator>
		<pubDate>Wed, 26 Aug 2009 15:10:54 +0000</pubDate>
		<guid isPermaLink="false">http://itsrashid.wordpress.com/2007/05/14/export-dataset-to-excel-in-c/#comment-334</guid>
		<description>it will be better if you include the namespaces, references list what should add to this.</description>
		<content:encoded><![CDATA[<p>it will be better if you include the namespaces, references list what should add to this.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on How to run Apache &amp; IIS parallel by yawmin</title>
		<link>http://itsrashid.wordpress.com/2007/06/05/how-to-run-apache-iis-parallel/#comment-332</link>
		<dc:creator>yawmin</dc:creator>
		<pubDate>Thu, 13 Aug 2009 09:47:55 +0000</pubDate>
		<guid isPermaLink="false">http://itsrashid.wordpress.com/2007/06/05/how-to-run-apache-iis-parallel/#comment-332</guid>
		<description>Hey I tried to set IIS to use port 8080 and Apache to use port 80
It works, but after that the website in IIS (.aspx) was unable to access SQL.
So now I have Apache on port 8080 and IIS on port 80.
and now both website are working.
(note the Website on Apache use php+MySql)</description>
		<content:encoded><![CDATA[<p>Hey I tried to set IIS to use port 8080 and Apache to use port 80<br />
It works, but after that the website in IIS (.aspx) was unable to access SQL.<br />
So now I have Apache on port 8080 and IIS on port 80.<br />
and now both website are working.<br />
(note the Website on Apache use php+MySql)</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on How to run Apache &amp; IIS parallel by Dheeraj</title>
		<link>http://itsrashid.wordpress.com/2007/06/05/how-to-run-apache-iis-parallel/#comment-328</link>
		<dc:creator>Dheeraj</dc:creator>
		<pubDate>Sat, 18 Jul 2009 03:27:46 +0000</pubDate>
		<guid isPermaLink="false">http://itsrashid.wordpress.com/2007/06/05/how-to-run-apache-iis-parallel/#comment-328</guid>
		<description>how to run iss and php parallel</description>
		<content:encoded><![CDATA[<p>how to run iss and php parallel</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Export DataSet to Excel in C# by Pradeep</title>
		<link>http://itsrashid.wordpress.com/2007/05/14/export-dataset-to-excel-in-c/#comment-327</link>
		<dc:creator>Pradeep</dc:creator>
		<pubDate>Mon, 22 Jun 2009 13:10:58 +0000</pubDate>
		<guid isPermaLink="false">http://itsrashid.wordpress.com/2007/05/14/export-dataset-to-excel-in-c/#comment-327</guid>
		<description>Hi ,
I m using above code but I m getting following error.
Error	3	The type or namespace name &#039;WorkbookEngine&#039; could not be found (are you missing a using directive or an assembly reference?)
Can u help me.
Regards,
Pradeep</description>
		<content:encoded><![CDATA[<p>Hi ,<br />
I m using above code but I m getting following error.<br />
Error	3	The type or namespace name &#8216;WorkbookEngine&#8217; could not be found (are you missing a using directive or an assembly reference?)<br />
Can u help me.<br />
Regards,<br />
Pradeep</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Export DataSet to Excel in C# by raju</title>
		<link>http://itsrashid.wordpress.com/2007/05/14/export-dataset-to-excel-in-c/#comment-326</link>
		<dc:creator>raju</dc:creator>
		<pubDate>Thu, 18 Jun 2009 16:25:48 +0000</pubDate>
		<guid isPermaLink="false">http://itsrashid.wordpress.com/2007/05/14/export-dataset-to-excel-in-c/#comment-326</guid>
		<description>Hi! I want to export my cutomized data report data to excel format. I am not using any data set / data grid/ data reader. I am working on NHibernate with C#.
here my records will be stored in one prpety bag and report header will be stored in another propety bag . please help me to complete this</description>
		<content:encoded><![CDATA[<p>Hi! I want to export my cutomized data report data to excel format. I am not using any data set / data grid/ data reader. I am working on NHibernate with C#.<br />
here my records will be stored in one prpety bag and report header will be stored in another propety bag . please help me to complete this</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Export DataSet to Excel in C# by Tachyon</title>
		<link>http://itsrashid.wordpress.com/2007/05/14/export-dataset-to-excel-in-c/#comment-325</link>
		<dc:creator>Tachyon</dc:creator>
		<pubDate>Tue, 09 Jun 2009 10:39:21 +0000</pubDate>
		<guid isPermaLink="false">http://itsrashid.wordpress.com/2007/05/14/export-dataset-to-excel-in-c/#comment-325</guid>
		<description>Ok, I tried to implement in a application I&#039;m making VS.NET 2008 but it didn&#039;t worked. 
Got some of the above errors and a excel-file of 9 bytes.

BUT... with some luck and few wild guesses, I got it to work:
CHEERS!!!!!


        public static void CreateWorkbook(DataSet ds, String path)
        {
            
            XmlDataDocument xmlDataDoc = new XmlDataDocument(ds);
            XslCompiledTransform xt = new XslCompiledTransform();
            StreamReader reader =new StreamReader(typeof (WorkbookEngine).Assembly.GetManifestResourceStream(typeof (WorkbookEngine), &quot;Excel.xsl&quot;));
            XmlTextReader xRdr = new XmlTextReader(reader);
            xt.Load(xRdr, null, null);
            StringWriter sw = new StringWriter();
            
            xt.Transform(xmlDataDoc, XmlWriter.Create(sw)); 
            
            StreamWriter myWriter = new StreamWriter (path + &quot;\\Report.xls&quot;);
            myWriter.Write (sw.ToString());
            myWriter.Close ();
        }

Take care!

Tachyon</description>
		<content:encoded><![CDATA[<p>Ok, I tried to implement in a application I&#8217;m making VS.NET 2008 but it didn&#8217;t worked.<br />
Got some of the above errors and a excel-file of 9 bytes.</p>
<p>BUT&#8230; with some luck and few wild guesses, I got it to work:<br />
CHEERS!!!!!</p>
<p>        public static void CreateWorkbook(DataSet ds, String path)<br />
        {</p>
<p>            XmlDataDocument xmlDataDoc = new XmlDataDocument(ds);<br />
            XslCompiledTransform xt = new XslCompiledTransform();<br />
            StreamReader reader =new StreamReader(typeof (WorkbookEngine).Assembly.GetManifestResourceStream(typeof (WorkbookEngine), &#8220;Excel.xsl&#8221;));<br />
            XmlTextReader xRdr = new XmlTextReader(reader);<br />
            xt.Load(xRdr, null, null);<br />
            StringWriter sw = new StringWriter();</p>
<p>            xt.Transform(xmlDataDoc, XmlWriter.Create(sw)); </p>
<p>            StreamWriter myWriter = new StreamWriter (path + &#8220;\\Report.xls&#8221;);<br />
            myWriter.Write (sw.ToString());<br />
            myWriter.Close ();<br />
        }</p>
<p>Take care!</p>
<p>Tachyon</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Export DataSet to Excel in C# by Ebbs</title>
		<link>http://itsrashid.wordpress.com/2007/05/14/export-dataset-to-excel-in-c/#comment-324</link>
		<dc:creator>Ebbs</dc:creator>
		<pubDate>Fri, 29 May 2009 11:37:46 +0000</pubDate>
		<guid isPermaLink="false">http://itsrashid.wordpress.com/2007/05/14/export-dataset-to-excel-in-c/#comment-324</guid>
		<description>If you still need a solution to your problems....try this link:

http://aspalliance.com/471_Convert_XML_To_an_Excel_Spreadsheet_Using_XSL.5</description>
		<content:encoded><![CDATA[<p>If you still need a solution to your problems&#8230;.try this link:</p>
<p><a href="http://aspalliance.com/471_Convert_XML_To_an_Excel_Spreadsheet_Using_XSL.5" rel="nofollow">http://aspalliance.com/471_Convert_XML_To_an_Excel_Spreadsheet_Using_XSL.5</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>
