Spire.DataExport for .NET (33)
Children categories
Spire.DataExport for .NET, is a professional .NET component suit for data exporting. It allows programmers export data from database to MS Excel, MS Word, HTML, XML, PDF, MS Access, DBF, SQL Script, SYLK, DIF, CSV ,MS Clipboard format. Here we will introduce how to export data from listview to HTML.
As the predominant markup language for web pages, HTMLwhich stands for HyperText Markup Language is written in the form of HTML elements consisting of tags, enclosed in angle brackets (like ), within the web page content. It's the basic building-blocks of webpages. HTML has many advantages such as:
- Easy to use
- Loose syntax (although, being too flexible will not comply with standards)
- Supported on almost every browser, if not all browsers
- Free - You need not buy any software
- Easy to learn & code even for novice programmers
- Very similar to XML syntax, which is increasingly used for data storage
- Widely used; established on almost every website, if not all websites
Spire.DataExport presents an easy way to export data from Listview to HTML. Download Spire.DataExport (or Spire.Office) with .NET framework 2.0 (or above) together and use the code below to export data from Listview to HTML with C#/VB.NET.
Spire.DataExport.HTML.HTMLExport htmlExport1;
this.htmlExport1.ActionAfterExport = Spire.DataExport.Common.ActionType.OpenView;
this.htmlExport1.DataFormats.CultureName = "zh-CN";
this.htmlExport1.DataFormats.Currency = "c";
this.htmlExport1.DataFormats.DateTime = "yyyy-M-d H:mm";
this.htmlExport1.DataFormats.Float = "g";
this.htmlExport1.DataFormats.Integer = "g";
this.htmlExport1.DataFormats.Time = "H:mm";
this.htmlExport1.FileName = "sample.html";
this.htmlExport1.HtmlStyle = Spire.DataExport.HTML.HtmlStyle.MSMoney;
this.htmlExport1.HtmlTableOptions.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(222)), ((System.Byte)(231)), ((System.Byte)(222)));
this.htmlExport1.HtmlTableOptions.FontColor = System.Drawing.Color.Black;
this.htmlExport1.HtmlTableOptions.HeadersBackColor = System.Drawing.Color.FromArgb(((System.Byte)(206)), ((System.Byte)(198)), ((System.Byte)(181)));
this.htmlExport1.HtmlTableOptions.HeadersFontColor = System.Drawing.Color.Black;
this.htmlExport1.HtmlTableOptions.OddBackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(251)), ((System.Byte)(240)));
this.htmlExport1.HtmlTextOptions.BackgroundColor = System.Drawing.Color.White;
this.htmlExport1.HtmlTextOptions.Font = new System.Drawing.Font("Arial", 8F);
this.htmlExport1.HtmlTextOptions.LinkActiveColor = System.Drawing.Color.Blue;
this.htmlExport1.HtmlTextOptions.LinkColor = System.Drawing.Color.Red;
this.htmlExport1.HtmlTextOptions.LinkVisitedColor = System.Drawing.Color.Purple;
this.htmlExport1.DataSource = Common.ExportSource.ListView;
this.htmlExport1.ListView = this.listView1;
htmlExport1.SaveToFile();
htmlExport1 As Spire.DataExport.HTML.HTMLExport
Me.htmlExport1.ActionAfterExport = Spire.DataExport.Common.ActionType.OpenView
Me.htmlExport1.DataFormats.CultureName = "zh-CN"
Me.htmlExport1.DataFormats.Currency = "c"
Me.htmlExport1.DataFormats.DateTime = "yyyy-M-d H:mm"
Me.htmlExport1.DataFormats.Float = "g"
Me.htmlExport1.DataFormats.Integer = "g"
Me.htmlExport1.DataFormats.Time = "H:mm"
Me.htmlExport1.FileName = "sample.html"
Me.htmlExport1.HtmlStyle = Spire.DataExport.HTML.HtmlStyle.MSMoney
Me.htmlExport1.HtmlTableOptions.BackColor = System.Drawing.Color.FromArgb(CType(222, Byte), CType(231, Byte), CType(222, Byte))
Me.htmlExport1.HtmlTableOptions.FontColor = System.Drawing.Color.Black
Me.htmlExport1.HtmlTableOptions.HeadersBackColor = System.Drawing.Color.FromArgb(CType(206, Byte), CType(198, Byte), CType(181, Byte))
Me.htmlExport1.HtmlTableOptions.HeadersFontColor = System.Drawing.Color.Black
Me.htmlExport1.HtmlTableOptions.OddBackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(251, Byte), CType(240, Byte))
Me.htmlExport1.HtmlTextOptions.BackgroundColor = System.Drawing.Color.White
Me.htmlExport1.HtmlTextOptions.Font = New System.Drawing.Font("Arial", 8.0!)
Me.htmlExport1.HtmlTextOptions.LinkActiveColor = System.Drawing.Color.Blue
Me.htmlExport1.HtmlTextOptions.LinkColor = System.Drawing.Color.Red
Me.htmlExport1.HtmlTextOptions.LinkVisitedColor = System.Drawing.Color.Purple
Me.htmlExport1.DataSource = Common.ExportSource.ListView
Me.htmlExport1.ListView = Me.listView1
htmlExport1.SaveToFile()
Because of safety, easy to transfer from one to another and also easy to use, PDf is now becoming No. 1 file format all over the world. Usually customers will need export data from database to PDF file format. Spire.DataExport for .NET is a .NET component suit, 100% pure managed by C# for data exporting from database such as ListView, datatable and SQL command into MS Excel,MS Word, HTML, XML, PDF, MS Access, DBF, SQL Script, SYLK, DIF, CSV ,MS Clipboard format.
Spire.DataExport for .Net provides a quick and easy solution to export data from Listview to PDF. With Spire.DataExport for .Net, users also have other rich options when export data from database.
Now Download Spire.DataExport (or Spire.Office) with .NET framework together and use the code below to export data from Listview to PDF with C#/VB.NET.
protected void Button1_Click(object sender, System.EventArgs e)
{
oleDbConnection1.Open();
this.cellExport1.ActionAfterExport = DataExport.Common.ActionType.None;
this.cellExport1.DataFormats.CultureName = "zh-CN";
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.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 = DataExport.Common.ExportSource.ListView;
this.cellExport1.ListView = this.listView1;
Using(MemoryStream stream = new MemoryStream())
{
cellExport1.SaveToFile(stream);
this.oleDbConnection1.Close();
Workbook workbook = new Workbook(stream);
PdfConverter pdfConverter = new PdfConverter(workbook);
PdfDocument pdfDocument = new PdfDocument();
pdfDocument.PageSettings.Orientation = pdf.PdfPageOrientation.Landscape;
pdfDocument.PageSettings.Width = 970;
pdfDocument.PageSettings.Height = 850;
PdfConverterSettings settings = new PdfConverterSettings();
settings.TemplateDocument = pdfDocument;
pdfDocument = pdfConverter.Convert(settings);
pdfDocument.SaveToFile("test.pdf");
}
}
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
oleDbConnection1.Open()
Me.cellExport1.ActionAfterExport = DataExport.Common.ActionType.None
Me.cellExport1.DataFormats.CultureName = "zh-CN"
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.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 = 8F
Me.cellExport1.SheetOptions.TitlesFormat.Font.Bold = True
Me.cellExport1.SheetOptions.TitlesFormat.Font.Name = "Arial"
Me.cellExport1.DataSource = DataExport.Common.ExportSource.ListView
Me.cellExport1.ListView = Me.listView1
Dim stream As New MemoryStream()
cellExport1.SaveToFile(stream)
stream.Close()
Me.oleDbConnection1.Close()
Dim workbook As New Workbook(stream)
Dim pdfConverter As New PdfConverter(workbook)
Dim pdfDocument As New PdfDocument()
pdfDocument.PageSettings.Orientation = pdf.PdfPageOrientation.Landscape
pdfDocument.PageSettings.Width = 970
pdfDocument.PageSettings.Height = 850
Dim settings As New PdfConverterSettings()
settings.TemplateDocument = pdfDocument
pdfDocument = pdfConverter.Convert(settings)
pdfDocument.SaveToFile("test.pdf")
End Sub
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.
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
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