C# .NET - file is not a valid ole2 compound file. gembox please help me?

Asked By avula on 27-Jun-12 07:16 AM
Hi Every one

file is not a valid ole2 compound file. gembox
am getting Actually am uploading the input file format is .txt then am changing the Path.ChangeExtension to .xls
Gembox getting error in
ExcelFile ef = new ExcelFile();


//here error thrown please help me

Jitendra Faye replied to avula on 27-Jun-12 09:01 AM
The file which you are loading using LoadXLs() method that file should be valid XLs file, As you told that you have changed extension .txt to .xls. but it doesn't mean that that file is also converted to xls file.

avula replied to Jitendra Faye on 27-Jun-12 09:41 AM
When i open the file its showing as i expected..but how can i convert to text file to excel file.

Vikram Singh Saini replied to avula on 27-Jun-12 10:51 AM

How the following code line works?

ExcelFile ef = new ExcelFile();

Since the Microsoft uses the same file as storage container for storing embedded data of excel file for .xls file.

Now when we change the extension of .txt file to .xls file, it get modified but still when we try to open same in Office Excel it show modal dialog box stating as,

"The file you are trying to open, 'Document.xls', is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?" Yes || No || Help

So that implies that while we have changed the extension, still the file is not complete .xls file because it is missing the Ole2Compound file.

And in same manner, internally, Gembox tries to extract storage information from Ole2Compound file associated with .xls file. Then convert plain text information of .xls file to temporary memory and save or load it as plain .xls. Now when we try the .txt converted to .xls file it expects the Ole2Compound file but that's not there and hence error.

Solution: You would need to convert the .txt document into .xls file in proper way. Merely changing extension doesn't set all internal things.

Hope it helps.
avula replied to Vikram Singh Saini on 27-Jun-12 11:37 PM
Yes,Can u please tell me which way is the best to convert text file to Excel file.
i want to read bulk text file data(more than 1Lack) into data set , but TabDelimeted not with " ","", format please help me
my text file saparated with \t  ,\n
please help me thanks