G
Guest
This is a question about working with Excel from .NET so if this is the wrong newsgroup, please let me know. Technologies are .NET Framework 1.1, C#, Excel 2003.
I have a Windows Forms app that is extracting information from about 450 similarly formatted spreadsheets. So I'm opening the spreadsheet, extracting the info into a dataset, closing the spreadsheet and moving on to the next one.
I always get an error when opening some spreadsheets. It's not the spreadsheets because it fails on different ones each time through. E.g. It will fail on the twelfth one the first time, then the twenty-third one the next time, and so on.
It's not a .NET error (so I can't trap it in a try-catch block). When it fails, a dialog appears with Microsoft Visual Basic as the title (I'm using C#) and the message is "File already exists". Note that I have Interactive set to false for the Excel application.
My theory is that I'm opening and closing spreadsheets too fast because when I put a Thread.Sleep(100) between the Close/Open statements, it works (although much slower than I'd like). I suspect that Excel is creating a temporary file based on the current time when the spreadsheet is opened and isn't deleting it fast enough when it is closed. So when the next spreadsheet is opened in the same "time frame" it tries to create a new temp file with the same name.
One final note: If I don't reference the Worksheets collection of the workbook, no error occurs. It fails only when I starting working with the sheets in the workbook (even if all I do is set a variable to workbook.Worksheets.Count).
I have a Windows Forms app that is extracting information from about 450 similarly formatted spreadsheets. So I'm opening the spreadsheet, extracting the info into a dataset, closing the spreadsheet and moving on to the next one.
I always get an error when opening some spreadsheets. It's not the spreadsheets because it fails on different ones each time through. E.g. It will fail on the twelfth one the first time, then the twenty-third one the next time, and so on.
It's not a .NET error (so I can't trap it in a try-catch block). When it fails, a dialog appears with Microsoft Visual Basic as the title (I'm using C#) and the message is "File already exists". Note that I have Interactive set to false for the Excel application.
My theory is that I'm opening and closing spreadsheets too fast because when I put a Thread.Sleep(100) between the Close/Open statements, it works (although much slower than I'd like). I suspect that Excel is creating a temporary file based on the current time when the spreadsheet is opened and isn't deleting it fast enough when it is closed. So when the next spreadsheet is opened in the same "time frame" it tries to create a new temp file with the same name.
One final note: If I don't reference the Worksheets collection of the workbook, no error occurs. It fails only when I starting working with the sheets in the workbook (even if all I do is set a variable to workbook.Worksheets.Count).