using System.IO;
using System.Data;
using Infragistics.Documents.Excel;
using Infragistics.Win.UltraWinGrid;
private UltraGrid ultraGrid;
...
string filePath = Application.StartupPath + @"\EMPLOYEE.xls";
if(File.Exists(filePath))
{
Workbook workBook = Workbook.Load(filePath);
Worksheet workSheet = workBook.Worksheets[0];
DataTable employeeTable = new DataTable("Employee");
int rowCount = 0;
int columnCount = 0;
foreach(WorksheetRow worksheetRow in workSheet.Rows)
{
if(rowCount == 0)
{
foreach(WorksheetCell worksheetCell in worksheetRow.Cells)
{
string cellValue = worksheetCell.Value.ToString().Trim();
if(cellValue != string.Empty)
{
DataColumn dataColumn = employeeTable.Columns.Add();
dataColumn.ColumnName = cellValue;
dataColumn.DataType = workSheet.Rows[rowCount + 1].Cells[columnCount].Value.GetType();
}
else
{
break;
}
columnCount++;
}
}
else
{
columnCount = 0;
DataRow employeeRow = employeeTable.NewRow();
foreach(WorksheetCell worksheetCell in worksheetRow.Cells)
{
object cellValue = workSheet.Rows[rowCount].Cells[columnCount].Value;
if(cellValue != null)
{
employeeRow[columnCount] = cellValue;
}
else
{
break;
}
columnCount++;
}
employeeTable.Rows.Add(employeeRow);
}
rowCount++;
}
employeeTable.AcceptChanges();
this.ultraGrid.DataSource = employeeTable;
}