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?
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?