您的位置:首页 > 数据库

上传Excel数据到数据库中(Asp.net自动生成三层代码 第六集 )

2015-09-01 19:26 615 查看
上传文件

string savePath = Server.MapPath("~/upload/");//指定上传文件在服务器上的保存路径
//检查服务器上是否存在这个物理路径,如果不存在则创建
if (!System.IO.Directory.Exists(savePath))
{
System.IO.Directory.CreateDirectory(savePath);
}

if (FileUpload1.HasFile)
{
string fileExtension = Path.GetExtension(this.FileUpload1.FileName).ToLower();
string filename = DateTime.Now.ToOADate() + fileExtension;
savePath = savePath + filename;
FileUpload1.SaveAs(savePath);
string aller = string.Format("<a href='upload/{0}'>upload/{0}</a>", filename);
Response.Write(aller);
}
else
{
Response.Write("你还没有选择上传文件!");
}


  Excel操作

var app = new Application { Visible = false };
Workbook workbook = app.Workbooks.Open(savePath);
Worksheet worksheet = app.Worksheets[1];


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