Esempio n. 1
0
        public ActionResult ExportPivotChart()
        {
            PrintingSystem ps = new PrintingSystem();

            PrintableComponentLink pclPivot = new PrintableComponentLink(ps);

            pclPivot.Component = PivotGridExtension.CreatePrintableObject(GetPivotGridSettings(), GetSalesPersonData());

            PrintableComponentLink pclChart = new PrintableComponentLink(ps);

            using (MemoryStream chartLayout = new MemoryStream())
            {
                GetChartSettings().SaveToStream(chartLayout);
                MVCxChartControl chart = new MVCxChartControl();
                chart.LoadFromStream(chartLayout);
                chart.DataSource = PivotGridExtension.GetDataObject(GetPivotGridSettings(), GetSalesPersonData(), true);
                chart.Width      = 900;
                chart.Height     = 400;
                chart.DataBind();
                pclChart.Component = ((IChartContainer)chart).Chart;
            }

            CompositeLink compositeLink = new CompositeLink(ps);

            compositeLink.Links.AddRange(new object[] { pclPivot, pclChart });
            compositeLink.CreateDocument();

            MemoryStream stream = new MemoryStream();

            compositeLink.PrintingSystem.ExportToXls(stream);
            stream.Position = 0;
            ps.Dispose();
            return(File(stream, "application/ms-excel", "PivotWithChart.xls"));
        }
Esempio n. 2
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            PrintingSystem ps = new PrintingSystem();

            PrintableComponentLink link1 = new PrintableComponentLink();

            link1.Component      = ASPxPivotGridExporter1;
            link1.PrintingSystem = ps;

            Link link2 = new Link();

            link2.CreateDetailArea += new CreateAreaEventHandler(link2_CreateDetailArea);
            link2.PrintingSystem    = ps;

            CompositeLink compositeLink = new CompositeLink();

            compositeLink.Links.AddRange(new object[] { link2, link1 });
            compositeLink.PrintingSystem = ps;

            compositeLink.CreateDocument();
            compositeLink.PrintingSystem.ExportOptions.Pdf.DocumentOptions.Author = "Test";

            using (MemoryStream stream = new MemoryStream())
            {
                compositeLink.PrintingSystem.ExportToPdf(stream);
                Response.Clear();
                Response.Buffer = false;
                Response.AppendHeader("Content-Type", "application/pdf");
                Response.AppendHeader("Content-Transfer-Encoding", "binary");
                Response.AppendHeader("Content-Disposition", "attachment; filename=test.pdf");
                Response.BinaryWrite(stream.ToArray());
                Response.End();
            }
            ps.Dispose();
        }
Esempio n. 3
0
        private void GenerateGrid()
        {
            CompositeLink composLink = new CompositeLink(new PrintingSystem());
            PrintableComponentLink pcLink1 = new PrintableComponentLink();
            Link linkMainReport = new Link();
            Link linkGrid1Report = new Link();
            linkGrid1Report.CreateDetailArea += new CreateAreaEventHandler(linkGrid1Report_CreateDetailArea);

            // Assign the controls to the printing links.
            pcLink1.Component = this.ThirdGridIncomeAnalysis;

            // Populate the collection of links in the composite link.
            // The order of operations corresponds to the document structure.
            composLink.Links.Add(linkGrid1Report);
            composLink.Links.Add(pcLink1);
            composLink.Links.Add(linkMainReport);

            // Create the report and show the preview window.
            //composLink.PrintingSystem.PreviewFormEx.AutoScale = true;
            composLink.PrintingSystem.PageSettings.Landscape = true;
            composLink.CreateDocument(printingSystem1);
            printingSystem1.PreviewFormEx.PrintingSystem.PageSettings.LeftMargin = 0;
            printingSystem1.PreviewFormEx.PrintingSystem.PageSettings.TopMargin = 30;
            //printingSystem1.PreviewFormEx.AutoScale = true;
            printingSystem1.PageSettings.Landscape = true;
            printingSystem1.PreviewFormEx.ForeColor = System.Drawing.Color.Black;
            printingSystem1.PreviewFormEx.Owner = this;
            printingSystem1.PreviewFormEx.PrintingSystem.Print();
        }
