hi guys,
Using vb.net 2010 I'm generating a report which uses an excel template.
I have no problems opening a PrintDialog, duplicating the template to a temp file, opening with Excel, acessing the cells, using the PrintOut method, making all the objects = nothing and deleting the temp file....
the problem is, the PrintOut method only receives the PrinterName whilst the PrinterDialog can set a wide range of printer parameters specially as color; b/w; draft...
The software will he deployed for a bunch of different ppl so I HAVE TO use late binding on this one.
Any help on: How to either open excel built-in print dialog for printing, or to pass the printer parameters to Excel before the PrintOut command???
Here is the code, I spared you guys from having to read where I populate the cells.
Using vb.net 2010 I'm generating a report which uses an excel template.
I have no problems opening a PrintDialog, duplicating the template to a temp file, opening with Excel, acessing the cells, using the PrintOut method, making all the objects = nothing and deleting the temp file....
the problem is, the PrintOut method only receives the PrinterName whilst the PrinterDialog can set a wide range of printer parameters specially as color; b/w; draft...
The software will he deployed for a bunch of different ppl so I HAVE TO use late binding on this one.
Any help on: How to either open excel built-in print dialog for printing, or to pass the printer parameters to Excel before the PrintOut command???
Here is the code, I spared you guys from having to read where I populate the cells.
VB.NET:
Dim PD As New PrintDialog
Dim FileName As String = "c:\temp " & Abs(Now.ToBinary).ToString & ".xlt"
PD.AllowPrintToFile = False
PD.AllowSelection = False
PD.AllowSomePages = False
PD.AllowCurrentPage = False
PD.PrintToFile = False
PD.ShowHelp = False
If PD.ShowDialog() <> 1 Then Exit Sub
If Not PD.PrinterSettings.IsValid Then Exit Sub
Try
oExcel = CreateObject("Excel.Application")
oExcel.UserControl = False
oExcel.Visible = False
File.WriteAllBytes(FileName, My.Resources.CalibrationCertificate)
oWB = oExcel.Workbooks.Open(FileName)
oWS = oWB.Worksheets(1)
' Here is where I played with the cell values and populate all the info it needs
oWB.PrintOut(, , , , PD.PrinterSettings.PrinterName)
oExcel.Quit()
oWS = Nothing
oWB = Nothing
oExcel = Nothing
r.Sleep(100)
File.Delete(FileName)
Catch ex As Exception
r.ErrorLog(ex.Message)
MessageBox.Show(ex.Message, r.text(Me.Name, "Error:"), MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try