//fileName --文件路径
public DataSet DataSetGetDataFromExcel(string fileName)
{
DataSet dataset = new DataSet ();
Cells cells;
Workbook workbook = new Workbook();
workbook.Open(fileName);
cells = workbook.Worksheets[0].Cells;
DataTable dt = cells.ExportDataTableAsString(0, 0, cells.MaxDataRow + 1, cells.MaxDataColumn + 1, true);//创建数据表
for (int k = 1; k < cells.MaxDataRow; k++)
{
for (int j = 0; j <= cells.MaxDataColumn; j++)
{
string s = cells[k, j].StringValue.Trim(); //关键部分
dt.Rows[k][j] = s;
}
}
var cc = dt;
dataset.Tables.Add(dt);
return dataset;
}