Friday, 05 August 2011 03:29

Export Data from Listview to CSV

Why Export Listview to CSV?

CSV file (Comma Separated Values, sometimes also called Comma Delimited) is a specially formatted plain text file which stores spreadsheet or basic database-style information in a very simple format, with one record on each line, and each field within that record separated by a comma. It is often used to exchange data between disparate applications. CSV has become a pseudo standard throughout the industry, even among non-Microsoft platforms because it is used in Microsoft Excel.

CSV files are often used as a simple way to transfer a large volume of spreadsheet or database information between programs, without worrying about special file types. For example, transferring a home-made address book from Excel into a database program such as Filemaker Pro could be done by exporting the file as a CSV from Excel, then importing that CSV into File maker.

How to Export Listview to CSV?

Spire.DataExport for .NET presents an easy solution for exporting Listvie to CSV. Spire.DataExport is a 100% pure .NET component suit for exporting data into MS Excel, MS Word, HTML, XML, PDF, MS Access, DBF, SQL Script, SYLK, DIF, CSV ,MS Clipboard format. Quickly and easily export data from Command, ListView, DataTable components. Save you much time and money by using Spire.DataExport.

Download Spire.DataExport (or Spire.Office) with .NET framework 2.0 (or above) together and use the code below to Export Listview to CSV:

