1 Replies - 11060 Views - Last Post: 29 September 2010 - 05:03 AM Rate Topic: -----

#1 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 469
  • View blog
  • Posts: 4,280
  • Joined: 25-March 09

C# and Excel error

Posted 29 September 2010 - 04:40 AM

Hi to everyone :)

i`m trying to send data to excel. and i get this error:
System.Runtime.InteropServices.COMException was unhandled
Message="Old format or invalid type library. (Exception from HRESULT: 0x80028018 (TYPE_E_INVDATAREAD))"


i`m using excel 2003 and C#. here is my code:
            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 and project references are correct.");
                return;
            }
            xlApp.Visible = true;
            Microsoft.Office.Interop.Excel.Workbook xlWB = xlApp.Workbooks.Add(
                Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet);
            Microsoft.Office.Interop.Excel.Worksheet xlWS = (Microsoft.Office.Interop.Excel.Worksheet)
                xlWB.Worksheets[1];



i get the error a this line:
Microsoft.Office.Interop.Excel.Workbook xlWB = xlApp.Workbooks.Add(
                Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet);



is this because i`m using old version of excel. i use Microsoft.Office.Interop.Excel v11.00

can someone pls help me :)

Is This A Good Question/Topic? 0
  • +

Replies To: C# and Excel error

#2 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 469
  • View blog
  • Posts: 4,280
  • Joined: 25-March 09

Re: C# and Excel error

Posted 29 September 2010 - 05:03 AM

For everyone that have the same problem from this link:
http://support.microsoft.com/kb/320369

the solution for me is:
            System.Globalization.CultureInfo oldCI = System.Threading.Thread.CurrentThread.CurrentCulture;
            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
            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 and project references are correct.");
                return;
            }
            xlApp.Visible = true;
            Microsoft.Office.Interop.Excel.Workbook xlWB = xlApp.Workbooks.Add(
                Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet);
            Microsoft.Office.Interop.Excel.Worksheet xlWS = (Microsoft.Office.Interop.Excel.Worksheet)
                xlWB.Worksheets[1];


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1