Esempio n. 1
0
        /// <summary>
        /// 输出csv文件
        /// </summary>
        /// <param name="allmts"></param>
        /// <param name="timemtMap"></param>
        /// <param name="filename"></param>
        /// <returns></returns>
        public ActionResult DownLoadCsvRunData(IList <string> allmts, IDictionary <string, IDictionary <string, string> > timemtMap, string filename)
        {
            CsvStreamWriter scvWriter = new CsvStreamWriter();

            //输入出到csv文件中的数据列表
            IList <string> dataList = new List <string>();

            //设置抬头行
            dataList.Add("                        " + filename + "                       ");
            //循环设置数据行
            //设置标题行
            allmts.Insert(0, Resources.SunResource.REPORT_TIME);
            dataList.Add(scvWriter.ConvertToSaveLine(allmts));
            //数据行临时list
            IList <string> tempList = new List <string>();

            foreach (string key in timemtMap.Keys)
            {
                dataList.Add(scvWriter.ConvertToSaveCell(key) + "," + scvWriter.ConvertToSaveLine(timemtMap[key].Values));
            }

            scvWriter.AddStrDataList(dataList);
            scvWriter.Save(Server.MapPath("/") + "tempexportfile/" + filename + ".csv");
            return(File(Server.MapPath("/") + "tempexportfile/" + filename + ".csv", "text/csv; charset=UTF-8", urlcode(filename) + ".csv"));
        }