excel to data
来源:互联网 发布:笔记本电脑com端口 编辑:程序博客网 时间:2024/05/16 19:21
protected void btn_Import_Click(object sender, EventArgs e)
{
try
{
string fileName = FileUpload1.FileName;
if (string.IsNullOrEmpty(fileName)) throw new Exception("请选择要上传的文件!");
if (Path.GetExtension(fileName).ToLower() != ".xls") throw new Exception("请上传正确的文件类型(xls)");
string date = "(" + DateTime.Now.ToShortDateString() + ")";
FileUpload1.SaveAs(Server.MapPath("excel/" + date + fileName));
string filePath = Server.MapPath("excel/" + date + fileName);
string mystring = string.Format("Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = '{0}';Extended Properties=Excel 8.0", filePath);
OleDbConnection cnnxls = new OleDbConnection(mystring);
DataTable dt = new DataTable();
try
{
OleDbDataAdapter myDa = new OleDbDataAdapter("select * from [Sheet1$]", cnnxls);
myDa.Fill(dt);
}
catch (Exception ole)
{
throw new Exception("数据源获取数据失败:" + ole.Message);
}
finally
{
cnnxls.Dispose();
cnnxls.Close();
}
int itemCount = 0;
Import(dt, ref itemCount);
Page.RegisterClientScriptBlock("", "<script>returnOk(" + itemCount + ")</script>");
}
catch (Exception err)
{
lab_Msg.Text = "错误:" + err.Message;
}
}
protected void Import(DataTable DT, ref int num)
{
string sql = string.Empty;
string hth = string.Empty;
DataTable dt;
try
{
for (int i = 3; i < DT.Rows.Count; i++)
{
dt = null;
string sys_guid= System.Guid.NewGuid().ToString();
// 插入数据库
num++;
}
ida.Close(true);
}
catch (Exception e)
{
ida.Close(false);
throw new Exception("数据导入失败:" + e.Message);
}
}
- excel to data
- Excel File to Oracle data.
- download as400 data to excel
- To import data from excel to DB
- ASP.NET Tip: Exporting Data to Excel
- export data from DataGrid to Excel
- Export data from SQL Server to Excel
- How to import xml data into excel
- C#DataGrid Export data to Excel
- Writing Data to Excel using C#
- Write data to an Excel Worksheet
- Export large data to excel use poi
- Import Data from Excel to SQL Server
- Write data to an Excel file without importing the data to the data table
- 5 Solutions to Export Data to Excel for ASP.NET
- Get data from an Excel file without importing the data to the data table
- Export Data from GridView to Excel, Word, HTML with C#
- Export large data from GridView to Excel file using C#
- 高效程序员之高效小工具- 介绍一下hott notes
- JAVA中对存储过程的调用方法
- 海量数据战争——谁能赢得未来?
- 爱情公式
- 用微服务器处理海量数据——你敢尝试吗?
- excel to data
- java中代码检查checkStyle结果分析
- weblogic 中域,集群,管理服务器和被管服务器之间的关系
- WM_TIMER 消息的问题
- 编译安装 Apache + Subversion + LDAP
- FAT32文件系统简介
- C++返回局部对象
- ria +prism 难解问题之 "返回类型必须是实体或复杂类型、复杂类型的集合或预定义的可序列化类型之一"
- 职场加薪步步高升的五大法则