您的位置:首页 > 编程语言 > ASP

asp.net excel 操作

2014-04-22 22:40 495 查看
/// <summary>
/// 数据操作
/// </summary>
/// <param name="fileName"></param>
/// <param name="savePath"></param>
private void DataOperator(string fileName, string savePath)
{

string myString = "Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = " + savePath + fileName + ";Extended Properties='Excel 8.0;HDR=False;IMEX=1'";
OleDbConnection oconn = new OleDbConnection(myString);
oconn.Open();
DataSet ds = new DataSet();
OleDbDataAdapter oda = new OleDbDataAdapter("select * from [Sheet1$]", oconn);
oda.Fill(ds);
oconn.Close();
DataSetOperator(ds, savePath + fileName);
}
/// <summary>
/// 数据集操作
/// </summary>
/// <param name="ds"></param>
private void DataSetOperator(DataSet ds, string filePath)
{
string sqlStr = "";
int k = 0;
try
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{

try
{

k++;
}
catch
{
continue;
}
}

}
catch (Exception ex)
{
// Response.Write("发生异常,数据已回滚/n信息/n" + ex.Message);

}
finally
{

Response.Write(sqlStr + "共转换" + k + "条");

}
}
#endregion
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: