Exemplo n.º 1
0
        public ActionResult ExportPayDetail(string payMonth)
        {
            IExcel         excel   = ExcelFactory.CreateDefault();
            PaymentManager payment = new PaymentManager();
            DataSet        ds      = payment.ExportDetail(payMonth);
            POIStream      stream  = new POIStream();

            stream.AllowClose = false;
            excel.Write(stream, ds, ExcelExtendType.XLSX);
            stream.AllowClose = true;
            byte[] buffer = new byte[stream.Length];
            stream.Position = 0;
            stream.Read(buffer, 0, buffer.Length);
            stream.Close();

            HttpResponse context = System.Web.HttpContext.Current.Response;

            try
            {
                context.ContentType = "application/ms-excel";
                context.AddHeader("Content-Disposition", string.Format("attachment; filename={0}.xlsx", HttpUtility.UrlEncode(payMonth + "个税信息", System.Text.Encoding.UTF8)));
                context.BinaryWrite(buffer);
                context.Flush();
                context.End();
            }
            catch (Exception ex)
            {
                context.ContentType = "text/plain";
                context.Write(ex.Message);
            }
            return(null);
        }
Exemplo n.º 2
0
        public ActionResult Export()
        {
            List <CompanyInfo> list      = new Manager.EmployeeManager().GetCompanies(string.Empty);
            IExcel             excel     = ExcelFactory.CreateDefault();
            DataTable          dataTable = Converts.ListToDataTable <CompanyInfo>(list);

            dataTable.Columns["Name"].Caption           = "单位名称";
            dataTable.Columns["Code"].Caption           = "组织机构代码";
            dataTable.Columns["Representative"].Caption = "法人";
            dataTable.Columns["AccountBalance"].Caption = "账户余额";
            dataTable.Columns.Remove("CompanyId");
            dataTable.Columns.Remove("AccountId");
            dataTable.Columns.Remove("Positions");
            dataTable.Columns.Remove("Remark");
            DataSet dataSet = new DataSet();

            dataSet.Tables.Add(dataTable);
            POIStream stream = new POIStream();

            stream.AllowClose = false;
            excel.Write(stream, dataSet, ExcelExtendType.XLSX);
            stream.AllowClose = true;
            byte[] buffer = new byte[stream.Length];
            stream.Position = 0;
            stream.Read(buffer, 0, buffer.Length);
            stream.Dispose();

            HttpResponse context = System.Web.HttpContext.Current.Response;

            try
            {
                context.ContentType = "application/ms-excel";
                context.AddHeader("Content-Disposition", string.Format("attachment; filename={0}.xlsx", HttpUtility.UrlEncode("单位信息", System.Text.Encoding.UTF8)));
                context.BinaryWrite(buffer);
                context.Flush();
                context.End();
            }
            catch (Exception ex)
            {
                context.ContentType = "text/plain";
                context.Write(ex.Message);
            }
            return(null);
        }
Exemplo n.º 3
0
        // GET: Reports/GetWxyjByYear/
        public ActionResult DownWxyjByYear(int year)
        {
            ReportManager manager = new ReportManager();
            DataSet       ds      = manager.GetWxyjByYear(year);

            ds.Tables[0].TableName = "sheet1";

            POIStream stream = new POIStream();
            IExcel    excel  = ExcelFactory.CreateDefault();

            stream.AllowClose = false;
            //excel.Write(stream, ds, ExcelExtendType.XLSX);
            string templateName = AppDomain.CurrentDomain.BaseDirectory + @"\Setting\Reports\wxyjYear.xml";

            excel.Write(stream, templateName, ds, ExcelExtendType.XLSX);
            stream.AllowClose = true;
            byte[] buffer = new byte[stream.Length];
            stream.Position = 0;
            stream.Read(buffer, 0, buffer.Length);
            stream.Close();

            HttpResponse context = System.Web.HttpContext.Current.Response;

            try
            {
                context.ContentType = "application/ms-excel";
                context.AddHeader("Content-Disposition", string.Format("attachment; filename={0}.xlsx", HttpUtility.UrlEncode("单位五险一金统计", System.Text.Encoding.UTF8)));
                context.BinaryWrite(buffer);
                context.Flush();
                context.End();
            }
            catch (Exception ex)
            {
                context.ContentType = "text/plain";
                context.Write(ex.Message);
            }
            return(null);
        }
Exemplo n.º 4
0
        public ActionResult Export(int payId)
        {
            PaymentManager pm      = new PaymentManager();
            Payment        payment = pm.LoadPayment(payId);

            #region 动态模板
            TTemplate template = new TTemplate();
            TRow      R1       = new TRow();
            TRow      R2       = new TRow();
            int       index1   = 3;
            int       index2   = 3;
            TCell     A        = new TCell("PersonId", "ID", 0, 0); A.RowSpan = 2; A.Width = 1;
            TCell     B        = new TCell("PersonName", "姓名", 0, 1); B.RowSpan = 2;
            TCell     C        = new TCell("PersonCode", "身份证", 0, 2); C.RowSpan = 2;
            R1.Cells.Add(A);
            R1.Cells.Add(B);
            R1.Cells.Add(C);
            foreach (PayItemDO item in payment.Items)
            {
                TCell cell = new TCell();
                cell.Name    = item.ItemName;
                cell.Caption = item.ItemCaption;
                if (item.IsLeaf == true)
                {
                    //cell.Width = 50;
                }
                if (item.ParentId == 0)
                {
                    cell.RowIndex    = 0;
                    cell.ColumnIndex = index1;
                    int colspan = 1;
                    foreach (PayItemDO pi in payment.Items)
                    {
                        if (pi.ParentId == item.ItemId)
                        {
                            colspan++;
                        }
                    }
                    if (colspan == 1)
                    {
                        cell.RowSpan = 2;
                        index1++;
                        index2++;
                    }
                    else
                    {
                        cell.ColSpan = colspan - 1;
                        index1       = index1 + cell.ColSpan;
                    }
                    R1.Cells.Add(cell);
                }
                else
                {
                    cell.RowIndex    = 1;
                    cell.ColumnIndex = index2;
                    index2           = index2 + 1;
                    R2.Cells.Add(cell);
                }
            }

            TSheet tsheet = new TSheet();
            tsheet.Name  = "Sheet1";
            tsheet.Title = "Sheet1";
            tsheet.Head.Rows.Add(R1);
            tsheet.Head.Rows.Add(R2);
            template.Sheets.Add(tsheet);
            #endregion

            IExcel  excel = ExcelFactory.CreateDefault();
            DataSet ds    = new DataSet();
            payment.DataSource.TableName = "Sheet1";
            ds.Tables.Add(payment.DataSource);
            POIStream stream = new POIStream();
            stream.AllowClose = false;
            excel.Write(stream, template, ds, ExcelExtendType.XLSX);
            stream.AllowClose = true;
            byte[] buffer = new byte[stream.Length];
            stream.Position = 0;
            stream.Read(buffer, 0, buffer.Length);
            stream.Close();

            HttpResponse context = System.Web.HttpContext.Current.Response;
            try
            {
                context.ContentType = "application/ms-excel";
                context.AddHeader("Content-Disposition", string.Format("attachment; filename={0}.xlsx", HttpUtility.UrlEncode(payment.PayTitle, System.Text.Encoding.UTF8)));
                context.BinaryWrite(buffer);
                context.Flush();
                context.End();
            }
            catch (Exception ex)
            {
                context.ContentType = "text/plain";
                context.Write(ex.Message);
            }
            return(null);
        }