您现在的位置: 爱51代码网 >> 范文 >> 文章正文
将DataTable的Data到生成CSV文件里面然后在保存到项目文件夹下面

将DataTable的Data到生成CSV文件里面然后在保存到项目文件夹下面

将DataTable的Data到生成CSV文件里面然后在保存到项目文件夹下面呢

C# code?1  

怎么做呢,求大神帮忙,

  public void ExportToExcelOfficeALLByAdditional()
        {
            SearchAdditionalRun search;
            string excelstr = "";
            string name = Request.QueryString["name"];
            string date = Request.QueryString["date"];
            if (date == "ALL")
            {
                search = new SearchAdditionalRun
               {
                   SearchType = SearchTypeEnum.Total,
                   Status = StatusEnum.Active,
               };
            }
            else
            {
                search = new SearchAdditionalRun
               {
                   ActualDate = date.ToInteger(),
                   SearchType = SearchTypeEnum.Total,
                   Status = StatusEnum.Active,
               };
            }
            IList<AdditionalRunInfo> info = iadditionalrun.Search(search);
            #region AdditionalRunInfo导??出?字??段?
            string strNull = "";
            excelstr = "AdditionalRunID" + "," +
                             "RequestDescription" + "," +
                             "ReasonID" + "," +
                             "Reason" + "," +
                             "DateRaised" + "," +
                             "ExpectedDate" + "," +
                             "ActualDate" + "," +
                             "ProjectID" + "," +
                             "Project #" + "," +
                             "ProjectName" + "," +
                             "InsertTime" + "," +
                             "LastChanged" + "," +
                             "Status" + "\n";//标题        
            #endregion
            foreach (AdditionalRunInfo item in info)
            {
                #region AdditionalRunInfo导??出?字??段?
                string DateRaised = item.DateRaised == DateTime.MinValue ? "" : item.DateRaised.ToString("yyyy-MM-dd");
                string ExpectedDate = item.ExpectedDate == DateTime.MinValue ? "" : item.ExpectedDate.ToString("yyyy-MM-dd");
                string InsertTime = item.InsertTime == DateTime.MinValue ? "" : item.InsertTime.ToString("yyyy-MM-dd");
                string LastChanged = item.LastChanged == DateTime.MinValue ? "" : item.LastChanged.ToString("yyyy-MM-dd");
                string ProjectNumber = ibkfm.GetBKFM(item.ProjectID).ProjectNumber;
                string ProjectName = ibkfm.GetBKFM(item.ProjectID).ProjectName;
                string Reason = isimplecategory.GetSimpleCategoryInfo(item.ReasonID).GetLangInfo(LanguageTypeEnum.Chinese).CategoryName;
                excelstr += item.AdditionalRunID + "," +
                            StringFormat(item.RequestDescription) + "," +
                            item.ReasonID + "," +
                            Reason + "," +
                            DateRaised + "," +
                            ExpectedDate + "," +
                            date + "," +
                            item.ProjectID + "," +
                            ProjectNumber + "," +
                            ProjectName + "," +
                            InsertTime + "," +
                            LastChanged + "," +
                            item.Status + "\n";//标题  
                #endregion
            }
            string url = Server.MapPath("~\\fileupload\\") + name + ".csv";//要存储的路径
            string path = "/fileupload/" + name + ".csv";//导出文件的相对路径,用于下?载
            StreamWriter sw = new StreamWriter(url, false, Encoding.GetEncoding("GB2312"));//把文件作为文件流保存在固定的路径
            sw.Write(excelstr);// 文件流写出
            sw.Flush();//判断是否有文件,如果有则删除
            sw.Dispose();//释放流的资源
            Response.Write("" + path + "");//输出文件相对路径
        }

  • 上一篇文章:

  • 下一篇文章: 没有了
  • 最新文章 热点文章 相关文章
    E-business suite system servic
    ZOJ 3700 Ever Dream 文章中单词
    TortoiseGit和msysGit安装及使用
    asp中有一段javascipt的网页鼠标
    sharepoint 2010 获取用户信息Us
    设计包含max函数的队列
    随机从数组中取出指定的不重复的
    mysql主从同步延迟方案解决的学习
    青岛科学六年级下册教材分析
    生日旅行总结
    sharepoint 2010 获取用户信息Us
    mysql主从同步延迟方案解决的学习
    生日旅行总结
    中小板生日快乐随感
    送生日快乐桑葚乳酪小蛋糕
    写给女儿的生日快乐
    总分公司财务核算
    恢复使用繁体字可行性研究报告
    青少年吸烟心理探析
    保险受益人制度相关问题的探讨
    Strus2 + pager-taglib 实现
    linux内核启动时R2的值来历
    JS中setInterval、setTimeou
    javascript 中强制执行 toSt
    SQL Server UNIQUE失效
    SQLServer2005中的企业管理器
    SQL Sever 如何修改主键数据
    sqlserver如何根据给出的时间
    解决SecureCRT连接linux超时
    dos编程:查询百度蜘蛛IP的命
     



    设为首页 | 加入收藏 | 网站地图 | 友情链接 |