Ejemplo n.º 1
0
        /// <summary>
        /// 导出excel数据
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="serieNo"></param>
        /// <returns></returns>
        public ActionResult DownLoadExcelRunData(IList <string> allmts, IDictionary <string, IDictionary <string, string> > timemtMap, string filename)
        {
            IList <ExcelData> datas = new List <ExcelData>();
            ExcelData         data  = new ExcelData();
            bool isMulti            = false;
            //标题行
            IList <string> xList = new List <string>();

            xList.Add("                        " + filename + "                       ");
            xList.Add(Resources.SunResource.REPORT_TIME);
            foreach (string key in timemtMap.Keys)
            {
                xList.Add(key);
            }
            data.Rows.Add(xList);
            datas.Add(data);

            IList <string> tmps = null;

            foreach (string mtkey in allmts)
            {
                data = new ExcelData();
                tmps = new List <string>();
                tmps.Add("        ");
                tmps.Add(mtkey);
                foreach (string key in timemtMap.Keys)
                {
                    //第一列是时间
                    tmps.Add(timemtMap[key][mtkey]);
                }
                data.Rows.Add(tmps);
                datas.Add(data);
            }

            ExcelStreamWriter xlsWriter = new ExcelStreamWriter(filename, datas, new string[] { }, "", "", isMulti);

            xlsWriter.Save(false);
            return(File(xlsWriter.FullName, "text/xls; charset=UTF-8", urlcode(xlsWriter.FileName)));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 导出excel数据
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="serieNo"></param>
        /// <returns></returns>
        public ActionResult ExportExcelChart(string filename, string serieNo)
        {
            ChartData chartData = null;// TempDataUtil.getChartData(serieNo+"_large");

            if (chartData == null)
            {
                chartData = TempDataUtil.getChartData(serieNo);
            }

            IList <ExcelData> datas      = new List <ExcelData>();
            ExcelData         data       = new ExcelData();
            string            reportname = string.Empty;
            bool isMulti = false;

            if (chartData != null)
            {
                isMulti = ReportBuilder.isMulti(chartData.units);

                reportname = (filename.Equals("chart") ? "" : filename) + chartData.name.Replace("/", "").Replace(" ", "");

                IList <string> xList = new List <string>();
                string         xname = Resources.SunResource.CUSTOMREPORT_CHART_TIME;
                if (chartData.names.Length > 0 && !string.IsNullOrEmpty(chartData.names[0]))
                {
                    xname = chartData.names[0] + "[" + chartData.units[0] + "]";
                }
                xList.Add(xname);
                int n = 1;// chartData.categories.Length > 100 ? 12 : 1;
                for (int k = 0; k < chartData.categories.Length; k = k + n)
                {
                    string x = chartData.categories[k];
                    xList.Add(x);
                }
                data.Rows.Add(xList);
                IList <string> tmps   = null;
                string[]       series = new string[chartData.series.Count()];
                for (int i = 0; i < chartData.series.Count(); i++)
                {
                    if (i > 0 && isMulti)
                    {
                        data = new ExcelData();
                    }
                    tmps = new List <string>();
                    string yname = chartData.series[i].name;
                    tmps.Add(yname);

                    for (int k = 0; k < chartData.series[i].data.Length; k = k + n)
                    {
                        float?f = chartData.series[i].data[k];
                        tmps.Add(f == null ? string.Empty : StringUtil.formatDouble(StringUtil.stringtoDouble(f.ToString()), "0.00"));
                    }
                    data.Rows.Add(tmps);
                    if (isMulti)
                    {
                        int slen   = yname.IndexOf("[");
                        int endLen = yname.IndexOf("]");
                        if (slen > -1)
                        {
                            data.Title = yname.Substring(slen + 1, endLen - slen - 1);
                        }
                        else
                        {
                            data.Title = yname;
                        }
                        data.series    = new String[] { chartData.series[i].name };
                        data.chartType = chartData.series[i].type;
                        datas.Add(data);
                    }
                    else
                    {
                        series[i] = chartData.series[i].name;
                    }
                }

                if (!isMulti && chartData.series.Count() > 0)
                {
                    int slen   = chartData.series[0].name.IndexOf("[");
                    int endLen = chartData.series[0].name.IndexOf("]");
                    if (slen > -1)
                    {
                        data.Title = chartData.series[0].name.Substring(slen + 1, endLen - slen - 1);
                    }
                    else
                    {
                        data.Title = chartData.series[0].name;
                    }
                    data.series    = series;
                    data.chartType = chartData.series[0].type;
                    datas.Add(data);
                }
            }

            ExcelStreamWriter xlsWriter = new ExcelStreamWriter(reportname, datas, chartData.units, reportname, "", isMulti);

            //散列图暂不生成
            if (chartData.series.Length > 0 && "scatter".Equals(chartData.series[0].type))
            {
                xlsWriter.Save(false);
            }
            else
            {
                xlsWriter.Save(true);
            }
            return(File(xlsWriter.FullName, "text/xls; charset=UTF-8", urlcode(xlsWriter.FileName)));
        }
Ejemplo n.º 3
0
        public ActionResult Plants_Output(string install_start, string install_end, int?index, string uname, string plantname)
        {
            string uids = "0,";

            if (string.IsNullOrEmpty(uname) == false)
            {
                IList <User> users = UserService.GetInstance().GetUsersLikeuname(uname);
                foreach (User user in users)
                {
                    uids += string.Format("{0},", user.id);
                }
            }
            uids         += "0";
            index         = index == null ? 1 : index.Value;
            install_start = install_start == null ? string.Empty : install_start;
            install_end   = install_end == null ? string.Empty : install_end;

            Hashtable table = new Hashtable();
            Plant     plant = new Plant();

            plant.name = plantname;
            Pager page = new Pager()
            {
                PageSize = ComConst.PageSize, PageIndex = (int)index
            };

            ViewData["page"] = page;
            table.Add("plant", plant);
            table.Add("install_start", install_start);
            table.Add("install_end", install_end);
            table.Add("uids", uids);
            table.Add("page", page);
            IList <Plant> plants = PlantService.GetInstance().QueryPagePlants(table);


            IList <ExcelData> eDatas = new List <ExcelData>();
            ExcelData         data   = new ExcelData();
            IList <string>    temp   = new List <string>();

            temp.Add("电站名");
            temp.Add("用户名");
            temp.Add("安装日期");
            temp.Add("安装功率");
            temp.Add("国家");
            temp.Add("城市");
            temp.Add("付款到期");
            data.Rows.Add(temp);
            foreach (Plant item in plants)
            {
                temp = new List <string>();
                temp.Add(item.name);
                temp.Add(item.User.username);
                temp.Add(item.installdate.ToShortDateString());
                temp.Add(item.design_power.ToString("0 kWp"));
                temp.Add(item.city);
                temp.Add(item.country);
                temp.Add(item.PaymentLimitDate.ToShortDateString());
                data.Rows.Add(temp);
            }
            eDatas.Add(data);
            ExcelStreamWriter writer = new ExcelStreamWriter(eDatas);

            writer.align = true;
            writer.Save("电站列表");
            return(File(writer.FullName, "text/xlsx; charset=UTF-8", urlcode(writer.FileName)));
        }