C# Excel Exception

Posted by Andrew James Watt on Stack Overflow See other posts from Stack Overflow or by Andrew James Watt
Published on 2011-11-15T09:47:31Z Indexed on 2011/11/15 9:51 UTC
Read the original article Hit count: 281

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about c#

Related posts about Xml