Esempio n. 4
0
        private void GenerateGrid()
        {
            CompositeLink          composLink = new CompositeLink(new PrintingSystem());
            PrintableComponentLink pcLink1    = new PrintableComponentLink();
            Link linkMainReport  = new Link();
            Link linkGrid1Report = new Link();

            linkGrid1Report.CreateDetailArea += new CreateAreaEventHandler(linkGrid1Report_CreateDetailArea);

            // Assign the controls to the printing links.
            pcLink1.Component = this.ThirdGridIncomeAnalysis;


            // Populate the collection of links in the composite link.
            // The order of operations corresponds to the document structure.
            composLink.Links.Add(linkGrid1Report);
            composLink.Links.Add(pcLink1);
            composLink.Links.Add(linkMainReport);

            // Create the report and show the preview window.
            //composLink.PrintingSystem.PreviewFormEx.AutoScale = true;
            composLink.PrintingSystem.PageSettings.Landscape = true;
            composLink.CreateDocument(printingSystem1);
            printingSystem1.PreviewFormEx.PrintingSystem.PageSettings.LeftMargin = 0;
            printingSystem1.PreviewFormEx.PrintingSystem.PageSettings.TopMargin  = 30;
            //printingSystem1.PreviewFormEx.AutoScale = true;
            printingSystem1.PageSettings.Landscape  = true;
            printingSystem1.PreviewFormEx.ForeColor = System.Drawing.Color.Black;
            printingSystem1.PreviewFormEx.Owner     = this;
            printingSystem1.PreviewFormEx.PrintingSystem.Print();
        }
    private void ExportToXls()
    {
        btn_search_Click(null, null);
        PrintingSystem ps = new PrintingSystem();

        PrintableComponentLink link1 = new PrintableComponentLink();

        //link1.Component = ASPxPivotGridExporter1;
        link1.PrintingSystem = ps;

        PrintableComponentLink link2 = new PrintableComponentLink();

        WebChartControl1.DataBind();
        link2.Component      = ((IChartContainer)WebChartControl1).Chart;
        link2.PrintingSystem = ps;

        CompositeLink compositeLink = new CompositeLink();

        compositeLink.Links.AddRange(new object[] { link1, link2 });
        compositeLink.PrintingSystem = ps;

        compositeLink.CreateDocument();
        compositeLink.PrintingSystem.ExportOptions.Pdf.DocumentOptions.Author = "Test";
        using (MemoryStream stream = new MemoryStream())
        {
            compositeLink.PrintingSystem.ExportToPdf(stream);


            byte[] bt = stream.GetBuffer();
            if (bt.Length > 0)
            {
                Response.Clear();
                Response.ClearHeaders();
                Response.ClearContent();
                Response.Buffer      = true;
                Response.ContentType = "application/xls";
                Response.AddHeader("Content-Length", bt.Length.ToString());
                Response.AddHeader("Content-Disposition", "inline; filename=123.xls");
                Response.BinaryWrite(bt);
            }
        }

        ps.Dispose();
    }
    private void ExportToPdf()
    {
        PrintingSystem ps = new PrintingSystem();

        PrintableComponentLink link1 = new PrintableComponentLink();

        //link1.Component = ASPxPivotGridExporter1;
        link1.PrintingSystem = ps;

        PrintableComponentLink link2 = new PrintableComponentLink();

        WebChartControl1.DataBind();
        link2.Component      = ((IChartContainer)WebChartControl1).Chart;
        link2.PrintingSystem = ps;

        CompositeLink compositeLink = new CompositeLink();

        compositeLink.Links.AddRange(new object[] { link1, link2 });
        compositeLink.PrintingSystem = ps;

        compositeLink.CreateDocument();
        compositeLink.PrintingSystem.ExportOptions.Pdf.DocumentOptions.Author = "Test";
        using (MemoryStream stream = new MemoryStream())
        {
            compositeLink.PrintingSystem.ExportToPdf(stream);
            Response.Clear();
            Response.Buffer = false;
            Response.AppendHeader("Content-Type", "application/pdf");
            Response.AppendHeader("Content-Transfer-Encoding", "binary");
            Response.AppendHeader("Content-Disposition", "attachment; filename=test.pdf");
            Response.BinaryWrite(stream.GetBuffer());
            Response.End();
        }

        ps.Dispose();
    }
