Problem reading Excel97 files with version 5.10.06

Questions and answers on how to use XLSReadWriteII 5.
Post Reply
mdonath
Posts: 23
Joined: Fri Oct 05, 2012 11:36 am

Problem reading Excel97 files with version 5.10.06

Post by mdonath »

In version 5.10.05 it was not possible to write this to an Excel97 file:

Code: Select all

	try
	{
		int Lines = 96;
		XLSReadWriteII51->Version = xvExcel97;
		XLSReadWriteII51->Sheets[0]->Columns->Items[0]->Width = 5000;
		TDateTime dt(TDateTime::CurrentDate());
		for(int i=0; i<Lines; i++)
			XLSReadWriteII51->Sheets[0]->AsDateTime[0][i] = dt + double(i+1)/96.;
		::DeleteFile(L"test01.xls");
		XLSReadWriteII51->Filename = L"test01.xls";
		XLSReadWriteII51->Write();
	}
	catch(Exception& e)
	{
		Application->ShowException(&e);
	}

That works fine now. But it is not possible to read this file again:

Code: Select all

		XLSReadWriteII51->Read();
Markus
d3nton
Posts: 133
Joined: Thu Oct 25, 2012 9:48 am

Re: Problem reading Excel97 files with version 5.10.06

Post by d3nton »

I can also reproduce this issue in Delphi.
It throws an 'List index out of bound exception' in unit BIUFF_READII5.pas
procedure TXLSReadII.RREC_COLINFO; line 1252.

Delphi sample code:
var
ExcelFile5 : TXLSReadWriteII5;

begin
ExcelFile5 := TXLSReadWriteII5.Create(nil);
ExcelFile5.Version := xvExcel97;
ExcelFile5.Filename := 'D:\output.xls';
ExcelFile5.Sheets[0].Columns[0].Width := 5000;
ExcelFile5.sheets[0].AsString[0,0] := 'test';

ExcelFile5.Write;
ExcelFile5.Read;
end.

It seems that there is an overflow previously when writing the file in unit
BIFF_WRITEII5.pas procedure TXLSWriteII.WREC_COLINFO; line 1601:
RecCOLINFO(PBuf).FormatIndex := Col.Style.Index - XLS_STYLE_DEFAULT_XF_COUNT;

Col.Style.Index is '0' in the sample case (XLS_STYLE_DEFAULT_XF_COUNT is 1). Since FormatIndex does not accept negative values ( FormatIndex is declared as 'word')
there is an overflow and PRecCOLINFO(PBuf).FormatIndex is saved as 65535. This might be the reason for the 'out of bounds' exception when reading the file.
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: Problem reading Excel97 files with version 5.10.06

Post by larsa »

Hello

FIxed in update 5.10.07
Lars Arvidsson, Axolot Data
d3nton
Posts: 133
Joined: Thu Oct 25, 2012 9:48 am

Re: Problem reading Excel97 files with version 5.10.06

Post by d3nton »

unfortunately it does not seem to be fixed.
Same error in V 5.10.07.

regards d3nton
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: Problem reading Excel97 files with version 5.10.06

Post by larsa »

Hello

The problem is fixed again in update 5.10.08.
Lars Arvidsson, Axolot Data
mdonath
Posts: 23
Joined: Fri Oct 05, 2012 11:36 am

Re: Problem reading Excel97 files with version 5.10.06

Post by mdonath »

No, the problem exists in version 5.10.08 too.
Also TXLSTokenizer.EOF is still present.

Markus
d3nton
Posts: 133
Joined: Thu Oct 25, 2012 9:48 am

Re: Problem reading Excel97 files with version 5.10.06

Post by d3nton »

I can confirm this. The problem still exists.
Just tested with my code above.
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: Problem reading Excel97 files with version 5.10.06

Post by larsa »

Hello

Seems that the fixes was lost when I was moving some files. Version 5.10.09 shall be ok.
Lars Arvidsson, Axolot Data
mdonath
Posts: 23
Joined: Fri Oct 05, 2012 11:36 am

Re: Problem reading Excel97 files with version 5.10.06

Post by mdonath »

Now it seems that 'AsDateTime' is completely broken:

Code: Select all

XLSReadWriteII51->Sheets[0]->AsDateTime[0][0] = TDateTime::CurrentDateTime();
In the Excel file the value is 00.01.1900 00:00

By the way, 'TXLSTokenizer.EOF' still exists, also in version 5.10.09.

Markus
mdonath
Posts: 23
Joined: Fri Oct 05, 2012 11:36 am

Re: Problem reading Excel97 files with version 5.10.06

Post by mdonath »

In the meantime I have found out that 'AsDateTime' fails if the double value of the TDateTime value has more than 4 digits after the decimal point.

Markus
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: Problem reading Excel97 files with version 5.10.06

Post by larsa »

Hello

This was really complicated... Please download the component again. I hope I got it right now...
Lars Arvidsson, Axolot Data
mdonath
Posts: 23
Joined: Fri Oct 05, 2012 11:36 am

Re: Problem reading Excel97 files with version 5.10.06

Post by mdonath »

Hello,

It seems to be the same version (with the same problems) as before (5.10.09).

Markus
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: Problem reading Excel97 files with version 5.10.06

Post by larsa »

Hello

I can't reproduce the problem anymore, so I consider this to be fixed. The version number was hovewer not changed in the last update but it is now, 5.10.10
Lars Arvidsson, Axolot Data
mdonath
Posts: 23
Joined: Fri Oct 05, 2012 11:36 am

Re: Problem reading Excel97 files with version 5.10.06

Post by mdonath »

Congratulations! Now all works fine.
Post Reply