oleDbCommand.Connection = oleDbConnection
Step 3
Set the export format
Many popular formats are
provided for you (the supported formats are: XLS, PDF, Microsoft Word, HTML,
Microsoft clipboard, XML, DBF, SQL Script, SYLK, DIF, CSV) as follows:
I chose XLS to export data to. Just use the code:
'Define export way
Dim cellExport As New Spire.DataExport.XLS.CellExport()
Dim workSheet1 As New Spire.DataExport.XLS.WorkSheet()
Step 4
Customize style and apply it
According to your requirements,
you can customize the style. First, to set the title format:
Code
'Title format
workSheet1.AutoFitColWidth = True
workSheet1.Options.TitlesFormat.Borders.Bottom.Style =
Spire.DataExport.XLS.CellBorderStyle.Medium
workSheet1.Options.TitlesFormat.Borders.Left.Style =
Spire.DataExport.XLS.CellBorderStyle.Medium
workSheet1.Options.TitlesFormat.Borders.Right.Style =
Spire.DataExport.XLS.CellBorderStyle.Medium
workSheet1.Options.TitlesFormat.Borders.Top.Style =
Spire.DataExport.XLS.CellBorderStyle.Medium
workSheet1.Options.TitlesFormat.FillStyle.Background =
Spire.DataExport.XLS.CellColor.SkyBlue
workSheet1.Options.TitlesFormat.Font.Color =
Spire.DataExport.XLS.CellColor.LightOrange
workSheet1.Options.TitlesFormat.FillStyle.Pattern =
Spire.DataExport.XLS.Pattern.Solid
workSheet1.Options.TitlesFormat.Alignment.Horizontal =
Spire.DataExport.XLS.HorizontalAlignment.Center
workSheet1.Options.TitlesFormat.Font.Size = 11.0F
Then is your data format in XLS, according to your requirement, you may decide
how many styles you should define. Here I define five styles:
'Define styles
Dim stripStyle1 As New Spire.DataExport.XLS.StripStyle()
Dim stripStyle2 As New Spire.DataExport.XLS.StripStyle()
Dim stripStyle3 As New Spire.DataExport.XLS.StripStyle()
Dim stripStyle4 As New Spire.DataExport.XLS.StripStyle()
Dim stripStyle5 As New Spire.DataExport.XLS.StripStyle()
Set various background colors and font colors of each style, in addition you can
set other format for your own need:
'Customize style1
stripStyle1.FillStyle.Background = Spire.DataExport.XLS.CellColor.LightGreen
stripStyle1.FillStyle.Pattern = Spire.DataExport.XLS.Pattern.Solid
stripStyle1.Font.Color = XLS.CellColor.Brown
stripStyle1.Font.Size = 11.0F
'Customize style2
stripStyle2.FillStyle.Background = Spire.DataExport.XLS.CellColor.Yellow
stripStyle2.FillStyle.Pattern = Spire.DataExport.XLS.Pattern.Solid
stripStyle2.Font.Color
= XLS.CellColor.DarkTeal
stripStyle2.Font.Size = 11.0F
'Customize style3
stripStyle3.FillStyle.Background = Spire.DataExport.XLS.CellColor.Color4
stripStyle3.FillStyle.Pattern = Spire.DataExport.XLS.Pattern.Solid
stripStyle3.Font.Color
= XLS.CellColor.Red
stripStyle3.Font.Size
= 10.7F
'Customize style4
stripStyle4.FillStyle.Background = Spire.DataExport.XLS.CellColor.Color8
stripStyle4.FillStyle.Pattern = Spire.DataExport.XLS.Pattern.Solid
stripStyle4.Font.Color
= XLS.CellColor.Plum
stripStyle4.Font.Size
= 10.4F
'Customize style5
stripStyle5.FillStyle.Background = Spire.DataExport.XLS.CellColor.PaleBlue
stripStyle5.FillStyle.Pattern = Spire.DataExport.XLS.Pattern.Solid
stripStyle5.Font.Color
= XLS.CellColor.DarkBlue
stripStyle5.Font.Size
= 10.1F
To make the table more beautiful, I set the borders color of it with four
directions: Bottom, Top, Left and Right:
'Set the border color of the cell
workSheet1.Options.CustomDataFormat.Borders.Bottom.Color =
Spire.DataExport.XLS.CellColor.Blue
workSheet1.Options.CustomDataFormat.Borders.Top.Color =
Spire.DataExport.XLS.CellColor.Blue
workSheet1.Options.CustomDataFormat.Borders.Left.Color =
Spire.DataExport.XLS.CellColor.Blue
workSheet1.Options.CustomDataFormat.Borders.Right.Color =
Spire.DataExport.XLS.CellColor.Blue
Step 5
Save to a file and launch it
The last step is to show your data results with your specified file format (XLS).
It will be saved in your work place (in the Debug file of your project) by
default.
'Save to
file
cellExport.SaveToFile("Customers.xls")
Use the following code to
launch it after running it.
'Open
the file after export
cellExport.ActionAfterExport = ActionType.OpenView
The result