asp.net excel 操作
/// <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";
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
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。