Spire.DataExport, as a 100% pure .NET component suit for data exporting from SQL Command, Listview and DataTable into MS Excel,MS Word, HTML, XML, PDF, MS Access, DBF, SQL Script, SYLK, DIF, CSV ,MS Clipboard format, quickly and easily! Here we will introduce how to export data from Listview to Excel with C#/VB.NET.

As an electronic spreadsheet program, MS Excel owns a lot of advantages such as it can be used for storing, organizing and manipulating data. Over several decades, Microsoft has updated, expanded and tweaked Excel to keep up with both modern technology and the needs of spreadsheet users. MS Excel has been the most popular data organizing program. So we may usually need export data from database into Excel, such as from ListView.

Spire.DataExport presents an easy way to export data from Listview to Excel. And it offers both C# and VB.Net language to realize it

Download Spire.DataExport (or Spire.Office) with .NET framework together and use the code below to export data from Listview to Excel with C# and VB.NET.

[C#]
this.cellExport1.ActionAfterExport = Spire.DataExport.Common.ActionType.OpenView;
	    this.cellExport1.AutoFitColWidth = true;
            this.cellExport1.DataFormats.CultureName = "en-us";
	    this.cellExport1.DataFormats.Currency = "?#,###,##0.00";
	    this.cellExport1.DataFormats.DateTime = "yyyy-M-d H:mm";
	    this.cellExport1.DataFormats.Float = "#,###,##0.00";
	    this.cellExport1.DataFormats.Integer = "#,###,##0";
	    this.cellExport1.DataFormats.Time = "H:mm";
	    this.cellExport1.FileName = "sample.xls";
	    this.cellExport1.SheetOptions.AggregateFormat.Font.Name = "Arial";
            this.cellExport1.SheetOptions.CustomDataFormat.Font.Name = "Arial";
	    this.cellExport1.SheetOptions.DefaultFont.Name = "Arial";
	    this.cellExport1.SheetOptions.FooterFormat.Font.Name = "Arial";
	    this.cellExport1.SheetOptions.HeaderFormat.Font.Name = "Arial";
	    this.cellExport1.SheetOptions.HyperlinkFormat.Font.Color = Spire.DataExport.XLS.CellColor.Blue;
	    this.cellExport1.SheetOptions.HyperlinkFormat.Font.Name = "Arial";
	    this.cellExport1.SheetOptions.HyperlinkFormat.Font.Underline = Spire.DataExport.XLS.XlsFontUnderline.Single;
	    this.cellExport1.SheetOptions.NoteFormat.Alignment.Horizontal = Spire.DataExport.XLS.HorizontalAlignment.Left;
	    this.cellExport1.SheetOptions.NoteFormat.Alignment.Vertical = Spire.DataExport.XLS.VerticalAlignment.Top;
	    this.cellExport1.SheetOptions.NoteFormat.Font.Bold = true;
	    this.cellExport1.SheetOptions.NoteFormat.Font.Name = "Tahoma";
	    this.cellExport1.SheetOptions.NoteFormat.Font.Size = 8F;
	    this.cellExport1.SheetOptions.TitlesFormat.Font.Bold = true;
	    this.cellExport1.SheetOptions.TitlesFormat.Font.Name = "Arial";
            this.cellExport1.DataSource = ExportSource.ListView;
            this.cellExport1.ListView = this.ListView1;
cellExport1.SaveToFile();
ListView to Excel with VB.NET Code
[VB.NET]
Me.cellExport1.ActionAfterExport = Spire.DataExport.Common.ActionType.OpenView
            Me.cellExport1.AutoFitColWidth = True
            Me.cellExport1.DataFormats.CultureName = "en-us"
            Me.cellExport1.DataFormats.Currency = "?#,###,##0.00"
            Me.cellExport1.DataFormats.DateTime = "yyyy-M-d H:mm"
            Me.cellExport1.DataFormats.Float = "#,###,##0.00"
            Me.cellExport1.DataFormats.Integer = "#,###,##0"
            Me.cellExport1.DataFormats.Time = "H:mm"
            Me.cellExport1.FileName = "sample.xls"
            Me.cellExport1.SheetOptions.AggregateFormat.Font.Name = "Arial"
            Me.cellExport1.SheetOptions.CustomDataFormat.Font.Name = "Arial"
            Me.cellExport1.SheetOptions.DefaultFont.Name = "Arial"
            Me.cellExport1.SheetOptions.FooterFormat.Font.Name = "Arial"
            Me.cellExport1.SheetOptions.HeaderFormat.Font.Name = "Arial"
            Me.cellExport1.SheetOptions.HyperlinkFormat.Font.Color = Spire.DataExport.XLS.CellColor.Blue
            Me.cellExport1.SheetOptions.HyperlinkFormat.Font.Name = "Arial"
            Me.cellExport1.SheetOptions.HyperlinkFormat.Font.Underline = Spire.DataExport.XLS.XlsFontUnderline.Single
            Me.cellExport1.SheetOptions.NoteFormat.Alignment.Horizontal = Spire.DataExport.XLS.HorizontalAlignment.Left
            Me.cellExport1.SheetOptions.NoteFormat.Alignment.Vertical = Spire.DataExport.XLS.VerticalAlignment.Top
            Me.cellExport1.SheetOptions.NoteFormat.Font.Bold = True
            Me.cellExport1.SheetOptions.NoteFormat.Font.Name = "Tahoma"
            Me.cellExport1.SheetOptions.NoteFormat.Font.Size = 8.0!
            Me.cellExport1.SheetOptions.TitlesFormat.Font.Bold = True
            Me.cellExport1.SheetOptions.TitlesFormat.Font.Name = "Arial"
            Me.cellExport1.DataSource = Common.ExportSource.ListView
            Me.cellExport1.ListView = Me.ListView1
            cellExport1.SaveToFile()
End Sub
Published in ListView Export