"floating point division by zero" with AutoWidthCols

Questions and answers on how to use XLSReadWriteII 5.
andre.santos
Posts: 12
Joined: Tue Dec 17, 2013 4:56 pm

"floating point division by zero" with AutoWidthCols

Post by andre.santos »

Hi

When i use the AutoWidthCols(), this function be return a error - "floating point division by zero" .
In old version worked perfectly, but after update the component this problem has happened.
adrianosilva
Posts: 15
Joined: Thu Aug 29, 2013 5:45 pm

Re: "floating point division by zero" with AutoWidthCols

Post by adrianosilva »

Hello,

I updated to the latest version and got the same error.
Best regards,

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

Re: "floating point division by zero" with AutoWidthCols

Post by larsa »

Hello

I can't reproduce this. Tested with update 5.20.11
It the error persists, please provide a complete sample that reproduces the error.
Lars Arvidsson, Axolot Data
andre.santos
Posts: 12
Joined: Tue Dec 17, 2013 4:56 pm

Re: "floating point division by zero" with AutoWidthCols

Post by andre.santos »

Hi

I did the sample and the error still persist. This code:

XLS.Clear();

XLS[0].AsString[0, 0] := 'Testing Value 0';
XLS[0].AsString[0, 1] := 'Testing Value';
XLS[0].AsString[0, 2] := 'Testing';
XLS[0].AsString[0, 3] := 'Testing Value 0 Testing Value 0 Testing Value 0';

XLS[0].AsString[1, 0] := 'Testing';
XLS[0].AsString[1, 1] := 'Testing Value 0 Testing Value 0 Testing Value 0';
XLS[0].AsString[1, 2] := 'Testing';
XLS[0].AsString[1, 3] := 'Testing Value';

XLS[0].AutoWidthCols(0, 1);
XLS[0].Name := 'Teste';
XLS.Filename := 'C:\Test.xlsx';
XLS.Write;

I am using the latest version.
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: "floating point division by zero" with AutoWidthCols

Post by larsa »

Hello

Still no luck. Which Delphi version do you use?
Lars Arvidsson, Axolot Data
andre.santos
Posts: 12
Joined: Tue Dec 17, 2013 4:56 pm

Re: "floating point division by zero" with AutoWidthCols

Post by andre.santos »

Hi,

i´m using Delphi XE2
andre.santos
Posts: 12
Joined: Tue Dec 17, 2013 4:56 pm

Re: "floating point division by zero" with AutoWidthCols

Post by andre.santos »

Hi

when I was debugging the code of component, i found this code in 'XLSColumn5.pas'

//XLSColumn5.pas
procedure TXLSColumn.SetPixelWidth(const AValue: integer);
begin
SetWidth(Round(Trunc((AValue - 5) / FOwner.FStyles.StdFontWidth * 100 + 0.5) / 100) * 256);
end;

the value of StdFontWidth is ZERO, returning the error message.
continuing debug the code, i found in 'Xc12DataStyleSheet5.pas', this code:

{$ifdef XLS_XSS}
procedure TXc12Fonts.CalcStdFontWidthHeight;
var
i: integer;
S: AxUCString;
Sz: TSize;
DC: HDC;
begin
FStdFontWidth := 0;
DC := CreateIC('DISPLAY',Nil,Nil,Nil);
try
SelectObject(DC,Items[0].GetHandle(GetDeviceCaps(DC,LOGPIXELSY)));
for i := 1 to 10 do begin
S := StrDigits;
Windows.GetTextExtentPoint32W(DC,PWideChar(S),1,Sz);
if Sz.cx > FStdFontWidth then
FStdFontWidth := Sz.cx;
end;
FStdFontHeight := Items[0].FLF.lfHeight;
finally
DeleteDC(DC);
end;
end;
{$endif}

Here FStdFontWidth receives a value, but when the application is running this code not executed.
In none moment the directive XLS_XSS is defined, so this code came be ignored.
adrianosilva
Posts: 15
Joined: Thu Aug 29, 2013 5:45 pm

Re: "floating point division by zero" with AutoWidthCols

Post by adrianosilva »

Hello,

I'm using Delphi 7 and XLSReadWriteII 5.20.11.

Code below:

sFileName := ExtractFilePath(Application.ExeName) + '\TestXLS.xlsx';
sMsg := '';
Try
xlsWorkbook.Clear;
xlsWorkbook.Version := xvExcel2007;
xlsWorkbook.Filename := sFileName;
xlsWorkSheet := xlsWorkbook.Sheets[0];
xlsWorkSheet.AsString[0, 0] := 'Value';
xlsWorkSheet.AsString[1, 0] := 'Formula';
xlsWorkSheet.AsString[2, 0] := 'Result';
xlsWorkSheet.AutoWidthCols(0, 2); // Here is when the error occurs
xlsWorkbook.Write;
Except
on E : Exception do
begin
MessageBox(Application.Handle, PChar(E.Message + ' - ' + sMsg), 'TestXLS', MB_OK + MB_ICONERROR);
end;
end;
Best regards,

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

Re: "floating point division by zero" with AutoWidthCols

Post by larsa »

Hello

Working fine with D7 as well. The latest update is 5.20.12. Please try that.
Lars Arvidsson, Axolot Data
andre.santos
Posts: 12
Joined: Tue Dec 17, 2013 4:56 pm

Re: "floating point division by zero" with AutoWidthCols

Post by andre.santos »

Hello

I updated to the latest version (5.20.12), but the same error still persist.

I use delphi XE2
rjvanvliet
Posts: 17
Joined: Fri Feb 01, 2013 8:24 pm

Re: "floating point division by zero" with AutoWidthCols

Post by rjvanvliet »

I got the same problem with Delphi Xe5.

Also the same error when inserting an image.

Regards,
RJvV
CareAll
Posts: 28
Joined: Mon Jun 24, 2013 9:30 am

Re: "floating point division by zero" with AutoWidthCols

Post by CareAll »

Same with Delphi 7.
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: "floating point division by zero" with AutoWidthCols

Post by larsa »

Hello

As I can't reproduce this error and hence debug the code, please check where/what in the source code that it is that causes this.
Lars Arvidsson, Axolot Data
rjvanvliet
Posts: 17
Joined: Fri Feb 01, 2013 8:24 pm

Re: "floating point division by zero" with AutoWidthCols

Post by rjvanvliet »

Hello,

I downloaded the latest version and removed all xlsread*.* files after deinstallation. Then I installed version 5.20.13 and now auto width and images word fine again. it must be some old source in my debug/ release dir. Strange but it works for me. So happy again!!

Regards,
RJ
adrianosilva
Posts: 15
Joined: Thu Aug 29, 2013 5:45 pm

Re: "floating point division by zero" with AutoWidthCols

Post by adrianosilva »

Hello,

The error occurs on file XLSColumn5.pas, line 328, in the procedure below:

procedure TXLSColumn.SetPixelWidth(const AValue: integer);
begin
SetWidth(Round(Trunc((AValue - 5) / FOwner.FStyles.StdFontWidth * 100 + 0.5) / 100) * 256);
end;

AValue has a integer value greater than 0 and FOwner.FStyles.StdFontWidth value is 0.
Best regards,

Adriano Silva
Post Reply