zoukankan      html  css  js  c++  java
  • 使用插件实现一般处理程序导出excel

    string sql = "select * from WJ_ProjectManager where" + WhereString ;
    DataTable dt = SqlHelper.ExecuteDataTable(sql);
    Aspose.Cells.Workbook wk = new Aspose.Cells.Workbook();
    string excelFile = string.Empty;
    excelFile = "项目管理导出模板.xlsx";
    wk.Open(System.Web.HttpContext.Current.Server.MapPath("/View/ProjectManager/" + excelFile));
    if (dt.Rows.Count > 0) {
    for (int i = 0; i < dt.Rows.Count; i++)
    {
    wk.Worksheets[0].Cells[i + 2, 0].PutValue(i+1); //项目名称
    wk.Worksheets[0].Cells[i + 2, 1].PutValue(dt.Rows[i]["P_Name"]); //项目名称

    wk.Worksheets[0].Cells[i + 2, 2].PutValue(dt.Rows[i]["P_Customer"].ToString().Split(',')[1]); //关联客户
    wk.Worksheets[0].Cells[i + 2, 3].PutValue(dt.Rows[i]["P_Price"]); //项目价格
    wk.Worksheets[0].Cells[i + 2, 4].PutValue(dt.Rows[i]["P_StartDay"].ToString().Substring(0,10)); //预计实施时间
    wk.Worksheets[0].Cells[i + 2, 5].PutValue(dt.Rows[i]["P_AddDay"].ToString().Substring(0,10));//项目新增时间
    wk.Worksheets[0].Cells[i + 2, 6].PutValue(dt.Rows[i]["P_Status"]);//项目状态
    wk.Worksheets[0].Cells[i + 2, 7].PutValue(dt.Rows[i]["P_Relation"]);//联系人
    wk.Worksheets[0].Cells[i + 2, 8].PutValue(dt.Rows[i]["P_Solder"]);//销售人员

    }


    string yxdatet = DateTime.Now.Year + "" + DateTime.Now.Month + "" + DateTime.Now.Day + "" + DateTime.Now.Millisecond;

    string filename = yxdatet + "项目管理.xls";
    string serverPath = System.Web.HttpContext.Current.Server.MapPath("/import/" + filename);
    wk.Save(serverPath);

    FileInfo fileInfo = new FileInfo(serverPath);
    context.Response.Clear();
    context.Response.ClearContent();
    context.Response.ClearHeaders();
    System.Web.HttpContext.Current.Response.Charset = "GB2312";
    context.Response.AddHeader("Content-Disposition", "attachment;filename=" + context.Server.UrlEncode(yxdatet + "项目管理.xls"));

    context.Response.AddHeader("Content-Length", fileInfo.Length.ToString());
    context.Response.AddHeader("Content-Transfer-Encoding", "binary");
    context.Response.ContentType = "application/octet-stream";
    context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
    context.Response.WriteFile(fileInfo.FullName);
    context.Response.Flush();
    context.Response.End();

  • 相关阅读:
    移动应用滑动屏幕方向判断解决方案,JS判断手势方向
    M1808本地配置IP全过程
    嵌入式板子tftpd交叉编译及使用
    七牛云ARM64交叉编译流程
    记录M1808Ubuntu18.04固定IP配置方案
    so库移植记录
    c++ 动态库的编译
    Linux提示Syntax error: end of file unexpected (expecting "then") 提示错误
    ubuntu18.04设置静态ip
    WebFlux中thymeleaf视图找不到的问题解决
  • 原文地址:https://www.cnblogs.com/huangguojin/p/5427878.html
Copyright © 2011-2022 走看看