473,473 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

VB.Net 2008 Save Print Preview DataGridView inside txt file or Excel

115 New Member
I知 using VB.Net 2008 application program.

I知 using DataGridView. I have a Print Preview option where i need to print the DataGridView.

Using "DataGridView1.Rows.Add" i知 adding rows to datagridview.
I知 using this code for Print Preview.

Expand|Select|Wrap|Line Numbers
  1. Dim MyDataGridViewPrinter As DataGridViewPrinter
  2.  
  3.  
  4.     Private Function SetupThePrinting() As Boolean
  5.         Dim MyPrintDialog As PrintDialog = New PrintDialog()
  6.  
  7.         MyPrintDialog.AllowCurrentPage = False
  8.         MyPrintDialog.AllowPrintToFile = False
  9.         MyPrintDialog.AllowSelection = False
  10.         MyPrintDialog.AllowSomePages = True
  11.         MyPrintDialog.PrintToFile = False
  12.         MyPrintDialog.ShowHelp = False
  13.         MyPrintDialog.ShowNetwork = False
  14.  
  15.         PrintDocument1.PrinterSettings = MyPrintDialog.PrinterSettings
  16.         PrintDocument1.DefaultPageSettings.Margins = New Margins(10, 10, 10, 10)
  17.  
  18.         MyDataGridViewPrinter = New DataGridViewPrinter(DataGridView1, PrintDocument1, False, True, "Manager", New Font("Tahoma", 18, FontStyle.Bold, GraphicsUnit.Point), Color.Black, True)
  19.  
  20.         Return True
  21.     End Function
  22.  
  23.     Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
  24.         Dim more As Boolean
  25.  
  26.         more = MyDataGridViewPrinter.DrawDataGridView(e.Graphics)
  27.         If more Then e.HasMorePages = True
  28.     End Sub
  29.  
  30.  
  31.     ' The Print Preview Button
  32.     Private Sub btnPrintPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrintPreview.Click
  33.         If SetupThePrinting() Then
  34.             Dim MyPrintPreviewDialog As PrintPreviewDialog = New PrintPreviewDialog()
  35.             MyPrintPreviewDialog.Document = PrintDocument1
  36.             MyPrintPreviewDialog.ShowDialog()
  37.         End If
  38.     End Sub
  39.  
I searched a lot, but I couldn稚 find it.

If you know how i can Save Print Preview inside text file or Excel, please help me. If you can provide an example, that will be so helpful.

Thanks in advance.
May 15 '12 #1
0 2243

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Rob McLennan - ZETLAND | last post by:
Hi, I have set up an external stylesheet, named "print.css", to format the style of all pages printed from my company's website. I've been previewing my changes to the stylesheet by doing...
3
by: Martin Doyle | last post by:
I've racked my brains, dissected the code and scoured the news groups, but I can see nothing giving any indication of why this might be happening. 1. Go to http://www.arkive.org 2. Click on...
0
by: HuggedRugger | last post by:
Hi, Can anyone help me with this. I have a datagrid on a web page I want to send to an excel sheet to print as a report. I send the data using command from my aspx.vb file which works...
1
by: Eager-Learner | last post by:
Through window.open or window.showmodaldialog, I want to open a word or excel document in Print Preview mode. Bcos I don't want the user to make any changes or save it but the user can ONLY VIEW OR...
7
by: black | last post by:
hi all~ in my .py file there are a few print to trace out some message and i wonder if we can save it into a specified file when that script get running. if so, i may just check that file to c...
7
by: Pat | last post by:
I would like to send the Print Preview of a MS Access form to a Snapshot file. The form contains an OLE graph. BACKGROUND A snapshot of a report is possible. If I could I would use a report to...
0
by: sqldude | last post by:
How can I disable the print preview while printing an excel file from C# code? Thanks.
3
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I have a question for you. I have a .csv file which has many lines of data. Each line has many data fields which are delimited by ",". Now I need to extract part of data from this...
5
by: maminx | last post by:
hello all, i want to call window print preview (in browser, File - Print Preview) by javascript, this is the code function printpreview() { var OLECMDID = 7; /* OLECMDID values: * 6...
1
by: RobT | last post by:
*sigh* I can't get this to work. My program fills all the values into an Excel spreadsheet- no problems there. What I'd like to do is a print preview/print function. I can't seem to get my code...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project用lanning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.