The printout method seem no work on my Application.

uyenchi

New member
Joined
Sep 17, 2003
Messages
1
Dear all,

On my application, I create Excel file as code below:

-------------------------------------------------------------------
private void butPrint_Click(object sender, System.EventArgs e)
{
Excel.Application oXL;
Excel._Workbook oWB;
Excel._Worksheet oSheet;

try
{
//Start Excel and get Application object.
oXL = new Excel.Application();
//Get a new workbook.
oWB = (Excel._Workbook)(oXL.Workbooks.Add( Missing.Value ));

oSheet = (Excel._Worksheet)oWB.ActiveSheet;

//-------------------------------------------------------
//Add content here
//-------------------------------------------------------

if (MessageBox.Show("Do you want to save this report?","Save report",MessageBoxButtons.YesNo,MessageBoxIcon.Question)==DialogResult.Yes)
{
oSheet.SaveAs(@"C:\test.xls",Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value);
}
oXL.ActiveWorkbook.PrintOut(Type.Missing , Type.Missing, Type.Missing, true, Type.Missing, Type.Missing, Type.Missing,Type.Missing);

oWB.Close(false,Missing.Value,Missing.Value);
}
catch( Exception theException )
{
blMwssage.Text=errorMessage;
}

oXL=null;
this.Cursor=Cursors.Default;
lblMwssage.Visible=true;
}

-----------------------------------------------------------------------
It works very well except oXL.ActiveWorkbook.PrintOut
I replace printout with oSheet.PrintOut but it still no work.

Please show me what is wrong?
 
try this:
oSheet.SelectedSheets.PrintOut(whatever)

if you do a Macro in Excel for printing out you get the following:
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True

leading me to believe you should use your oSheet variable rather than your oWB variable.

Hope this helps or at least points you to a new direction
 
Back
Top