Esempio n. 1
0
        public ActionResult ToExcel()
        {
            Acc_Account account  = GAccount.GetAccountInfo();
            string      unit     = account.UnitID.ToString();
            string      unitName = account.UnitName;

            string where = " and a.Unit = '" + unit + "'";
            string strCurPage;
            string strRowNum;
            string Cname      = Request["cname"].ToString();
            string ContractID = Request["contractID"].ToString();
            string year       = DateTime.Now.ToString("yyyy");

            if (Request["curpage"] != null)
            {
                strCurPage = Request["curpage"].ToString();
            }
            if (Request["rownum"] != null)
            {
                strRowNum = Request["rownum"].ToString();
            }
            else
            {
                strRowNum = "10";
            }
            if (Cname != "")
            {
                where += " and a.Cname like '%" + Cname + "%'";
            }
            if (ContractID != "")
            {
                where += " and a.ContractID like '%" + ContractID + "%'";
            }
            DataTable data = ContractMan.getNewPrintStandingBook(where);

            if (data != null)
            {
                string strCols = "序号-2000,合同编号-5000,合同名称-5000,内容-5000,签署日期-5000,甲方单位-7000,乙方单位-7000,合同金额-5000,页数-5000,经办人-5000,备注-7000";
                data.Columns["xu"].SetOrdinal(0);
                System.IO.MemoryStream stream = ExcelHelper.ExportDataTableToExcel(data, year + "年" + unitName + "合同管理台账", strCols.Split(','));
                stream.Seek(0, System.IO.SeekOrigin.Begin);
                return(File(stream, "application/vnd.ms-excel", "Info.xls"));
            }
            else
            {
                return(null);
            }
        }