Excel Automation problem

  • Thread starter Thread starter Walter Andosen
  • Start date Start date
W

Walter Andosen

I have some trouble creating a Excel workbook. I get lots
of Exceptions.

For example I get
System.Runtime.InteropServices.COMException (0x80028018):
Old format or invalid type library.
at Excel.ApplicationClass.set_DisplayAlerts(Boolean RHS)

when I do

Excel.Application excel=new Excel.Application();
excel.DisplayAlerts=false; // <-- Exception thrown here.

I have problems with this as well (I get some HRESULT
error):

Excel.Range range;
range=worksheet.get_Range("A1",Missing.Value).get_Resize
(1,fieldCount);
range.set_Value(Missing.Value,headers);
range.Font.Bold=true;

I also get the "Old format or invalid type library."
error when I do:
workbook.SaveAs
(@"C:\Book1.xls",Excel.XlFileFormat.xlXMLSpreadsheet,Missi
ng.Value,Missing.Value,Missing.Value,Missing.Value,Excel.X
lSaveAsAccessMode.xlNoChange,Missing.Value,Missing.Value,M
issing.Value,Missing.Value,Missing.Value);


What is wrong? I'm using Office 2003 and I have the
following references:
adodb
Excel
Microsoft.Office.Core
stdole
System
VBIDE

usings:
using System;
using System.Collections;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.InteropServices;
using ADODB;

Other Excel things like
range.CopyFromRecordset(rs,Missing.Value,Missing.Value);

Please help!

Walter
 
There is a bug in Excel 2003 that may cause an "Old format or invalid type
library" exception. The exception is thrown when the method your calling or
the method called internally by the public property requires an LCID locale
identifier and you're running an English version of Excel on a computer with
a forreign regional setting.
The easiest way to workaround the bug is to set the CurrentCulture property
of the Thread to en-US.
System.Threading.Thread.CurrentThread.CurrentCulture = new
CultureInfo("en-US");

Anders Norås
http://dotnetjunkies.com/weblog/anoras/
 
Back
Top