MIS Putro


Is there anyone have sample/sourcode how to export data to xls format and also how to use Printview


Re: Visual Basic Express Edition Export to xls and Printview

Martin Xie - MSFT


1. How to export data to xls format

Could you please clarify that from what object you want to export to xls format

Here is a source-opened sample: How to export DataGrid to Excel. Is it what you want


2. How to use Printview

You need to use a PrintDocument object and a PrintPreviewDialog object.

Code Snippet

Public Class Form1

' Declare the dialog.

Friend WithEvents PrintPreviewDialog1 As PrintPreviewDialog

' Declare a PrintDocument object named document.

Private WithEvents document As New PrintDocument

' Initalize the dialog.

Private Sub InitializePrintPreviewDialog()

' Create a new PrintPreviewDialog using constructor.

Me.PrintPreviewDialog1 = New PrintPreviewDialog

'Set the size, location, and name.

Me.PrintPreviewDialog1.ClientSize = New System.Drawing.Size(400, 300)

Me.PrintPreviewDialog1.Location = New System.Drawing.Point(29, 29)

Me.PrintPreviewDialog1.Name = "PrintPreviewDialog1"

' Set the minimum size the dialog can be resized to.

Me.PrintPreviewDialog1.MinimumSize = New System.Drawing.Size(375, 250)

' Set the UseAntiAlias property to true, which will allow the operating system to smooth fonts.

Me.PrintPreviewDialog1.UseAntiAlias = True

End Sub

Private Sub PrintButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

PrintPreviewDialog1.Document = document

' Call the ShowDialog method. This will trigger the document's PrintPage event.


End Sub

Private Sub document_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles document.PrintPage

' Insert code to render the page here.

' This code will be called when the PrintPreviewDialog.Show method is called.

' The following code will render a simple message on the document in the dialog.

Dim text As String = "In document_PrintPage method."

Dim printFont As New System.Drawing.Font("Arial", 35, System.Drawing.FontStyle.Regular)

e.Graphics.DrawString(text, printFont, System.Drawing.Brushes.Black, 0, 0)

End Sub

End Class

Please check these references.

How do I print out the specific data record

HELP! Print preview Dialog

How to Print a DataGrid in .NET

Best regards,

Martin Xie

Re: Visual Basic Express Edition Export to xls and Printview

Martin Xie - MSFT


If you still have any doubt and concern about this issue, please let me know.



Re: Visual Basic Express Edition Export to xls and Printview

MIS Putro

Hi Martin

Yes, it helps me so much, thanks for your prompt