public static void ExportOlvToCsv(ObjectListView olv, String fileName) { OLVExporter exporter = new OLVExporter(olv); String csv = exporter.ExportTo(OLVExporter.ExportFormat.CSV); File.WriteAllText(fileName, csv); }
public static void ExportOlvToHtml(ObjectListView olv, String fileName) { OLVExporter exporter = new OLVExporter(olv); String html = exporter.ExportTo(OLVExporter.ExportFormat.HTML); File.WriteAllText(fileName, html); }
// ----- Export to File via Context Menu Strip ---------- void ExportToFile(string name, ObjectListView olv, OLVExporter.ExportFormat f) { OLVExporter oex = new OLVExporter(olv, olv.FilteredObjects); string s = oex.ExportTo(f); File.WriteAllText(name, s); MessageBox.Show(name + " saved", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information); }
public void Test_TabSeparated_WithoutHeader() { this.olv.SetObjects(PersonDb.All); this.olv.SelectedObject = PersonDb.All[0]; OLVExporter exporter = new OLVExporter(this.olv, this.olv.SelectedObjects); exporter.IncludeColumnHeaders = false; string tabSeparated = exporter.ExportTo(OLVExporter.ExportFormat.TSV); Assert.AreEqual(tabSeparated, @"name occupation 200 True "); }
public void Test_CSV_EscapedValues() { PersonDb.All[0].Occupation = @"Some, ""value"""; this.olv.SetObjects(PersonDb.All); this.olv.SelectedObject = PersonDb.All[0]; OLVExporter exporter = new OLVExporter(this.olv, this.olv.SelectedObjects); string csv = exporter.ExportTo(OLVExporter.ExportFormat.CSV); Assert.AreEqual(csv, @"""Name"",""Occupation"",""Culinary Rating"",""CanTellJokes"",""IsActive"" ""name"",""Some, """"value"""""",""200"",""True"","""" "); }
public void Test_HTML_EscapedValues() { PersonDb.All[0].Occupation = @"Complex <T> "" & string"; this.olv.SetObjects(PersonDb.All); this.olv.SelectedObject = PersonDb.All[0]; OLVExporter exporter = new OLVExporter(this.olv, this.olv.SelectedObjects); string html = exporter.ExportTo(OLVExporter.ExportFormat.HTML); Assert.AreEqual(html, @"<table><tr><td>Name</td><td>Occupation</td><td>Culinary Rating</td><td>CanTellJokes</td><td>IsActive</td></tr> <tr><td>name</td><td>Complex <T> " & string</td><td>200</td><td>True</td><td></td></tr> </table> "); }
public void Test_TabSeparated_Simple() { this.olv.SetObjects(PersonDb.All); OLVExporter exporter = new OLVExporter(this.olv); string tabSeparated = exporter.ExportTo(OLVExporter.ExportFormat.TSV); Assert.AreEqual(tabSeparated, @"Name Occupation Culinary Rating CanTellJokes IsActive name occupation 200 True name occupation 200 True aaa First Alphabetical Name occupation3 90 True name4 occupation4 80 True name5 occupation5 140 True name6 occupation6 65 True zzz Last Alphabetical Name occupation6 60 True "); }
public void Test_CSV_Simple() { this.olv.SetObjects(PersonDb.All); OLVExporter exporter = new OLVExporter(this.olv); string csv = exporter.ExportTo(OLVExporter.ExportFormat.CSV); Assert.AreEqual(csv, @"""Name"",""Occupation"",""Culinary Rating"",""CanTellJokes"",""IsActive"" ""name"",""occupation"",""200"",""True"","""" ""name"",""occupation"",""200"",""True"","""" ""aaa First Alphabetical Name"",""occupation3"",""90"",""True"","""" ""name4"",""occupation4"",""80"",""True"","""" ""name5"",""occupation5"",""140"",""True"","""" ""name6"",""occupation6"",""65"",""True"","""" ""zzz Last Alphabetical Name"",""occupation6"",""60"",""True"","""" "); }
private void cmdExport_Click(object sender, EventArgs e) { var dlg = new SaveFileDialog() { DefaultExt = "csv", AddExtension = true, Filter = "Pliki csv (*.csv)|*.csv|Wszystkie pliki (*.*)|*.*" }; if (dlg.ShowDialog() == DialogResult.OK) { var csv = new OLVExporter() { IncludeColumnHeaders = true, ListView = olvUser, ModelObjects = NewUsers }.ExportTo(OLVExporter.ExportFormat.CSV); File.WriteAllText(dlg.FileName, csv); MessageBox.Show("Plik został zapisany!", Application.ProductName, MessageBoxButtons.OK); } }
public void Test_HTML_Simple() { this.olv.SetObjects(PersonDb.All); OLVExporter exporter = new OLVExporter(this.olv); string html = exporter.ExportTo(OLVExporter.ExportFormat.HTML); Assert.AreEqual(html, @"<table><tr><td>Name</td><td>Occupation</td><td>Culinary Rating</td><td>CanTellJokes</td><td>IsActive</td></tr> <tr><td>name</td><td>occupation</td><td>200</td><td>True</td><td></td></tr> <tr><td>name</td><td>occupation</td><td>200</td><td>True</td><td></td></tr> <tr><td>aaa First Alphabetical Name</td><td>occupation3</td><td>90</td><td>True</td><td></td></tr> <tr><td>name4</td><td>occupation4</td><td>80</td><td>True</td><td></td></tr> <tr><td>name5</td><td>occupation5</td><td>140</td><td>True</td><td></td></tr> <tr><td>name6</td><td>occupation6</td><td>65</td><td>True</td><td></td></tr> <tr><td>zzz Last Alphabetical Name</td><td>occupation6</td><td>60</td><td>True</td><td></td></tr> </table> "); }
private async Task ExportData(OLVExporter.ExportFormat format, string ext, string filter) { if (gvResults.InvokeRequired) { gvResults.BeginInvoke(new MethodInvoker(async delegate() { await ExportData(format, ext, filter); })); } else { SaveFileDialog dlgExport = new SaveFileDialog(); dlgExport.FileName = RecordNames + "-" + DateTime.Now.ToLongDateString() + ext; dlgExport.Filter = filter; if (dlgExport.ShowDialog() == DialogResult.OK) { StartAWSOperation("Exporting to " + dlgExport.FileName); await Task.Run(() => { try { OLVExporter exporter = new OLVExporter(gvResults, gvResults.FilteredObjects); string csv = string.Empty; csv = exporter.ExportTo(format); using (StreamWriter sw = new StreamWriter(dlgExport.FileName)) sw.Write(csv); EndAWSOperation("Data saved to " + dlgExport.FileName); } catch (Exception e) { EndAWSOperation("Unable to export data: " + e.Message); } }); } } }