Esempio n. 7
0
 protected virtual void CreateDocument(CompositeLink link)
 {
     link.CreateDocument();
 }
Esempio n. 8
0
        public void CreateReport()
        {
            var link = new CompositeLink(new PrintingSystem());

            var link1 = new PrintableComponentLink();
            var pcLink1 = new PrintableComponentLink();
            var footer = new PageFooterArea();
            footer.Content.Add("Printed on " + "[Date Printed]" + " by " + Utils.Username);
            footer.LineAlignment = BrickAlignment.Near;
            var header = new PageHeaderArea();
            link.CreateMarginalHeaderArea += CreateMarginalHeaderArea;
            link.PageHeaderFooter = new PageHeaderFooter(header, footer);
            link.PrintingSystem.SetCommandVisibility(PrintingSystemCommand.Save, CommandVisibility.None);
            link.PrintingSystem.SetCommandVisibility(PrintingSystemCommand.Watermark, CommandVisibility.None);
            link.PrintingSystem.SetCommandVisibility(PrintingSystemCommand.FillBackground, CommandVisibility.None);
            link.PrintingSystem.SetCommandVisibility(PrintingSystemCommand.HandTool, CommandVisibility.None);
            link.PrintingSystem.SetCommandVisibility(PrintingSystemCommand.Open, CommandVisibility.None);
            link.PrintingSystem.SetCommandVisibility(PrintingSystemCommand.Customize, CommandVisibility.None);
            link.PrintingSystem.SetCommandVisibility(PrintingSystemCommand.Scale, CommandVisibility.None);
            link.PrintingSystem.SetCommandVisibility(PrintingSystemCommand.Parameters, CommandVisibility.None);
            link.PrintingSystem.SetCommandVisibility(PrintingSystemCommand.SubmitParameters, CommandVisibility.None);
            link.PrintingSystem.SetCommandVisibility(PrintingSystemCommand.Background, CommandVisibility.None);
            link.PrintingSystem.SetCommandVisibility(PrintingSystemCommand.None, CommandVisibility.None);
            link.PrintingSystem.SetCommandVisibility(PrintingSystemCommand.DocumentMap, CommandVisibility.None);
  


            link.PrintingSystem.PreviewRibbonFormEx.RibbonControl.Pages["Print Preview"].Groups["Document"].Visible = false;
            link.PrintingSystem.PreviewRibbonFormEx.RibbonControl.Pages["Print Preview"].Groups["Background"].Visible =false;
            link.PrintingSystem.PreviewRibbonFormEx.RibbonControl.Pages["Print Preview"].Groups["Zoom"].Visible =false;


            link.Margins.Left = 100;
            link.Margins.Right = 100;
            link.Margins.Top = 100;
            link.Margins.Bottom = 90;
            link.PaperKind = PaperKind.A4;

            var linkGrid1Report = new Link();
            linkGrid1Report.CreateDetailArea += linkGrid1Report_CreateDetailArea;


            var linkGrid2Report = new Link();

           // link.PrintingSystem.Document.AutoFitToPagesWidth = 1;

            link1.Component = gridControl1;
            

             
            link.Links.Add(link1);

            link.Links.Add(linkGrid1Report);
            pcLink1.Component = gridControl2;
            link.Links.Add(pcLink1);
            

            link.CreateDocument();

            //if (string.IsNullOrEmpty(watermark))
            //    link.PrintingSystemBase.Watermark.Text = "Draft";
            //else
            //{
            //    link.PrintingSystemBase.Watermark.Text = "watermark";
            //}
            link.ShowRibbonPreview(UserLookAndFeel.Default);


        }
