I'm using an embed resources in my c# application
string sPath = System.IO.Path.GetTempFileName();
System.IO.File.WriteAllBytes(sPath, Properties.Resources.test)
workbook = app.Workbooks.Open(sPath,missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
It worked fine until today,It throw me some bad exception:
System.NullReferenceException: Object reference not set to an instance of an object at ......
It is only on 2 windows xp proffesional edition installations, both root and user accounts (u开发者_JAVA技巧ser account is very limited there, because of admin policy).
Till today it worked on several xp and vista installation, without any problems.
What could be a cause of this problem?
Thank you for any ideas.
I think this would be a reference issue due to version problem as you stated. Since you added in a reference to the Microsoft Excel 11.0 Object Library (2003 excel) then I don't think you can create an Microsoft Excel 9.0 (Excel 2000) app. I've never tried dealing with different versions but maybe you can add both reference in and open them in a try and catch when one fails.
pseudo code
try{
workbook = app.Workbooks.Open(sPath,missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
}
catch ( NullReferenceException e )
{
// This means the user is in Excel 9.0 (Excel 2000)
// Open workbook as Excel 2000
}
Hope this helps
精彩评论