导入:
public DataTable ReadDataByExcel(string fileFullPath)
{
// strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileFullPath + ";Extended Properties='Excel 8.0;HDR=False;IMEX=1;'";//只适合xls后缀
string strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileFullPath + ";Extended Properties='Excel 12.0;HDR=NO;IMEX=1;'";
OleDbConnection oleConn = new OleDbConnection(strConn);
try
{
oleConn.Open();
DataTable sheetNames = oleConn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
string tableName = "sheet1$";
if (sheetNames.Rows.Count > 0)
{
tableName = sheetNames.Rows[0][2].ToString();
}
//foreach (DataRow dr in sheetNames.Rows)
//{
// if (dr[2].ToString().Replace("$", "") != "sheet1")
// {
// continue;
// }
// else
// {
// tableName = "sheet1";
// break;
// }
//}
if (tableName.Length <= 0)
{
return null;
}
string sql = "select * from [" + tableName + "]";
OleDbDataAdapter oleDaExcel = new OleDbDataAdapter(sql, oleConn);
DataSet ds = new DataSet();
oleDaExcel.Fill(ds, tableName);
//CNoteFacade facade = new CNoteFacade();
return ds.Tables[0];
}
catch (Exception)
{
return null;
}
finally
{
oleConn.Close();
}
}
导出:http://blog.csdn.net/duanzi_peng/article/details/17414629
100分买这个,价出高了……
我也来看看
一百份也。。。 哪个快来写。
想要什么格式 我可以给你实现什么格式