Results 1 to 1 of 1

Thread: Checking Excel types

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Dunmow,Essex,England
    Posts
    898

    Checking Excel types

    Hi All,

    I have found an interesting one. I have written an Application based on the Excel files being saved as a 'Workbook'. I was sent new excel files and for all intense and purpose they looked identical save for the data in them the same as previous files.

    When I went to open the files using an OleDbConnection I received an error stating that the files were not in the expected format. Further investigation found that the files had been saved as spreadsheet and not workbook so failed to open. Once I did a manual open of the excel file and did a SaveAs workbook, my app opened the file no problem.

    I therefore want to amend the app to check how the Excel file was saved. At the moment I've got away with not using Office.Interop and am just using ADO.NET. does anybody have any ideas how I can test for the original 'save type'?

    Using Office interop, the following code will do what I want, so I'm really looking for the ADO.NET equivalent.

    Code:
    Microsoft.Office.Interop.Excel.Application ExcelApp = new Microsoft.Office.Interop.Excel.Application();
                ExcelApp.DisplayAlerts = false;
                Microsoft.Office.Interop.Excel.Workbook WB = ExcelApp.Workbooks.Open(@Source);
                WB.SaveAs(@Source, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing);
                WB.Close(true, @Source, false);
                ExcelApp.Quit();
    Last edited by Bill Crawley; Feb 8th, 2011 at 11:20 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width