asp.net excel 操作
2014-04-22 22:40
579 查看
/// <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
/// 数据操作
/// </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
相关文章推荐
- asp.net 操作excel的实现代码
- Asp.Net中Word,Excel等office com组件操作权限的问题
- 用ASP.NET操作Excel
- 告别ASP.NET操作EXCEL的烦恼
- ASP.NET 操作Excel 备忘录
- 告别ASP.NET操作EXCEL的烦恼
- asp.net操作excel
- Asp.Net用OWC操作Excel
- c# ASP.Net 使用开源免费类库操作Excel
- ASP.NET 调用Excel 操作Excel文件 不使用oledb
- ASP.NET操作EXCEL的总结篇
- ASP.NET中的Excel操作(OLEDB方式)
- asp.net 操作 excel 出现 class 组件错误 或 打开文件错误
- ASP.NET通过OLE DB操作Excel
- ASP.NET操作Excel备忘录
- asp.net 在IIS下操作Excel文件权限不足的解决方法
- asp.net 操作Excel 连接字符串
- asp.net操作Excel总结
- ASP.NET操作Excel时出现
- asp.net 操作excel的实现代码