Here's some code I wrote to get data from an excel file... To add the reference go to Project->Add Reference then find Microsoft.Office.Interop.Excel under the .Net tab. Note I think you need to have excel (or maybe just any office product) installed in order for this reference to be available.
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Office.Core;
using Microsoft.Office.Interop.Excel;
using System.Data.OleDb;
using System.Threading;
namespace MobileExcelDB
{
public class ExcelFile
{
public delegate void delProgUpdate(double dProgress);
public delegate void delLoadComplete();
public event delProgUpdate ProgressUpdate;
public event delLoadComplete LoadComplete;
string _Path;
const int MAX_ROW = 100;
const int MAX_COL = 100;
public string[,] Data = new string[MAX_ROW,MAX_COL];
public double Progress { get; private set; }
public ExcelFile(string sPath)
{
_Path = sPath;
}
public void LoadFile()
{
Thread doExcelLoad = new Thread(new ParameterizedThreadStart(DoLoad));
doExcelLoad.Start(_Path);
}
private void DoLoad(object sPath)
{
ApplicationClass excelApp = new ApplicationClass();
excelApp.Visible = false;
Workbook myWorkbook = excelApp.Workbooks.Open((string)sPath);
Sheets sheets = myWorkbook.Worksheets;
Worksheet myWorksheet = (Microsoft.Office.Interop.Excel.Worksheet)sheets.get_Item(1);
for (int i = 0; i < MAX_ROW ; i++)
{
for (int ii = 0; ii < MAX_COL; ii++)
{
try
{
Data[i, ii] = ((Range)myWorksheet.Cells[i, ii]).get_Value(Type.Missing).ToString();
}
catch { Data[i, ii] = null; }
}
if (i % 10 == 0)
{
UpdateProgress(i);
ProgressUpdate.Invoke(Progress);
}
}
myWorkbook.Close();
excelApp.Quit();
LoadComplete.Invoke();
}
private void UpdateProgress(int iRowsLoaded)
{
Progress = ((double)iRowsLoaded / (double)MAX_ROW) * 100;
}
}