Esempio n. 9
0
        /// <summary>
        /// 匯出Excel
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected override void ToExcelButton_Click(object sender, EventArgs e)
        {
            base.ToExcelButton_Click(sender, e);
            if (tabControl1.SelectedIndex == 0)
            {
                if (gridView1.RowCount <= 0)
                {
                    MessageBox.Show("無內容,請重新查詢", "取消儲存");
                    return;
                }
            }
            else
            {
                if (gridView3.RowCount <= 0)
                {
                    MessageBox.Show("無內容,請重新查詢", "取消儲存");
                    return;
                }
            }
            SaveFileDialog OFD = new SaveFileDialog();

            OFD.InitialDirectory = "D:\\";
            OFD.RestoreDirectory = true;
            OFD.Title            = "儲存檔案";
            OFD.DefaultExt       = "xls";
            OFD.Filter           = "Microsoft Office Excel 活頁簿 (*.xls)|*.xls";

            GridControl[] grids;

            if (tabControl1.SelectedIndex == 0)
            {
                //合併兩個gridcontrol到同一個報表
                grids = new GridControl[] { gridControl1 };
            }
            else
            {
                grids = new GridControl[] { gridControl3 };
            }

            OFD.FileName = FileName_OutPutExcel;
            DialogResult chooseOutPut = OFD.ShowDialog();

            if (chooseOutPut == DialogResult.Cancel)
            {
                return;
            }

            //gridview排版
            gridView1.OptionsView.ColumnAutoWidth = false;
            gridView1.OptionsPrint.AutoWidth      = false;
            gridView1.BestFitColumns();
            gridView2.OptionsView.ColumnAutoWidth = false;
            gridView2.OptionsPrint.AutoWidth      = false;
            gridView2.BestFitColumns();
            gridView3.OptionsView.ColumnAutoWidth = false;
            gridView3.OptionsPrint.AutoWidth      = false;
            gridView3.BestFitColumns();
            gridView1.AppearancePrint.Row.Font            = new Font("Arial Unicode MS", 12);
            gridView1.AppearancePrint.Row.Options.UseFont = true;
            gridView2.AppearancePrint.Row.Font            = new Font("Arial Unicode MS", 12);
            gridView2.AppearancePrint.Row.Options.UseFont = true;
            gridView3.AppearancePrint.Row.Font            = new Font("Arial Unicode MS", 12);
            gridView3.AppearancePrint.Row.Options.UseFont = true;

            PrintingSystem ps            = new PrintingSystem();
            CompositeLink  compositeLink = new CompositeLink();

            compositeLink.PrintingSystem = ps;

            foreach (GridControl gc in grids)
            {
                PrintableComponentLink link = new PrintableComponentLink();
                link.Component = gc;

                compositeLink.Links.Add(link);
            }
            compositeLink.CreateDocument();

            //準備輸出
            DevExpress.XtraPrinting.XlsExportOptions XEO = new DevExpress.XtraPrinting.XlsExportOptions();
            XEO.TextExportMode = DevExpress.XtraPrinting.TextExportMode.Text;
            XEO.ExportMode     = XlsExportMode.SingleFile;
            XEO.SheetName      = FileName_OutPutExcel;

            DevExpress.XtraPrinting.PdfExportOptions PEO = new PdfExportOptions();
            //PEO.PasswordSecurityOptions.OpenPassword = "******";

            #region 檢查檔案是否能寫入
            bool IsFileLocked = false;
            if (File.Exists(OFD.FileName))
            {
                FileInfo   filepath = new FileInfo(OFD.FileName);
                FileStream steam    = null;
                try
                {
                    steam = filepath.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None);
                }
                catch (IOException e1)
                {
                    IsFileLocked = true;
                }
                finally
                {
                    if (steam != null)
                    {
                        steam.Close();
                    }
                }
            }
            #endregion
            if (IsFileLocked)
            {
                MessageBox.Show("檔案被鎖定,請檢查是否有其他程式正在開啟", "匯出失敗");
                return;
            }
            compositeLink.ExportToXls(OFD.FileName, XEO);
            //gridView1.ExportToXls(OFD.FileName, XEO);
            MessageBox.Show("檔案匯出至 " + OFD.FileName + " 完畢", "匯出成功");

            //gridview排版
            gridView1.OptionsView.ColumnAutoWidth = true;
            gridView1.OptionsPrint.AutoWidth      = true;
            gridView1.BestFitColumns();
            gridView2.OptionsView.ColumnAutoWidth = true;
            gridView2.OptionsPrint.AutoWidth      = true;
            gridView2.BestFitColumns();
            gridView3.OptionsView.ColumnAutoWidth = true;
            gridView3.OptionsPrint.AutoWidth      = true;
            gridView3.BestFitColumns();
        }