

The code begins by declaring the variables used in the code. NOTE: The VB code code above is set up to run with Option Strict ON. ‘ NOTE: When in release mode, this does the trick OSheet.Cells(rowCount, dt.Columns.Count)) ORange = oSheet.Range(oSheet.Cells(1, 1), _ OSheet.Cells(rowCount, i) = dr.Item(i – 1).ToString OSheet.Cells(1, i) = dt.Columns(i – 1).ColumnName ‘ BE SURE TO CHANGE THIS LINE TO USE *YOUR* DATATABLEĭim dt As Data.DataTable = Customers.RetrieveAsDataTable OSheet = DirectCast(oWB.ActiveSheet, Excel.Worksheet) ‘ Start Excel and get Application object. NOTE: When in release mode, this does the trick

OWB.Close(Missing.Value, Missing.Value, Missing.Value) Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,

BE SURE TO CHANGE THIS LINE TO USE *YOUR* DATATABLEĭataTable dt = Customers.RetrieveAsDataTable() įor (int i = 1 i < dt.Columns.Count+1 i++) OSheet = (Excel.Worksheet)oWB.ActiveSheet Start Excel and get Application object. It is provided in one big chunk to make it easier to copy/paste into your application. The rest of the code is presented in VB and C# and then discussed below. Every parameter must have a value, so Missing.Value is used to provide a value for all unspecified optional parameters. This is required because C# 3.0 does not support optional parameters. NOTE: C# also requires a reference to System.Reflection to use the Missing.Value field. To keep the namespaces clear, consider using an alias. This post covers one straightforward technique.įirst, set a reference to the desired version of the Microsoft Excel Object Library from the COM tab of the Add Reference dialog. As with most things in Visual Studio, there are many ways to export data from your.
