private DataTable GetExcel(string filepach)
{
string str;
FarPoint.Win.Spread.FpSpread fpSpread1 = new FarPoint.Win.Spread.FpSpread();
try
{
fpSpread1.OpenExcel(filepach);
}
catch
{
string filepath1=Path.GetTempPath() + "//"+ Path.GetFileName(filepach);
File.Copy(filepach,filepath1) ;
fpSpread1.OpenExcel(filepath1);
File.Delete(filepath1);
}
DataTable dt = new DataTable();
for (int k = 1; k <= fpSpread1.Sheets[0].GetLastNonEmptyColumn(FarPoint.Win.Spread.NonEmptyItemFlag.Data) + 1; k++)
{
dt.Columns.Add("col" + k.ToString());
}
for (int i = 0; i < fpSpread1.Sheets[0].GetLastNonEmptyRow(FarPoint.Win.Spread.NonEmptyItemFlag.Data) + 1; i++)
{
DataRow dr = dt.NewRow();
str = "";
for (int j = 0; j < fpSpread1.Sheets[0].GetLastNonEmptyColumn(FarPoint.Win.Spread.NonEmptyItemFlag.Data) + 1; j++)
{
str = str + fpSpread1.Sheets[0].Cells[i, j].Text;
dr[j] = fpSpread1.Sheets[0].Cells[i, j].Text;
}
if (str != "")
dt.Rows.Add(dr);
}
return dt;
}