I
i3tech
Hi,
While iam trying to copy a worksheet from one file to another file in C#,
VS.NET 2003 i get error message saying: "Exception from HRESULT:
0x800A03EC."
The Exact Code i used is:
Excel.Application xlApp1 = new Excel.ApplicationClass();
Excel.Application xlApp2 = new Excel.ApplicationClass();
object missing = Type.Missing;
xlApp1.Workbooks.Open(System.Windows.Forms.Application.StartupPath +
@"\Reports.xls" ,
missing , missing, missing, missing, missing,missing, missing, missing,
missing, missing, missing, missing, missing, missing);
xlApp2.Workbooks.Open(System.Windows.Forms.Application.StartupPath +
@"\Template.xls" ,
missing , missing, missing, missing, missing,missing, missing, missing,
missing, missing, missing, missing, missing, missing);
Excel.Workbook xlSrcBook;
Excel.Workbook xlDestBook;
xlSrcBook = xlApp2.ActiveWorkbook as Workbook;
xlDestBook = xlApp1.ActiveWorkbook as Workbook;
try
{
(xlSrcBook.Sheets[2] as
Worksheet).Copy(missing,xlDestBook.Sheets[xlDestBook.Sheets.Count]);
xlApp2.Visible = true;
}
catch(Exception ex)
{
MessageBox.Show(this,ex.Message);
}
finally
{
xlSrcBook.Saved = true;
xlDestBook.Saved = true;
xlSrcBook.Close(missing,missing,missing);
xlDestBook.Close(missing,missing,missing);
xlApp1.Quit();
xlApp1 = null;
xlApp2.Quit();
xlApp2 = null;
}
Can someone please help me in finding out the mistake ?
While iam trying to copy a worksheet from one file to another file in C#,
VS.NET 2003 i get error message saying: "Exception from HRESULT:
0x800A03EC."
The Exact Code i used is:
Excel.Application xlApp1 = new Excel.ApplicationClass();
Excel.Application xlApp2 = new Excel.ApplicationClass();
object missing = Type.Missing;
xlApp1.Workbooks.Open(System.Windows.Forms.Application.StartupPath +
@"\Reports.xls" ,
missing , missing, missing, missing, missing,missing, missing, missing,
missing, missing, missing, missing, missing, missing);
xlApp2.Workbooks.Open(System.Windows.Forms.Application.StartupPath +
@"\Template.xls" ,
missing , missing, missing, missing, missing,missing, missing, missing,
missing, missing, missing, missing, missing, missing);
Excel.Workbook xlSrcBook;
Excel.Workbook xlDestBook;
xlSrcBook = xlApp2.ActiveWorkbook as Workbook;
xlDestBook = xlApp1.ActiveWorkbook as Workbook;
try
{
(xlSrcBook.Sheets[2] as
Worksheet).Copy(missing,xlDestBook.Sheets[xlDestBook.Sheets.Count]);
xlApp2.Visible = true;
}
catch(Exception ex)
{
MessageBox.Show(this,ex.Message);
}
finally
{
xlSrcBook.Saved = true;
xlDestBook.Saved = true;
xlSrcBook.Close(missing,missing,missing);
xlDestBook.Close(missing,missing,missing);
xlApp1.Quit();
xlApp1 = null;
xlApp2.Quit();
xlApp2 = null;
}
Can someone please help me in finding out the mistake ?