[C#]
this.txtExport1.ActionAfterExport = Spire.DataExport.Common.ActionType.OpenView;
    this.txtExport1.DataFormats.CultureName = "en-us";
    this.txtExport1.DataFormats.Currency = "c";
    this.txtExport1.DataFormats.DateTime = "yyyy-M-d H:mm";
    this.txtExport1.DataFormats.Float = "g";
    this.txtExport1.DataFormats.Integer = "g";
    this.txtExport1.DataFormats.Time = "H:mm";
    this.txtExport1.DataEncoding = Spire.DataExport.Common.EncodingType.ASCII;
    this.txtExport1.DataSource = ExportSource.ListView;
    this.txtExport1.ListView = this.ListView1
    txtExport1.ExportType = TextExportType.CSV;
    txtExport1.FileName = "sample.csv";
    txtExport1.SaveToFile();
[VB.NET]
Me.txtExport1.ActionAfterExport = Spire.DataExport.Common.ActionType.OpenView
            Me.txtExport1.DataFormats.CultureName = "en-us"
            Me.txtExport1.DataFormats.Currency = "c"
            Me.txtExport1.DataFormats.DateTime = "yyyy-M-d H:mm"
            Me.txtExport1.DataFormats.Float = "g"
            Me.txtExport1.DataFormats.Integer = "g"
            Me.txtExport1.DataFormats.Time = "H:mm"
            Me.txtExport1.DataEncoding = Spire.DataExport.Common.EncodingType.ASCII
            Me.txtExport1.DataSource = Common.ExportSource.ListView
            Me.txtExport1.ListView = Me.ListView1
txtExport1.ExportType = TextExportType.CSV
                        txtExport1.FileName = "sample.csv"
                        txtExport1.SaveToFile()
Thursday, 04 August 2011 03:01

Export Data from Listview to XML

Why Export Listview to Office OpenXML?

Office OpenXML has its own advantages. Office OpenXML, or Extensible Markup Language is a set of rules for encoding documents in machine-readable form. The real power of Office OpenXML comes from the fact that with Office OpenXML, not only can you define your own set of tags, but the rules specified by those tags need not be limited to formatting rules. And the most benefit of Office OpenXML is that because you are writing your own markup language, you are not restricted to a limited set of tags defined by proprietary vendors. Furthermore, Office OpenXML allows you to define all sorts of tags with all sorts of rules, such as tags representing business rules or tags representing data description or data relationships.

How to Export Listview to Office OpenXML?

As a professional and powerful .NET component suit for data exporting, Spire.DataExport for .NET can export data from Database to MS Excel,MS Word, HTML, Office OpenXML, PDF, MS Access, DBF, SQL Script, SYLK, DIF, CSV ,MS Clipboard format and of course enable to export ListView to Office OpenXML.

Spire.DataExport for .NET offers an easy solution on Exporting listview to Office OpenXML. Download Spire.DataExport (or Spire.Office) with .NET framework 2.0 (or above) together and use the code below to Export Listview to Office OpenXML:

[C#]
this.xmlExport1.ActionAfterExport = Spire.DataExport.Common.ActionType.OpenView;
			this.xmlExport1.DataFormats.CultureName = "zh-CN";
			this.xmlExport1.DataFormats.Currency = "c";
			this.xmlExport1.DataFormats.DateTime = "yyyy-M-d H:mm";
			this.xmlExport1.DataFormats.Float = "g";
			this.xmlExport1.DataFormats.Integer = "g";
			this.xmlExport1.DataFormats.Time = "H:mm";
			this.xmlExport1.FileName = "sample.xml";
            this.xmlExport1.DataSource = Common.ExportSource.ListView;
            this.xmlExport1.ListView = this.listView1;
oleDbConnection1.Open();
try{
xmlExport1.SaveToFile();
}
Finally
{
oleDbConnection1.Close();

}
[VB.NET]
Me.xmlExport1.ActionAfterExport = Spire.DataExport.Common.ActionType.OpenView
            Me.xmlExport1.DataFormats.CultureName = "zh-CN"
            Me.xmlExport1.DataFormats.Currency = "c"
            Me.xmlExport1.DataFormats.DateTime = "yyyy-M-d H:mm"
            Me.xmlExport1.DataFormats.Float = "g"
            Me.xmlExport1.DataFormats.Integer = "g"
            Me.xmlExport1.DataFormats.Time = "H:mm"
            Me.xmlExport1.FileName = "sample.xml"
            Me.xmlExport1.DataSource = Common.ExportSource.ListView
            Me.xmlExport1.ListView = Me.listView1
oleDbConnection1.Open()
            Try
                 xmlExport1.SaveToFile()
Finally
                Me.oleDbConnection1.Close()
            End Try
Thursday, 04 August 2011 02:53

Export Data from Listview to RTF

Why Export Listview to RTF?

RTF (Rich Text Format) is one of three core file formats which Microsoft supports natively along with DOC and DOCX. It's a cross-platform file extension supported by almost all word processors regardless of operating system. RTF word processing files are typically smaller, safer and can be used across a variety of operating systems. Main advantages of RTF:

  • File Transparency
  • The ability mentioned above of RTF files to be read by the receiver regardless of the type of word processor or its version or the operating system being used. While in some cases this may be the most essential requirement.
  • No Risk of Viruses
  • Unlike Word .doc files, RTF files cannot contain the numerous "macro" and other viruses that plague Microsoft Word documents. Many business and other e-mail servers refuse to accept e-mailed "attachments" which are in .doc format because of all the viruses that may be carried by Word .doc files. However, they will accept the same document in RTF, since the RTF file cannot transmit viruses. This security against the risk of virus infection applies regardless of whether your document would be conveyed via diskette, e-mail attachment, or as an archived web file.
  • Smaller File Size for Text Documents
  • For having greater disk storage capacity, this may sometimes be an advantage.

How to Export Listview to RTF?

Spire.DataExport for .NET as a professional .NET component suit for data exporting can easily help to export Listview to RTF. Download Spire.DataExport (or Spire.Office) with .NET framework 2.0 (or above) together and use the code below to Export Listview to RTF:

[C#]
this.rtfExport1.ActionAfterExport = Spire.DataExport.Common.ActionType.OpenView;
			this.rtfExport1.DataFormats.CultureName = "en-us";
			this.rtfExport1.DataFormats.Currency = "c";
			this.rtfExport1.DataFormats.DateTime = "yyyy-M-d H:mm";
			this.rtfExport1.DataFormats.Float = "g";
			this.rtfExport1.DataFormats.Integer = "g";
			this.rtfExport1.DataFormats.Time = "H:mm";
			this.rtfExport1.FileName = "sample.doc";
			this.rtfExport1.RTFOptions.DataStyle.Font = new System.Drawing.Font("Arial", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.World);
			this.rtfExport1.RTFOptions.FooterStyle.Font = new System.Drawing.Font("Arial", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.World);
			this.rtfExport1.RTFOptions.HeaderStyle.Font = new System.Drawing.Font("Arial", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.World);
			this.rtfExport1.RTFOptions.TitleStyle.Alignment = Spire.DataExport.RTF.RtfTextAlignment.Center;
			this.rtfExport1.RTFOptions.TitleStyle.Font = new System.Drawing.Font("Arial", 10F, System.Drawing.FontStyle.Bold);
                             this.rtfExport1.DataSource = ExportSource.ListView;
                            this.rtfExport1.ListView = this.ListView1
          rtfExport1.SaveToFile();
[VB.NET]
Me.rtfExport1.ActionAfterExport = Spire.DataExport.Common.ActionType.OpenView
            Me.rtfExport1.DataFormats.CultureName = "en-us"
            Me.rtfExport1.DataFormats.Currency = "c"
            Me.rtfExport1.DataFormats.DateTime = "yyyy-M-d H:mm"
            Me.rtfExport1.DataFormats.Float = "g"
            Me.rtfExport1.DataFormats.Integer = "g"
            Me.rtfExport1.DataFormats.Time = "H:mm"
            Me.rtfExport1.FileName = "sample.doc"
            Me.rtfExport1.RTFOptions.DataStyle.Font = New System.Drawing.Font("Arial", 10.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.World)
            Me.rtfExport1.RTFOptions.FooterStyle.Font = New System.Drawing.Font("Arial", 10.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.World)
            Me.rtfExport1.RTFOptions.HeaderStyle.Font = New System.Drawing.Font("Arial", 10.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.World)
            Me.rtfExport1.RTFOptions.TitleStyle.Alignment = Spire.DataExport.RTF.RtfTextAlignment.Center
            Me.rtfExport1.RTFOptions.TitleStyle.Font = New System.Drawing.Font("Arial", 10.0!, System.Drawing.FontStyle.Bold)
            Me.rtfExport1.DataSource = Common.ExportSource.ListView
            Me.cellExport1.ListView = Me.ListView1
            Me.cellExport1.SaveToFile()
Wednesday, 03 August 2011 03:55

Export Data from Listview to HTML

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.

[C#]
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();
[VB.NET]
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.

[C#]
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");

                    }
       }
[VB.NET]
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.

[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

Text watermark and image watermark are all watermarks in Word document. The difference lies in that text watermark always shows some additional but related information to the word context. While image watermark is used to make the Word document be more attractive. This section will show you solutions to add both text watermark and image watermark via a .NET Word component in C#, VB.NET.

Spire.Doc for .NET, a reliable .NET Word component, enables you to generate, read, edit, convert even print your Word document in a fast speed. Using Spire.Doc for .NET, you can easily add both text watermark and image watermark in your Word document in C#, VB.NET. Please see the target Word document with image watermark as below picture:

Word Watermarks

Here, you can download Spire.Doc for .NET and install it in system. After adding Spire.Doc dll, you can perform adding Word watermark task by below soluctions.

Add Image Watermark in Word with C#, VB.NET

There are four lines of key code for you to add your image watermark. First we need to create a new instance of the Spire.Doc.PictureWatermark named picture. Then, load an image from system by calling the method: System.Drawing.Image FromFile(string filename). The third line enables you to set the image watermark scaling when adding to Word file. While in the last step, you can set the image that you just load to be Word watermark. Please see the code below:

[C#]
using Spire.Doc;
namespace AddWatermark
{
    class Program
    {
        static void Main(string[] args)
        {
            Document document = new Document();
            PictureWatermark picture = new PictureWatermark();
            picture.Picture = System.Drawing.Image.FromFile(@"..\imagess.jpeg");
            picture.Scaling = 250;
            document.Watermark = picture;
        }
    }
}
[VB.NET]
Imports Spire.Doc
Namespace AddWatermark

	Class Program
		Private Shared Sub Main(args As String())
			Dim document As New Document()
			Dim picture As New PictureWatermark()
			picture.Picture = System.Drawing.Image.FromFile("..\imagess.jpeg")
			picture.Scaling = 250
			document.Watermark = picture
		End Sub
	End Class
End Namespace

Add Text Watermark in Word with C#, VB.NET

This solution is as easy as the solution above. After creating a new instance of Spire.Doc.TextWatermark class which is called txtWatermark, you can set the text which will be shown in Word document. Then, by setting the property TextWatermark.FontSize and TextWatermark.Layout, you can decide the text size and layout of your text watermark. Finally, set the text watermark to be the one you just defined.

[C#]
using Spire.Doc;
using Spire.Doc.Documents;
namespace AddWatermark

{
    class Program
    {
        static void Main(string[] args)
        {
            Document document = new Document();
            TextWatermark txtWatermark = new TextWatermark();
            txtWatermark.Text = "Microsoft";
            txtWatermark.FontSize = 90;
            txtWatermark.Layout = WatermarkLayout.Diagonal;
            document.Watermark = txtWatermark;

        }
    }
}
[VB.NET]
Imports Spire.Doc
Imports Spire.Doc.Documents
Namespace AddWatermark
	Class Program
		Private Shared Sub Main(args As String())
			Dim document As New Document()
			Dim txtWatermark As New TextWatermark()
			txtWatermark.Text = "Microsoft"
			txtWatermark.FontSize = 90
			txtWatermark.Layout = WatermarkLayout.Diagonal
			document.Watermark = txtWatermark

		End Sub
	End Class
End Namespace

Spire.Doc for .NET is specially designed for creating, reading, writing, manipulating Word documents in your .NET applications. With this .NET Word component, you can perform a wide range of tasks directly.

This section will show you a very simple solution to split PDF file to multiple files in your .NET applications. The whole solution only requires four lines of key code for you to successfully split PDF document by pages via a .NET PDF component Spire.PDF for .NET.

Spire.PDF for .NET, built from scratch in C#, is a .NET PDF component that enables you to create, read, write and manipulate PDF documents without Adobe Acrobat or any other external libraries. Using Spire.PDF for .NET, you can view the main method, please preview the effective screenshot first:

Split PDF Document

The following is a list of two methods which have to be invoked during PDF splitting process:

doc.Split(pattern): After loading your PDF file or creating and editing a new PDF file, it is very easy for you to split the original PDF document by pages. Only one parameter is passed to offer a template name of the target PDF files.

String.Format(pattern, doc.Pages.Count - 1): By using the "string format" method, you can preview an existing file by returning the PDF file name which you want to process. The second parameter in this method is designed to point out the index item which begins with 0.

Spire.PDF for .NET helps you to easily accomplish your PDF split task by two methods, four lines of core code. Please download Spire.PDF for .NET and follow code below:

Code Sample for Splitting PDF in C# and VB.NET

[C#]
using Spire.Pdf;

namespace split_pdf
{
    class Program
    {
        static void Main(string[] args)
        {
            //open an existing pdf document
            PdfDocument doc = new PdfDocument(@"..\Sample3.pdf");
            //Split one PDF document to multiple files
            String pattern = "SplitDocument-{0}.pdf";
            doc.Split(pattern);
            String lastPageFileName
                = String.Format(pattern, doc.Pages.Count - 1);
            doc.Close();
        }
    }
}
[VB.NET]
Imports Spire.Pdf

Namespace split_pdf
    Class Program
	Private Shared Sub Main(args As String())
		'open an existing pdf document
		Dim doc As New PdfDocument("..\Sample3.pdf")
		'Split one PDF document to multiple files
		Dim pattern As [String] = "SplitDocument-{0}.pdf"
		doc.Split(pattern)
		Dim lastPageFileName As [String] = [String].Format(pattern, doc.Pages.Count - 1)
		doc.Close()
	End Sub
    End Class
End Namespace
Friday, 29 July 2011 02:44

Insert Interior in Excel in C#, VB.NET

What is Excel Interior?

Excel provides essentially no support in worksheet functions for Working with cell colors. However, colors are often used in spreadsheets to indicate some sorts of value or category. Thus comes the need for functions that can work with colors on the worksheet. So it appears in the version in Excel 2007 as a new function. It contains all kinds of colors. Below I will show you how to insert interior in Excel with MS Excel and how to do this with Spire.XLS.

How to insert interior in Excel with MS Excel?

To insert interior in Excel with Microsoft Excel, you can follow the sections below:

  • Open the worksheet in Excel
  • Highlight the zones that you want to insert interior
  • Rightclick and choose Setting Cell Format
  • Choose Fill->Fill Effect in the dialog box of Setting Cell Format
  • In the box, you can change the Color and the Shade Format to your desired effect

How to Insert Interior with Spire.XLS?

It's convenient to realize C#/.NET Excel Integration via Spire.XLS. In interior method, to realize interior you may set the color gradient by assigning sheet.Range[string.Format("E{0}:K{0}", i)].Style.Interior.FillPattern property with ExcelPatternType.Gradient. You can set the BackKnownColor and ForeKnownColor of the sheet. What's more, you can set the gradient style, in the demo, we set the gradient style vertical. In order to reflect the effect, we merge the worksheet range from E to K. In this demo, we use Enum method to enumerate many kinds of colors and define a random object to fill the cell with a gradient color randomly.

First, let's preview the effect screenshot:

Excel Interior

Here comes to the full code in C# and VB.NET.

[C#]
using Spire.Xls;
using System.Drawing;
using System;

namespace Interior
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a workbook
            Workbook workbook = new Workbook();

            //Initialize the worksheet
            Worksheet sheet = workbook.Worksheets[0];

            //Specify the version
            workbook.Version = ExcelVersion.Version2007;

            //Define the number of the colors 
            int maxColor = Enum.GetValues(typeof(ExcelColors)).Length;

            //Create a random object
            Random random = new Random((int)System.DateTime.Now.Ticks);

            for (int i = 2; i < 40; i++)
            {
                //Random backKnownColor
                ExcelColors backKnownColor = (ExcelColors)(random.Next(1, maxColor / 2));
                sheet.Range["A1"].Text = "Color Name";
                sheet.Range["B1"].Text = "Red";
                sheet.Range["C1"].Text = "Green";
                sheet.Range["D1"].Text = "Blue";

                //Merge the sheet"E1-K1"
                sheet.Range["E1:K1"].Merge();
                sheet.Range["E1:K1"].Text = "Gradient";
                sheet.Range["A1:K1"].Style.Font.IsBold = true;
                sheet.Range["A1:K1"].Style.Font.Size = 11;

                //Set the text of color in sheetA-sheetD
                string colorName = backKnownColor.ToString();
                sheet.Range[string.Format("A{0}", i)].Text = colorName;
                sheet.Range[string.Format("B{0}", i)].Text = workbook.GetPaletteColor(backKnownColor).R.ToString();
                sheet.Range[string.Format("C{0}", i)].Text = workbook.GetPaletteColor(backKnownColor).G.ToString();
                sheet.Range[string.Format("D{0}", i)].Text = workbook.GetPaletteColor(backKnownColor).B.ToString();

                //Merge the sheets 
                sheet.Range[string.Format("E{0}:K{0}", i)].Merge();

                //Set the text of sheetE-sheetK
                sheet.Range[string.Format("E{0}:K{0}", i)].Text = colorName;

                //Set the interior of the color
                sheet.Range[string.Format("E{0}:K{0}", i)].Style.Interior.FillPattern = ExcelPatternType.Gradient;
                sheet.Range[string.Format("E{0}:K{0}", i)].Style.Interior.Gradient.BackKnownColor = backKnownColor;
                sheet.Range[string.Format("E{0}:K{0}", i)].Style.Interior.Gradient.ForeKnownColor = ExcelColors.White;
                sheet.Range[string.Format("E{0}:K{0}", i)].Style.Interior.Gradient.GradientStyle = GradientStyleType.Vertical;
                sheet.Range[string.Format("E{0}:K{0}", i)].Style.Interior.Gradient.GradientVariant = GradientVariantsType.ShadingVariants1;
            }

            //AutoFit Column
            sheet.AutoFitColumn(1);

            //Save the file
            workbook.SaveToFile("Sample.xls",ExcelVersion.Version97to2003);

            //Launch the file
            System.Diagnostics.Process.Start("Sample.xls");
        }
    }
}
[VB.NET]
Imports Spire.Xls
Imports System.Drawing
Imports System

Module Module1

    Sub Main()
        'Create a workbook
        Dim workbook As New Workbook()

        'Initialize the worksheet
        Dim sheet As Worksheet = workbook.Worksheets(0)

        'Specify the version
        workbook.Version = ExcelVersion.Version2007

        'Define the number of the colors 
        Dim maxColor As Integer = [Enum].GetValues(GetType(ExcelColors)).Length

        'Create a random object
        Dim random As New Random()

        For i As Integer = 2 To 39
            'Random backKnownColor
            Dim backKnownColor As ExcelColors = DirectCast(random.[Next](1, maxColor \ 2), ExcelColors)
            sheet.Range("A1").Text = "Color Name"
            sheet.Range("B1").Text = "Red"
            sheet.Range("C1").Text = "Green"
            sheet.Range("D1").Text = "Blue"

            'Merge the sheet"E1-K1"
            sheet.Range("E1:K1").Merge()
            sheet.Range("E1:K1").Text = "Gradient"
            sheet.Range("A1:K1").Style.Font.IsBold = True
            sheet.Range("A1:K1").Style.Font.Size = 11

            'Set the text of color in sheetA-sheetD
            Dim colorName As String = backKnownColor.ToString()
            sheet.Range(String.Format("A{0}", i)).Text = colorName
            sheet.Range(String.Format("B{0}", i)).Text = workbook.GetPaletteColor(backKnownColor).R.ToString()
            sheet.Range(String.Format("C{0}", i)).Text = workbook.GetPaletteColor(backKnownColor).G.ToString()
            sheet.Range(String.Format("D{0}", i)).Text = workbook.GetPaletteColor(backKnownColor).B.ToString()

            'Merge the sheets 
            sheet.Range(String.Format("E{0}:K{0}", i)).Merge()

            'Set the text of sheetE-sheetK
            sheet.Range(String.Format("E{0}:K{0}", i)).Text = colorName

            'Set the interior of the color
            sheet.Range(String.Format("E{0}:K{0}", i)).Style.Interior.FillPattern = ExcelPatternType.Gradient
            sheet.Range(String.Format("E{0}:K{0}", i)).Style.Interior.Gradient.BackKnownColor = backKnownColor
            sheet.Range(String.Format("E{0}:K{0}", i)).Style.Interior.Gradient.ForeKnownColor = ExcelColors.White
            sheet.Range(String.Format("E{0}:K{0}", i)).Style.Interior.Gradient.GradientStyle = GradientStyleType.Vertical
            sheet.Range(String.Format("E{0}:K{0}", i)).Style.Interior.Gradient.GradientVariant = GradientVariantsType.ShadingVariants1
        Next

        'AutoFit Column
        sheet.AutoFitColumn(1)

        'Save doc file.
        workbook.SaveToFile("Sample.xls",ExcelVersion.Version97to2003)

        'Launching the MS Word file.
        System.Diagnostics.Process.Start("Sample.xls")
    End Sub
End Module

After running the demo, you will find color interior in your 2007 worksheet.

Friday, 29 July 2011 02:30

Edit Excel Data in C#, VB.NET

It is necessary to edit existing Excel workbook when the data information has changed. For example, if the one staff’s telephone number or address is changed, the matched data in Excel should be changed as well. Solution in this guide focuses on introducing the solution to Edit Excel and format edited data in C# and VB.NET. The following screenshot presents result after editing.

Edit Excel Data

Spire.XLS for .NET, a professional .NET Excel component, provides an XlsRange class to enables users to set Text, Value, Number, Formula or other properties to edit data in specified cells. In this example, the data in Cell D2 and E2 is edited in the existing Excel workbook. Also, the edited data will be formatted for distinguishing with other data information. When formatting, set Font properties of CellStyle for specified cell range, including FontName and Color. Download and Install Spire.XLS for .NET and follow code below.

[C#]
using Spire.Xls;
using System.Drawing;

namespace EditSheet
{
    class Program
    {
        static void Main(string[] args)
        {
            //Load Workbook
            Workbook workbook = new Workbook();
            workbook.LoadFromFile(@"E:\Work\Documents\ExcelFiles\Staff Contact Info.xlsx");

            //Edit Text
            Worksheet sheet = workbook.Worksheets[0];
            sheet.Range["D2"].Text = "Kelly Cooper";
            sheet.Range["D2"].Style.Font.FontName = "Arial Narrow";
            sheet.Range["D2"].Style.Font.Color = Color.DarkBlue;

            //Edit Cell Value
            sheet.Range["E2"].Value = "00-1-285-7901742";
            sheet.Range["E2"].Style.Font.FontName = "Book Antiqua";
            sheet.Range["E2"].Style.Font.Color = Color.DarkOrange;

            //Save and Launch
            workbook.SaveToFile("EditSheet.xlsx", ExcelVersion.Version2010);
            System.Diagnostics.Process.Start("EditSheet.xlsx");

        }
    }
}
[VB.NET]
Imports Spire.Xls
Imports System.Drawing

Namespace EditSheet
    Friend Class Program
        Shared Sub Main(ByVal args() As String)
            'Load Workbook
            Dim workbook As New Workbook()
            workbook.LoadFromFile("E:\Work\Documents\ExcelFiles\Staff Contact Info.xlsx")

            'Edit Text
            Dim sheet As Worksheet = workbook.Worksheets(0)
            sheet.Range("D2").Text = "Kelly Cooper"
            sheet.Range("D2").Style.Font.FontName = "Arial Narrow"
            sheet.Range("D2").Style.Font.Color = Color.DarkBlue

            'Edit Cell Value
            sheet.Range("E2").Value = "00-1-285-7901742"
            sheet.Range("E2").Style.Font.FontName = "Book Antiqua"
            sheet.Range("E2").Style.Font.Color = Color.DarkOrange

            'Save and Launch
            workbook.SaveToFile("EditSheet.xlsx", ExcelVersion.Version2010)
            System.Diagnostics.Process.Start("EditSheet.xlsx")

        End Sub
    End Class
End Namespace