通过Asp.net在Sql Server Table中上载或导入带有多个工作表的Excel工作表

时间:2013-11-14 06:23:00

标签: asp.net sql-server excel

我有包含多个工作表的excel表格,我想将此excel表格上传/导入表格。

例如:
Excel表格格式:
表1
拉姆|库马尔|耆那教
Radhe | Mohane |夏尔马

表2
Mohan |库马尔|古普塔
Chand |谢卡尔|维尔马

 我想在sql server表中上传/导入这个excel 表名:info
名字|中间名|姓氏

1 个答案:

答案 0 :(得分:0)

链接:

http://www.aspsnippets.com/Articles/Read-and-Import-Excel-Sheet-into-SQL-Server-Database-in-ASP.Net.aspx

protected void btnUpload_Click(object sender, EventArgs e)

{

    if (FileUpload1.HasFile)

    {

        string FileName = Path.GetFileName(FileUpload1.PostedFile.FileName);

        string Extension = Path.GetExtension(FileUpload1.PostedFile.FileName);

        string FolderPath = ConfigurationManager.AppSettings["FolderPath"];

        string FilePath = Server.MapPath(FolderPath + FileName);

        FileUpload1.SaveAs(FilePath);

        GetExcelSheets(FilePath, Extension, "Yes");

    }

}