<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>BlogoDev &#187; Excel</title>
	<atom:link href="http://www.bluby.org/blog/tag/excel/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bluby.org/blog</link>
	<description>Un blog para desarrolladores</description>
	<lastBuildDate>Mon, 28 Jun 2010 17:34:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>[VB.Net] Exportar DataSet a Excel</title>
		<link>http://www.bluby.org/blog/2009/08/vb-net-exportar-dataset-a-excel/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=vb-net-exportar-dataset-a-excel</link>
		<comments>http://www.bluby.org/blog/2009/08/vb-net-exportar-dataset-a-excel/#comments</comments>
		<pubDate>Mon, 31 Aug 2009 03:09:17 +0000</pubDate>
		<dc:creator>P-los</dc:creator>
				<category><![CDATA[Funciones]]></category>
		<category><![CDATA[Excel]]></category>
		<category><![CDATA[VB.Net]]></category>

		<guid isPermaLink="false">http://www.bluby.org/blog/?p=77</guid>
		<description><![CDATA[Recientemente me solicitaron para un proyecto que los reportes se mandaran directamente a Excel. He aquí una pequeña función capaz de exportar cualquier DataSet a un archivo de Excel: Public Sub ExportarArchivo(ByVal archivo As String, ByVal datos As DataSet) Dim xl As New Microsoft.Office.Interop.Excel.ApplicationClass Dim wBook As Microsoft.Office.Interop.Excel.Workbook Dim wSheet As Microsoft.Office.Interop.Excel.Worksheet wBook = xl.Workbooks.Add [...]]]></description>
			<content:encoded><![CDATA[<p>Recientemente me solicitaron para un proyecto que los reportes se mandaran directamente a Excel. He aquí una pequeña función capaz de exportar cualquier DataSet a un archivo de Excel:</p>
<p><code>Public Sub ExportarArchivo(ByVal archivo As String, ByVal datos As DataSet)<br />
        Dim xl As New Microsoft.Office.Interop.Excel.ApplicationClass<br />
        Dim wBook As Microsoft.Office.Interop.Excel.Workbook<br />
        Dim wSheet As Microsoft.Office.Interop.Excel.Worksheet<br />
        wBook = xl.Workbooks.Add<br />
        wSheet = wBook.ActiveSheet<br />
        Dim colIndex As Integer = 0<br />
        Dim rowIndex As Integer = 0<br />
        For Each dc As System.Data.DataColumn In datos.Tables(0).Columns<br />
            colIndex = colIndex + 1<br />
            xl.Cells(1, colIndex) = dc.ColumnName<br />
        Next<br />
        For Each dr In datos.Tables(0).Rows<br />
            rowIndex = rowIndex + 1<br />
            colIndex = 0<br />
            For Each dc In datos.Tables(0).Columns<br />
                colIndex = colIndex + 1<br />
                xl.Cells(rowIndex + 1, colIndex) = dr(dc.ColumnName)<br />
            Next<br />
        Next<br />
        wSheet.Columns.AutoFit()<br />
        Dim blnFileOpen As Boolean = False<br />
        Try<br />
            Dim fileTemp As System.IO.FileStream = System.IO.File.OpenWrite(archivo)<br />
            fileTemp.Close()<br />
        Catch ex As Exception<br />
            blnFileOpen = False<br />
        End Try<br />
        If System.IO.File.Exists(archivo) Then<br />
            System.IO.File.Delete(archivo)<br />
        End If<br />
        wBook.SaveAs(archivo)<br />
        xl.Workbooks.Open(archivo)<br />
        xl.Visible = True<br />
    End Sub<br />
</code><br />
Para que no cause errores, hay que agregar como referencia la siguiente:<br />
<code>Microsoft.Office.Interop.Excel</code></p>
<p>Espero les sea tan util como a mi!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bluby.org/blog/2009/08/vb-net-exportar-dataset-a-excel/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
