I am trying to copy all data from worksheet1 and paste the values into worksheet2 at the same position I am using office 2003 and the Interlop library.
Here is my code;
public void CreateExcelWorksheet()
{
Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
if (xlApp == null)
{
Console.WriteLine("EXCEL could not be started. Check that your office installation.");
return;
}
xlApp.Visible = true;
Workbook wb = xlApp.Workbooks.OpenXML(@"C:\XML_Export.xml", Type.Missing, 2);
Worksheet worksheet1 = wb.Worksheets[1] as Worksheet;
Worksheet worksheet2 = wb.Worksheets[2] as Worksheet;
worksheet1.UsedRange.Copy(Type.Missing);
worksheet2.PasteSpecial(Microsoft.Office.Interop.Excel.XlPasteType.xlPasteValues, false, false, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
}
For some reason after the paste command the following exception occurs:
Exception from HRESULT: 0x800A03EC
Could anyone help?