I’m filling a Data Table use ODP.NET’s OracleDataAdapter. I’d like to pass along the column headers too. Any idea how to go about this? Thanks!
OracleDataAdapter oda = new OracleDataAdapter(oc);
oda.Fill(dt);
FileInfo outFile = new FileInfo(outputPath + "out.xlsx");
using (ExcelPackage pck = new ExcelPackage(outFile))
{
//Create the worksheet
ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Netstat");
for (int row = 1; row <= dt.Rows.Count; row++)
{
for (int column = 1; column <= dt.Columns.Count; column++)
{
ws.Cells[row, column].Value = dt.Rows[row - 1][column - 1];
}
}
pck.Save();
Not sure how you are filling the
DataSetbut if you use the “standard way” i.e.THEN the column names are already in the
DataSeti.e.MyDataSet.Tables [MyTableName].Columns[0].ColumnName.This is a standard ADO.NET feature, nothing special about ODP.NET – see the MSDN reference at http://msdn.microsoft.com/en-us/library/bh8kx08z%28v=VS.100%29.aspx and http://msdn.microsoft.com/en-us/library/system.data.datacolumn.columnname.aspx
EDIT – AFTER the OP added source code:
In your code you aren’t using
DataSetbutDataTableso you can access the column names bydt.Columns[column].ColumnName.