private void ExportToCsv(object sender, EventArgs e) { var sfd = new SaveFileDialog { Title = @"Enregistrer", DefaultExt = "CSV", Filter = @"CSV document (*.CSV)|*.CSV" }; if (sfd.ShowDialog() != DialogResult.OK) { return; } if (string.IsNullOrEmpty(sfd.FileName)) { return; } // export CSV options var options = new CsvExportOptions { Separator = ";", TextExportMode = TextExportMode.Value, QuoteStringsWithSeparators = true, Encoding = Encoding.Unicode, EncodingType = EncodingType.Unicode, }; viewLigne.OptionsPrint.PrintFooter = false; viewLigne.ExportToCsv(sfd.FileName, options); viewLigne.OptionsPrint.PrintFooter = true; OpenExportedFile(sfd.FileName); }
/// <summary> /// 导出CSV /// </summary> /// <param name="gv"></param> private static void ExportCsv(GridView gv) { var saveFileDialog = new SaveFileDialog { FileName = DateTime.Now.ToString(BaseSystemInfo.DateFormat) + "打印数据", Title = @"导出Csv", Filter = @"Csv文件(*.csv)|*.csv", OverwritePrompt = false }; //已存在文件是否覆盖提示 var dialogResult = saveFileDialog.ShowDialog(); if (dialogResult != DialogResult.OK) { return; } while (System.IO.File.Exists(saveFileDialog.FileName) && XtraMessageBox.Show("该文件名已存在,是否覆盖?", AppMessage.MSG0000, MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) { if (dialogResult != DialogResult.Yes) { return; } } if (string.IsNullOrEmpty(saveFileDialog.FileName)) { return; } try { var options = new CsvExportOptions { TextExportMode = TextExportMode.Text }; if (gv.Columns.ColumnByFieldName("Check") != null) { gv.Columns["Check"].Visible = false; } gv.ExportToCsv(saveFileDialog.FileName, options); if (gv.Columns.ColumnByFieldName("Check") != null) { gv.Columns["Check"].Visible = true; } OpenFile(saveFileDialog.FileName); } catch (Exception ex) { XtraMessageBox.Show(ex.Message.Contains("正由另一进程使用") ? "数据导出失败!文件正由另一个程序占用!" : ex.Message, AppMessage.MSG0000); } }
private void button1_Click(object sender, EventArgs e) { // A path to export a report. string reportPath = "c:\\Test.csv"; // Create a report instance. XtraReport1 report = new XtraReport1(); // Get its CSV export options. CsvExportOptions csvOptions = report.ExportOptions.Csv; // Set CSV-specific export options. csvOptions.Encoding = Encoding.Unicode; csvOptions.Separator = CultureInfo.CurrentCulture.TextInfo.ListSeparator.ToString(); // Export the report to CSV. report.ExportToCsv(reportPath); // Show the result. StartProcess(reportPath); }
private void btnExportToCSV_Click(object sender, EventArgs e) { try { SaveFileDialog save = new SaveFileDialog(); save.Filter = "CSV file (*.csv)|*.csv|All file (*.*)|*.*"; if (save.ShowDialog() == DialogResult.OK) { CsvExportOptions tuyChinh = new CsvExportOptions() { TextExportMode = TextExportMode.Value, Encoding = Encoding.UTF8, Separator = "#", }; gridControl1.ExportToCsv(save.FileName, tuyChinh); StaticClass.Log.GhiFile("Xuất dữ liệu ra file CSV: " + save.FileName); } } catch (Exception ex) { ExceptionUtil.ThrowMsgBox(ex.Message); } }
public static bool SaveItemListViewToCsv( ExchangeService oExchangeService, ListView oListView, string sFilePath, List <AdditionalPropertyDefinition> oAdditionalPropertyDefinitions, List <ExtendedPropertyDefinition> oExtendedPropertyDefinitions, CsvExportOptions oCsvExportOptions ) { bool bRet = false; string sHeader = string.Empty; string sLine = string.Empty; int iFolderPathColumn = 14; // Folder Path PropertySet oExtendedPropSet = new PropertySet(BasePropertySet.IdOnly); if (oExtendedPropertyDefinitions != null) { foreach (ExtendedPropertyDefinition oEPD in oExtendedPropertyDefinitions) { oExtendedPropSet.Add(oEPD); } } StreamWriter w = File.AppendText(sFilePath); char[] TrimChars = { ',', ' ' }; StringBuilder SbHeader = new StringBuilder(); int iHeaderCount = 0; // Build header part for listview foreach (ColumnHeader oCH in oListView.Columns) { iHeaderCount++; // Exclusions if (oCsvExportOptions._CsvExportGridExclusions != Exports.CsvExportGridExclusions.ExportAll) { if (oCsvExportOptions._CsvExportGridExclusions == Exports.CsvExportGridExclusions.ExcludeAllInGridExceptFilePath) { if (iFolderPathColumn == iHeaderCount) { SbHeader.Append(oCH.Text); SbHeader.Append(","); } } } else { SbHeader.Append(oCH.Text); SbHeader.Append(","); } } sHeader = SbHeader.ToString(); sHeader = sHeader.TrimEnd(TrimChars); // Add headers for custom properties. if (oAdditionalPropertyDefinitions != null) { sHeader += "," + AdditionalProperties.GetExtendedPropertyHeadersAsCsvContent(oAdditionalPropertyDefinitions); sHeader = sHeader.TrimEnd(TrimChars); } w.WriteLine(sHeader); ItemId oItemId = null; string sExtendedValue = string.Empty; int iCount = 0; string s = string.Empty; foreach (ListViewItem oListViewItem in oListView.SelectedItems) { iCount++; StringBuilder SbLine = new StringBuilder(); ItemTag oCalendarItemTag = (ItemTag)oListViewItem.Tag; oItemId = oCalendarItemTag.Id; byte[] oFromBytes; if (oListViewItem.Selected == true) { int iColumnCount = 0; foreach (ListViewItem.ListViewSubItem o in oListViewItem.SubItems) { iColumnCount++; s = (o.Text); // clean or encode strings to prevent issus with usage in a CSV? ---------- if (oCsvExportOptions._CsvStringHandling != CsvStringHandling.None) { s = AdditionalProperties.DoStringHandling(s, oCsvExportOptions._CsvStringHandling); } if (oCsvExportOptions.HexEncodeBinaryData == true) { if (oListViewItem.Tag != null) { if (oListViewItem.Tag.ToString() == "Binary") { oFromBytes = System.Convert.FromBase64String(s); // Base64 to byte array. s = StringHelper.HexStringFromByteArray(oFromBytes, false); } } } //// If its base64 encoded then convert it to hex encoded. //if (oCsvExportOptions.HexEncodeBinaryData == true) //{ // //bColumnIsByteArray = StringHelper.IsBase64Encoded(s); // if (StringHelper.IsBase64Encoded(s) == true) // { // oFromBytes = System.Convert.FromBase64String(s); // Base64 to byte array. // s = StringHelper.HexStringFromByteArray(oFromBytes, false); // } //} // Exclusions -------------------------------------------- if (oCsvExportOptions._CsvExportGridExclusions != Exports.CsvExportGridExclusions.ExportAll) { if (oCsvExportOptions._CsvExportGridExclusions == Exports.CsvExportGridExclusions.ExcludeAllInGridExceptFilePath) { if (iFolderPathColumn == iColumnCount) { SbLine.Append(s); SbLine.Append(","); } } } else { SbLine.Append(s); SbLine.Append(","); } } } sLine = SbLine.ToString(); sLine = sLine.TrimEnd(TrimChars); // Add Additional Properties ---------------------------------------------- StringBuilder oStringBuilder = new StringBuilder(); if (oExtendedPropertyDefinitions != null) { string sExt = AdditionalProperties.GetExtendedPropertiesForItemAsCsvContent( oExchangeService, oItemId, oExtendedPropertyDefinitions, oCsvExportOptions ); sLine += "," + sExt; //sLine = SbLine.ToString(); sLine = sLine.TrimEnd(TrimChars); } w.WriteLine(sLine); bRet = true; } w.Close(); return(bRet); }
public void ExportToCsv(Stream stream, CsvExportOptions options) { report.ExportToCsv(stream, options); }
public void ExportToFile(ReportExecuter template, string docType, string title, string fileName) { if (docType == "EKRAN") { report.ShowPreview(); return; } if (string.IsNullOrEmpty(fileName)) fileName = title.MakeFileName(); else fileName = fileName.MakeFileName(); string dir = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\CinarDocs"; if (!Directory.Exists(dir)) Directory.CreateDirectory(dir); Process.Start(dir); using (MemoryStream st = new MemoryStream()) { switch (docType) { case "CSV": CsvExportOptions csvOptions = new CsvExportOptions(); csvOptions.Encoding = Encoding.GetEncoding(1254); template.ExportToCsv(st, csvOptions); break; case "HTM": template.ExportToHtml(st, new HtmlExportOptions("UTF8", title, true)); break; case "JPG": template.ExportToImage(st, new ImageExportOptions(ImageFormat.Jpeg)); break; case "MHT": template.ExportToMht(st, new MhtExportOptions("UTF8")); break; case "PDF": template.ExportToPdf(st, new PdfExportOptions()); break; case "RTF": template.ExportToRtf(st, new RtfExportOptions()); break; case "TXT": template.ExportToText(st, new TextExportOptions("", Encoding.UTF8)); break; case "XLS": template.ExportToXls(st, new XlsExportOptions(TextExportMode.Value, false, true)); break; } string path = dir + "\\" + fileName + "." + docType; File.WriteAllBytes(path, st.ToArray()); } }