public DataTable ReadExcelToTable(string filepath)
{
string excelfilePath = ServerMapPath(Excel/Excelxls);
ExcelApplication myExcel = new ExcelApplicationClass();
ExcelWorkbooks myBooks = myExcelApplicationWorkbooks;
object oMissing = SystemReflectionMissingValue;
ExcelWorkbook myBook = myBooksOpen(excelfilePath oMissing oMissing oMissing oMissing oMissing oMissing oMissing oMissing oMissing oMissing oMissing oMissing oMissing oMissing);
//ExcelWorkbook myBook = myExcelWorkbooks[];
int sheetint = myBookWorksheetsCount;//能得到sheet的数量
ExcelWorksheet mySheet = (ExcelWorksheet)myBookWorksheets[];
int rowsint = mySheetUsedRangeCellsRowsCount; //得到行数
int columnsint = mySheetUsedRangeCellsColumnsCount;//得到列数
SystemDataDataTable dt = new SystemDataDataTable(mytable);
for (int i = ; i < columnsint; i++)
{
dtColumnsAdd(F + iToString() SystemTypeGetType(SystemString));
}
DataSet myDs = new DataSet();
myDsTablesAdd(dt);
DataRow myRow;
myDsClear();
for (int i = ; i < rowsint; i++) //第一行为标题不读取
{
myRow = myDsTables[mytable]NewRow();
for (int j = ; j < columnsint; j++)
{
ExcelRange r = (ExcelRange)mySheetCells[i j];
string strValue = rTextToString();
string aa = strValue;
string columnname = F + jToString();
myRow[columnname] = strValue;
}
myDsTables[mytable]RowsAdd(myRow);
}
return myDsTables[mytable];
}