Ejemplo n.º 1
0
        /// <summary>
        /// 导出
        /// </summary>
        /// <param name="dt"></param>
        public void ToExcel1(DataTable dt)
        {
            AppLibrary.WriteExcel.XlsDocument doc = new AppLibrary.WriteExcel.XlsDocument();
            doc.FileName = DateTime.Now.ToString("yyyyMMdd") + ".xls";
            string SheetName = "Sheet1";
            //记录条数
            int       mCount = dt.Rows.Count;
            Worksheet sheet  = doc.Workbook.Worksheets.Add(SheetName);
            Cells     cells  = sheet.Cells;

            //第一行表头
            for (int i = 0; i < title.Length; i++)
            {
                cells.Add(1, i + 1, title[i].Trim());
            }
            for (int m = 0; m < mCount; m++)
            {
                for (int j = 0; j < title.Length; j++)
                {
                    //可以直接取图片的地址
                    string filename            = Server.MapPath("~/" + dt.Rows[m]["Img"].ToString());
                    byte[] filedata            = getImageByte(filename);;
                    System.IO.MemoryStream ms  = new System.IO.MemoryStream(filedata);
                    System.Drawing.Image   img = System.Drawing.Image.FromStream(ms);
                    img.Save(filename);

                    // cells.Add(m + 2, j + 1, dt.Rows[m][j].ToString());

                    cells.Add(m + 2, j + 1, img);
                }
            }
            doc.Send();
            Response.End();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 导出
        /// </summary>
        /// <param name="dt"></param>
        public void ToExcel(DataTable dt)
        {
            AppLibrary.WriteExcel.XlsDocument doc = new AppLibrary.WriteExcel.XlsDocument();
            doc.FileName = DateTime.Now.ToString("yyyyMMdd") + ".xls";
            string SheetName = "Sheet1";
            //记录条数
            int       mCount = dt.Rows.Count;
            Worksheet sheet  = doc.Workbook.Worksheets.Add(SheetName);
            Cells     cells  = sheet.Cells;

            //第一行表头
            for (int i = 0; i < title.Length; i++)
            {
                cells.Add(1, i + 1, title[i].Trim());
            }
            for (int m = 0; m < mCount; m++)
            {
                for (int j = 0; j < title.Length; j++)
                {
                    cells.Add(m + 2, j + 1, dt.Rows[m][j].ToString());
                }
            }
            doc.Send();
            Response.End();
        }
Ejemplo n.º 3
0
        public void Export()
        {
            //俱乐部名称
            var clubname = HttpContext.Current.Request.QueryString["clubname"].ToString();
            //类型
            var       saleactivitytypeid       = HttpContext.Current.Request.QueryString["saleactivitytypeid"].ToString();
            var       begindate                = HttpContext.Current.Request.QueryString["begindate"].ToString();
            var       enddate                  = HttpContext.Current.Request.QueryString["enddate"].ToString();
            IDatabase database                 = DataFactory.Database();
            IRepository <ActivityViewModel> re = new Repository <ActivityViewModel>();
            DataTable data     = new DataTable();
            string    strwhere = " IsDelete=0  ";

            if (!string.IsNullOrEmpty(clubname))
            {
                strwhere += " and ClubName like '%" + clubname + "%'";
            }
            if (!string.IsNullOrEmpty(saleactivitytypeid))
            {
                strwhere += " and ClubActivityTypeId=" + saleactivitytypeid;
            }
            if (!string.IsNullOrEmpty(begindate))
            {
                strwhere += " and ActivityDate>='" + begindate + "'";
            }
            if (!string.IsNullOrEmpty(enddate))
            {
                strwhere += " and ActivityDate<='" + enddate + "'";
            }
            data = database.FindTableBySql("select [clubactivityinfoid],[clubname],[clubactivitytypeid],[activitydate],[activitycost],[createtime],[createuserid],[isshow] ,[isdelete],[createusername],[clubactivitytypename]  from C_ClubActivityInfoView where " + strwhere + " order by ClubActivityInfoId desc");
            AppLibrary.WriteExcel.XlsDocument doc = new AppLibrary.WriteExcel.XlsDocument();
            // HttpContext.Current.Response.Write();
            doc.FileName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls";
            string    sheetname = "SHEET";
            Worksheet sheet     = doc.Workbook.Worksheets.Add(sheetname);
            Cells     cells     = sheet.Cells;
            XF        XFstyle   = doc.NewXF();

            XFstyle.HorizontalAlignment = HorizontalAlignments.Centered;
            cells.Add(1, 1, "车主俱乐部名称");
            cells.Add(1, 2, "活动类别");
            cells.Add(1, 3, "日期");
            cells.Add(1, 4, "活动成本");
            int f = 1;

            for (int i = 0; i < data.Rows.Count; i++)
            {
                f++;
                cells.Add(f, 1, data.Rows[i]["clubname"]);
                cells.Add(f, 2, data.Rows[i]["clubactivitytypename"]);
                cells.Add(f, 3, DateTime.Parse(data.Rows[i]["activitydate"].ToString()).ToString("yyyy-MM-dd"));
                cells.Add(f, 4, data.Rows[i]["activitycost"]);
            }
            doc.Send();
            HttpContext.Current.Response.Flush();
            HttpContext.Current.Response.End();
        }
        public void Print()
        {
            //区域
            var activitareaid = HttpContext.Current.Request.QueryString["activitareaid"].ToString();
            //经销商
            var agencyid = HttpContext.Current.Request.QueryString["agencyid"].ToString();
            //类型
            var       saleactivitytypeid       = HttpContext.Current.Request.QueryString["saleactivitytypeid"].ToString();
            var       begindate                = HttpContext.Current.Request.QueryString["begindate"].ToString();
            var       enddate                  = HttpContext.Current.Request.QueryString["enddate"].ToString();
            IDatabase database                 = DataFactory.Database();
            IRepository <ActivityViewModel> re = new Repository <ActivityViewModel>();
            DataTable data     = new DataTable();
            string    strwhere = "";

            if (!string.IsNullOrEmpty(activitareaid))
            {
                strwhere += " and ActivitAreaId=" + activitareaid;
            }
            if (!string.IsNullOrEmpty(agencyid))
            {
                strwhere += " and AgencyId=" + agencyid;
            }
            if (!string.IsNullOrEmpty(saleactivitytypeid))
            {
                strwhere += " and SaleActivityTypeId=" + saleactivitytypeid;
            }
            if (!string.IsNullOrEmpty(begindate))
            {
                strwhere += " and ActivityDate>='" + begindate + "'";
            }
            if (!string.IsNullOrEmpty(enddate))
            {
                strwhere += " and ActivityDate<='" + enddate + "'";
            }
            data = database.FindTableBySql("select * from View_Activity where IsDelete=0 " + strwhere + "");
            var newd = data.Columns.Add("publishwaycontent", typeof(String));
            var list = new Utilities.PublishWay().ToSelectListItem();

            for (int i = 0; i < data.Rows.Count; i++)
            {
                string str = data.Rows[i]["publishway"].ToString();
                if (!string.IsNullOrEmpty(str))
                {
                    string[] arrstr            = str.Split(',');
                    string   publishwaycontent = "";
                    if (!string.IsNullOrEmpty(str))
                    {
                        foreach (var item in list)
                        {
                            foreach (var item1 in arrstr)
                            {
                                if (item.Value == item1)
                                {
                                    publishwaycontent += item.Text + ",";
                                }
                            }
                        }
                    }
                    data.Rows[i]["publishwaycontent"] = publishwaycontent.Substring(0, publishwaycontent.Length - 1);
                }
                else
                {
                    data.Rows[i]["publishwaycontent"] = "";
                }
            }
            AppLibrary.WriteExcel.XlsDocument doc = new AppLibrary.WriteExcel.XlsDocument();
            // HttpContext.Current.Response.Write();
            doc.FileName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls";
            string    sheetname = "SHEET";
            Worksheet sheet     = doc.Workbook.Worksheets.Add(sheetname);
            Cells     cells     = sheet.Cells;
            XF        XFstyle   = doc.NewXF();

            XFstyle.HorizontalAlignment = HorizontalAlignments.Centered;
            cells.Add(1, 1, "经销商名称");
            cells.Add(1, 2, "区域");
            cells.Add(1, 3, "日期");
            cells.Add(1, 4, "活动类别");
            cells.Add(1, 5, "活动客流量");
            cells.Add(1, 6, "活动潜客量");
            cells.Add(1, 7, "活动车主量");
            cells.Add(1, 8, "活动现场订单量");
            cells.Add(1, 9, "活动成本金额");
            cells.Add(1, 10, "活动后续订单量");
            cells.Add(1, 11, "宣传类型");
            int f = 1;

            for (int i = 0; i < data.Rows.Count; i++)
            {
                f++;
                cells.Add(f, 1, data.Rows[i]["agencyname"]);
                cells.Add(f, 2, data.Rows[i]["activityareaname"]);
                cells.Add(f, 3, DateTime.Parse(data.Rows[i]["activitydate"].ToString()).ToString("yyyy-MM-dd"));
                cells.Add(f, 4, data.Rows[i]["saleactivitytypename"]);
                cells.Add(f, 5, data.Rows[i]["passengerflow"]);
                cells.Add(f, 6, data.Rows[i]["latentpassengerflow"]);
                cells.Add(f, 7, data.Rows[i]["carowner"]);
                cells.Add(f, 8, data.Rows[i]["orderquantity"]);
                cells.Add(f, 9, data.Rows[i]["primecost"]);
                cells.Add(f, 10, data.Rows[i]["laterorderquantity"]);
                cells.Add(f, 11, data.Rows[i]["publishwaycontent"]);
            }
            doc.Send();
            HttpContext.Current.Response.Flush();
            HttpContext.Current.Response.End();
        }