private void sbExport_Click(object sender, EventArgs e) { var sfd = new SaveFileDialog(); sfd.Filter = "Excel File (*.xlsx)|*.xlsx"; if (sfd.ShowDialog(this) == DialogResult.OK) { var printingSystem = new PrintingSystemBase(); var compositeLink = new CompositeLinkBase(); compositeLink.PrintingSystemBase = printingSystem; var link = new PrintableComponentLinkBase(); link.Component = gcRawData; compositeLink.Links.Add(link); link = new PrintableComponentLinkBase(); link.Component = gcSummary; compositeLink.Links.Add(link); var options = new XlsxExportOptions(); options.ExportMode = XlsxExportMode.SingleFilePageByPage; compositeLink.CreatePageForEachLink(); compositeLink.ExportToXlsx(sfd.FileName, options); System.Diagnostics.Process.Start(sfd.FileName); } }
private void toExcel() { XlsxExportOptions opt = new XlsxExportOptions(); opt.ExportMode = XlsxExportMode.SingleFilePageByPage; string FileName = "C:\\CORRECT\\XLS\\" + Reportenombre + ".xlsx"; opt.SheetName = "NEW"; //gridView1.ExportToXlsx(FileName); gridView1.OptionsPrint.ExpandAllDetails = true; gridView1.OptionsPrint.PrintDetails = true; gridView1.OptionsPrint.ExpandAllGroups = true; //gridView2.OptionsPrint.ExpandAllDetails = true; //gridView2.OptionsPrint.PrintDetails = true; gridView1.ZoomView(); //CompositeLink conp = new CompositeLink(); var printingSystem = new PrintingSystemBase(); var compositeLink = new CompositeLinkBase(); compositeLink.PrintingSystemBase = printingSystem; var link1 = new PrintableComponentLinkBase(); link1.Component = gridControl1; //var link2 = new PrintableComponentLinkBase(); //link2.Component = grid2; compositeLink.Links.Add(link1); // compositeLink.Links.Add(link2); var options = new XlsxExportOptions(); options.ExportMode = XlsxExportMode.SingleFilePageByPage; compositeLink.CreatePageForEachLink(); compositeLink.ExportToXlsx(FileName, options); //conp.ExportToXlsx(FileName, opt); //gridView1.ExportToXlsx(FileName,opt); //gridControl1.DefaultView Microsoft.Office.Interop.Excel.Application excell; Microsoft.Office.Interop.Excel.Workbook workbook; excell = new Excel.Application(); excell.Visible = true; workbook = excell.Workbooks.Open(FileName); }
private void ConfigureExport(ASPxGridView grid) { PrintingSystemBase ps = new PrintingSystemBase(); ps.ExportOptions.Xlsx.SheetName = "Tipos de Documentos"; ps.XlSheetCreated += ps_XlSheetCreated; PrintableComponentLinkBase link1 = new PrintableComponentLinkBase(ps); link1.PaperName = "DatosGenerales"; link1.Component = Exporter; CompositeLinkBase compositeLink = new CompositeLinkBase(ps); compositeLink.Links.AddRange(new object[] { link1 }); compositeLink.CreatePageForEachLink(); ps.Dispose(); grid.Settings.ShowColumnHeaders = true; }
private void xuấtExcelToolStripMenuItem_Click(object sender, EventArgs e) { if (xuatExcelDialog.ShowDialog() == DialogResult.OK) { var compositeLink = new CompositeLinkBase(); compositeLink.PrintingSystemBase = ps; var sheetTnBao = new PrintableComponentLinkBase(); sheetTnBao.Component = gridcontrol_tinbao; var sheetXLK = new PrintableComponentLinkBase(); sheetXLK.Component = gridControl_xlk; compositeLink.Links.Add(sheetTnBao); compositeLink.Links.Add(sheetXLK); var options = new XlsxExportOptions(); options.ExportMode = XlsxExportMode.SingleFilePageByPage; compositeLink.CreatePageForEachLink(); compositeLink.ExportToXlsx(xuatExcelDialog.FileName, options); } }
protected void ExportButton_Click(object sender, EventArgs e) { PrintingSystemBase ps = new PrintingSystemBase(); PrintableComponentLinkBase link1 = new PrintableComponentLinkBase(ps); link1.Component = GridExporter; PrintableComponentLinkBase link2 = new PrintableComponentLinkBase(ps); link2.Component = TreeListExporter; PrintableComponentLinkBase link3 = new PrintableComponentLinkBase(ps); Chart.DataBind(); link3.Component = ((IChartContainer)Chart).Chart; CompositeLinkBase compositeLink = new CompositeLinkBase(ps); compositeLink.Links.AddRange(new object[] { link1, link2, link3 }); compositeLink.CreatePageForEachLink(); using (MemoryStream stream = new MemoryStream()) { XlsxExportOptions options = new XlsxExportOptions(); options.ExportMode = XlsxExportMode.SingleFilePageByPage; compositeLink.PrintingSystemBase.ExportToXlsx(stream, options); Response.Clear(); Response.Buffer = false; Response.AppendHeader("Content-Type", "application/xlsx"); Response.AppendHeader("Content-Transfer-Encoding", "binary"); Response.AppendHeader("Content-Disposition", "attachment; filename=test.xlsx"); Response.BinaryWrite(stream.ToArray()); Response.End(); } ps.Dispose(); }
public void exportToExcel( ) { using (var saveDialog = new SaveFileDialog()) { DialogResult dialogResult = default(DialogResult); var _with1 = saveDialog; _with1.Filter = "Microsoft Excel|*.xls"; _with1.Title = "Save as Excel"; _with1.FileName = string.Format("{0}_{1}", this.Text, DateTime.Today.ToString("yyyyMMdd")); _with1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); if (_with1.ShowDialog() == DialogResult.OK) { try { var printingSystem = new PrintingSystemBase(); var compositeLink = new CompositeLinkBase(); compositeLink.PrintingSystemBase = printingSystem; var link1 = new PrintableComponentLinkBase(); link1.Component = gcTotal; //link1.PaperName = gcTotal.Tag.ToString(); var link2 = new PrintableComponentLinkBase(); link2.Component = gcDetail; //link2.PaperName = gcDetail.Tag.ToString(); var link3 = new PrintableComponentLinkBase(); link3.Component = gcCandidate; //link3.PaperName = gcCandidate.Tag.ToString(); compositeLink.Links.Add(link1); compositeLink.Links.Add(link2); compositeLink.Links.Add(link3); var options = new XlsxExportOptions(); options.ExportMode = XlsxExportMode.SingleFilePageByPage; compositeLink.CreatePageForEachLink(); compositeLink.ExportToXlsx(_with1.FileName, options); string strexcelversion = Functions.GetOfficeVersion(); if (int.Parse(strexcelversion) >= 2007) { Microsoft.Office.Interop.Excel.Application exc = new Microsoft.Office.Interop.Excel.Application(); Microsoft.Office.Interop.Excel.Workbook workbook = exc.Workbooks.Open(_with1.FileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); Microsoft.Office.Interop.Excel.Sheets sheets = workbook.Worksheets; Microsoft.Office.Interop.Excel.Worksheet sheet1 = (Microsoft.Office.Interop.Excel.Worksheet)(sheets[1]); Microsoft.Office.Interop.Excel.Worksheet sheet2 = (Microsoft.Office.Interop.Excel.Worksheet)(sheets[2]); Microsoft.Office.Interop.Excel.Worksheet sheet3 = (Microsoft.Office.Interop.Excel.Worksheet)(sheets[3]); sheet1.Name = gcTotal.Tag.ToString(); sheet2.Name = gcDetail.Tag.ToString(); sheet3.Name = gcCandidate.Tag.ToString(); workbook.Close(true, Type.Missing, Type.Missing); exc.Quit(); } //System.Diagnostics.Process.Start(_with1.FileName); DialogResult = XtraMessageBox.Show("Do you want to open this file?", "Information", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); if (DialogResult == DialogResult.Yes) { System.Diagnostics.Process.Start(_with1.FileName); } else { XtraMessageBox.Show("Export Succeeded!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { XtraMessageBox.Show("Could not export to excel file." + Environment.NewLine + ex.Message.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }