下载excel模板
来源:互联网 发布:手机远程拍照软件 编辑:程序博客网 时间:2024/04/26 18:28
下载事件中写
Page.ClientScript.RegisterStartupScript(GetType(), "alert", "alert('测试成功!');", true);
System.IO.FileInfo file = new System.IO.FileInfo(Server.MapPath("../fellowship/template.xls"));//在项目的位置下放个Excel
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(file.FullName);
Response.End();
Response.Flush();
Response.Clear();
导入excel内容事件写这个方法
private void uploadOperation()
{
//string fileName = "";
// fileName = Request.QueryString["fileName"].Trim();
if (!this.fileUpload.FileName.Substring(this.fileUpload.FileName.LastIndexOf(".")).ToUpper().Equals(".XLS"))
{
Page.ClientScript.RegisterStartupScript(GetType(), "alert", "alert('只能导入Excel文件!')", true);
return;
}
// ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "updatepanel2", "alert('测试成功!');", true);
string oldfileName = this.fileUpload.FileName;
string newfileName = JinRi.Logic.GroupTicket.get_OrderNo(base.authorInfo.UserId) + ".xls";
this.fileUpload.SaveAs(Server.MapPath(@"~/fellowship/" + newfileName + ""));
StringBuilder xmlnode = new StringBuilder();
DataTable dt = selectExcel(newfileName);
if (dt != null)
{
Session["uploadFileName"] = newfileName;
}
else
{
Session["uploadFileName"] = null;
}
}
private DataTable selectExcel(string fileName)
{
// 连接字符串
string xlsPath = Server.MapPath("~/fellowship/" + fileName + "");
if (xlsPath == "")
{
return null;
}
// 相对物理路径:
string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Extended Properties=/"Excel 8.0;IMEX=1;HDR=NO;/";" + "data source=" + xlsPath;
// 查询语句
string sql = "SELECT * FROM [Sheet1$]";
if (!System.IO.File.Exists(xlsPath))
{
throw new Exception("文件不存在!");
}
DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter(sql, connStr);
try
{
da.Fill(ds); // 填充DataSet
if (ds.Tables[0].Rows.Count > 501)
{
this.txtUpload.Value = "error1";
}
else if (ds.Tables[0].Columns.Count != 2)
{
this.txtUpload.Value = "error2";
}
else
{
this.txtUpload.Value = "yes";
}
}
catch (Exception)
{
return null;
//throw new Exception(ex.Message);//则抛出的是系统自己的异常信息.
//throw new UploadExeception("上传的Excel文件被占用,请关闭这个文件!");//抛出的是用户自定义的异常信息.
}
// 在这里对DataSet中的数据进行操作
// 输出,绑定数据
return ds.Tables[0];
}
- 下载excel模板
- excel 下载模板
- 动态下载Excel模板
- 下载excel模板
- 下载excel模板
- EXCEL下载模板
- excel 下载模板
- Java 下载 Excel模板
- excel模板文件下载
- springmvc 利用模板 下载excel
- Java Web下载Excel模板
- java之excel模板下载
- 简单的下载excel模板
- 下载Excel文件模板 ---文件下载--SSM
- 复制Excel模板,填写Excel模板,然后下载
- EXCEL模板的上传个下载
- 下载excel模板一直缺少下拉选项
- Java操作Excel之下载模板
- Using threads and ProgressDialog
- 发挥青年创业的人才智慧 湖塘镇的青年企业家商会终于成立
- Excel导入SQL数据库
- 基于java的mud游戏CoffeeMud(1)--- 安装
- Separating Lists with Headers
- 下载excel模板
- 闲极无聊,开始学JAVA
- Getting Data From the Web (URLConnection via http)
- cookie总结
- 幽默哲学
- C#操纵本地IIS(建站点)
- 工作<=应届生
- 如何实现ubuntu桌面远程控制?
- xml文件对比或xml大字符串对比方法(蛮精简的)