0

Encountered ApplicationException Occured "Invalid file format" exception

Code Details:

// Step:1 load the log file
  private static String logFilePath =Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "XYZ", "ABC", "Log") + "\\log.xls";
   C1XLBook logBook = new C1XLBook();
   logBook.Load(logFilePath);
   XLSheet logSheet = logBook.Sheets[0];

Exception stacktrace

at C1.C1Excel.C1XLBook.(String msg, Boolean badArgument)
at C1.C1Excel.C1XLBook.(String msg)
at C1.C1Excel.C1XLBook.(String fileName, Boolean fillSheets)
at C1.C1Excel.C1XLBook.Load(String fileName, FileFormat format, Boolean fillSheets)
at C1.C1Excel.C1XLBook.Load(String fileName)

Getting exception on this line

XLSheet logSheet = logBook.Sheets[0];
Ashwin Patil
  • 1,307
  • 1
  • 23
  • 27
  • Seems pretty straightforward... This `C1Excel` tool is expecting a specific file format, and the file you're providing doesn't match that format. One of the overloads for `.Load()` looks like it allows you to specify the format, maybe try that? – David Oct 03 '13 at 10:16
  • I have tried both xls and xlsx.. Getting same error. – Ashwin Patil Oct 03 '13 at 10:57

1 Answers1

0

There can be multiple reasons for this :

  1. The file might be generated using Excel95. Latest version of C1Excel supports loading Excel95 also.
  2. There is no file on the logFilePath path
  3. Excel file is corrupt.

Try using the latest build or following overload to load the file :

c1XLBook1.Load(logFilePath ,FileFormat.Biff8 );

Thanks, Richa

Richa
  • 69
  • 3