/// <summary> /// 把XtraGrid中的数据倒出到Txt 中 /// </summary> /// <param name="pDg"></param> /// <param name="pExportFullName"></param> public void ExportToText(DevExpress.XtraGrid.GridControl pDg, string pExportFullName) { if (pDg.MainView != null) { try { //ExportTxtProvider ex = new ExportTxtProvider(pExportFullName); //ExportTo(pDg, ex); TextExportOptions option = new TextExportOptions(); //option.Encoding = Encoding.UTF8; //转成中文格式,方便EXCEL直接打开 option.Encoding = System.Text.Encoding.GetEncoding("GB2312"); option.TextExportMode = TextExportMode.Value; option.Separator = "\t"; option.QuoteStringsWithSeparators = false; pDg.MainView.ExportToText(pExportFullName, option); } catch (Exception e) { throw e; } } }
public void ShowExportDialog() { using (var dlg = new SaveFileDialog()) { dlg.Title = "Tabelle exportieren"; dlg.RestoreDirectory = true; dlg.AddExtension = true; dlg.DefaultExt = ".xlsx"; dlg.Filter = "Excel Datei|*.xlsx|PDF-Dokument|*.pdf|CSV-Tabelle|*.csv|Rich-Text|*.rtf"; dlg.FilterIndex = 1; dlg.AutoUpgradeEnabled = true; dlg.CheckPathExists = true; dlg.ValidateNames = true; if (dlg.ShowDialog() != DialogResult.OK) { return; } try { this.isExporting = true; switch ((Path.GetExtension(dlg.FileName) ?? "").ToLower()) { case ".xlsx": this.ExportToXlsx(dlg.FileName); break; case ".csv": this.ExportToCsv(dlg.FileName); break; case ".pdf": this.ExportToPdf(dlg.FileName); break; case ".rtf": this.ExportToRtf(dlg.FileName); break; default: TextExportOptions opt = new TextExportOptions(); opt.Separator = "\t"; this.ExportToText(dlg.FileName, opt); break; } } finally { this.isExporting = false; } ProcessStartInfo psi = new ProcessStartInfo(); psi.UseShellExecute = true; psi.FileName = dlg.FileName; Process.Start(psi); } }
private void button1_Click(object sender, EventArgs e) { // A path to export a report. string reportPath = "c:\\Test.txt"; // Create a report instance. XtraReport1 report = new XtraReport1(); // Get its Text export options. TextExportOptions txtOptions = report.ExportOptions.Text; // Set Text-specific export options. txtOptions.Encoding = Encoding.Unicode; txtOptions.Separator = CultureInfo.CurrentCulture.TextInfo.ListSeparator.ToString(); // Export the report to Text. report.ExportToText(reportPath); // Show the result. StartProcess(reportPath); }
public static void TabloDisariAktar(this GridView tablo, DosyaTuru dosyaTuru, string dosyaFormati, string excelSayfaAdi = null) { if (Messages.TabloExportMessage(dosyaFormati) != DialogResult.Yes) { return; } if (!Directory.Exists(Application.StartupPath + @"\Temp")) { Directory.CreateDirectory(Application.StartupPath + @"\Temp"); } var dosyaAdi = Guid.NewGuid().ToString(); var filePath = $@"{Application.StartupPath}\Temp\{dosyaAdi}"; switch (dosyaTuru) { case DosyaTuru.ExcelStandart: { var opt = new XlsxExportOptionsEx { ExportType = ExportType.Default, SheetName = excelSayfaAdi, TextExportMode = TextExportMode.Text, }; filePath = filePath + ".Xlsx"; tablo.ExportToXlsx(filePath, opt); } break; case DosyaTuru.ExcelFormatli: { var opt = new XlsxExportOptionsEx { ExportType = ExportType.WYSIWYG, SheetName = excelSayfaAdi, TextExportMode = TextExportMode.Text, }; filePath = filePath + ".Xlsx"; tablo.ExportToXlsx(filePath, opt); } break; case DosyaTuru.ExcelFormatsiz: { var opt = new CsvExportOptionsEx { ExportType = ExportType.WYSIWYG, TextExportMode = TextExportMode.Text, }; filePath = filePath + ".Csv"; tablo.ExportToCsv(filePath, opt); } break; case DosyaTuru.WordDosyasi: { filePath = filePath + ".Rtf"; tablo.ExportToRtf(filePath); } break; case DosyaTuru.PdfDosyasi: { filePath = filePath + ".Pdf"; tablo.ExportToPdf(filePath); } break; case DosyaTuru.TxtDosyasi: { var opt = new TextExportOptions { TextExportMode = TextExportMode.Text }; filePath = filePath + ".Txt"; tablo.ExportToText(filePath, opt); } break; } if (!File.Exists(filePath)) { Messages.HataMesaji("Tablo Verileri Dosyaya Aktarılamadı."); return; } Process.Start(filePath); }
public void ExportToText(Stream stream, TextExportOptions options) { report.ExportToText(stream, options); }
public static void TableExport(this GridView table, FileType fileType, string fileFormat, string excelPageName = null) { if (Messages.TableExportMessage(fileFormat) != DialogResult.Yes) { return; } if (!Directory.Exists(Application.StartupPath + @"\Temp")) { Directory.CreateDirectory(Application.StartupPath + @"\Temp"); } var fileName = Guid.NewGuid().ToString(); var filePath = $@"{Application.StartupPath}\Temp\{fileName}"; switch (fileType) { case FileType.ExcelStandart: { var opt = new XlsxExportOptionsEx { ExportType = DevExpress.Export.ExportType.Default, SheetName = excelPageName, TextExportMode = TextExportMode.Text }; filePath = filePath + ".Xlsx"; table.ExportToXlsx(filePath, opt); } break; case FileType.ExcelFormat: { var opt = new XlsxExportOptionsEx { ExportType = DevExpress.Export.ExportType.WYSIWYG, SheetName = excelPageName, TextExportMode = TextExportMode.Text }; filePath = filePath + ".Xlsx"; table.ExportToXlsx(filePath, opt); } break; case FileType.ExcelUnformatted: { var opt = new CsvExportOptionsEx { ExportType = DevExpress.Export.ExportType.WYSIWYG, TextExportMode = TextExportMode.Text }; filePath = filePath + ".Csv"; table.ExportToCsv(filePath, opt); } break; case FileType.WordFile: { filePath = filePath + ".Rtf"; table.ExportToRtf(filePath); } break; case FileType.PdfFile: { filePath = filePath + ".Pdf"; table.ExportToPdf(filePath); } break; case FileType.TxtFile: { var opt = new TextExportOptions { TextExportMode = TextExportMode.Text }; filePath = filePath + ".Txt"; table.ExportToText(filePath, opt); } break; } if (!File.Exists(filePath)) { Messages.ErrorMessage("File not found."); return; } Process.Start(filePath); }