🙂 İNSANLARIN EN HAYIRLISI INSANLARA FAYDALI OLANDIR 🙂

Ramazan HABER / C# RMOS / gridview print ve dışa aktarma excel kaydetme pdf vs. SaveFileDialog

1-) C# RMOS - gridview print ve dışa aktarma excel kaydetme pdf vs. SaveFileDialog

 

 

 gridView1.ShowPrintPreview();

....

 private void gridView2_PrintInitialize(object sender, DevExpress.XtraGrid.Views.Base.PrintInitializeEventArgs e)

        {

            PrintingSystemBase pb = e.PrintingSystem as PrintingSystemBase;

            pb.PageSettings.Landscape = true;

        }

 

 

1-) EXCEL , PDF VS

 

 

public void yazdir(GridControl gridControl)

        {

            using (SaveFileDialog saveDialog = new SaveFileDialog())

            {

                saveDialog.Filter = "Excel (2010) (.xlsx)|*.xlsx|Excel (2003)(.xls)|*.xls|RichText File (.rtf)|*.rtf |Pdf File (.pdf)|*.pdf |Html File (.html)|*.html";

                if (saveDialog.ShowDialog() != DialogResult.Cancel)

                {

                    string exportFilePath = saveDialog.FileName;

                    string fileExtenstion = new FileInfo(exportFilePath).Extension;

 

                    switch (fileExtenstion)

                    {

                        case ".xls":

                            gridControl.ExportToXls(exportFilePath);

                            break;

                        case ".xlsx":

                            gridControl.ExportToXlsx(exportFilePath);

                            break;

                        case ".rtf":

                            gridControl.ExportToRtf(exportFilePath);

                            break;

                        case ".pdf":

                            gridControl.ExportToPdf(exportFilePath);

                            break;

                        case ".html":

                            gridControl.ExportToHtml(exportFilePath);

                            break;

                        case ".mht":

                            gridControl.ExportToMht(exportFilePath);

                            break;

                        default:

                            break;

                    }

 

                //string dosyaKonum = Path.GetDirectoryName(Application.ExecutablePath);

 

                   string basePath= Path.GetDirectoryName(exportFilePath);

 

                    var p = new Process();

                    p.StartInfo = new ProcessStartInfo(basePath)

                    {

                        UseShellExecute = true

                    };

                    p.Start();

                }

            }

        }

 

 

 

2-) DİĞER

 

  public void yazdir(GridControl gridControl)

        {

            using (SaveFileDialog saveDialog = new SaveFileDialog())

            {

                saveDialog.Filter = "Excel (2003)(.xls)|*.xls|Excel (2010) (.xlsx)|*.xlsx |RichText File (.rtf)|*.rtf |Pdf File (.pdf)|*.pdf |Html File (.html)|*.html";

                if (saveDialog.ShowDialog() != DialogResult.Cancel)

                {

                    string exportFilePath = saveDialog.FileName;

                    string fileExtenstion = new FileInfo(exportFilePath).Extension;

 

                    switch (fileExtenstion)

                    {

                        case ".xls":

                            gridControl.ExportToXls(exportFilePath);

                            break;

                        case ".xlsx":

                            gridControl.ExportToXlsx(exportFilePath);

                            break;

                        case ".rtf":

                            gridControl.ExportToRtf(exportFilePath);

                            break;

                        case ".pdf":

                            gridControl.ExportToPdf(exportFilePath);

                            break;

                        case ".html":

                            gridControl.ExportToHtml(exportFilePath);

                            break;

                        case ".mht":

                            gridControl.ExportToMht(exportFilePath);

                            break;

                        default:

                            break;

                    }

 

                    if (File.Exists(exportFilePath))

                    {

                        try

                        {

                            //Try to open the file and let windows decide how to open it.

                           var p = new Process();

                            p.StartInfo = new ProcessStartInfo(exportFilePath)

                            {

                                UseShellExecute = true

                            };

                            p.Start();

 

 

                        }

                        catch

                        {

                            String msg = "The file could not be opened." + Environment.NewLine + Environment.NewLine + "Path: " + exportFilePath;

                            MessageBox.Show(msg, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);

                        }

                    }

                    else

                    {

                        String msg = "The file could not be saved." + Environment.NewLine + Environment.NewLine + "Path: " + exportFilePath;

                        MessageBox.Show(msg, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    }

                }

            }

 2022 Ağustos 06 Cumartesi
 1,193