Recent

Author Topic: Timeformat-Cells are in TsWorksheetGrid not editable, bug or feature?  (Read 3632 times)

Soner

  • Sr. Member
  • ****
  • Posts: 305
Timeformat-Cells are in TsWorksheetGrid not editable, bug, feature or do I have to do something extra?

To reproduce the problem follow the next steps or try it with spready example application.

1. Create new project and place on the form one TsWorksheetGrid and TButton.

2. Make Grid editable.(--> sWorksheetGrid1.Options.goEditing:=true)

3. Write in Buttons onclick handler this:
Code: Pascal  [Select][+][-]
  1. uses fpsTypes;
  2. procedure TForm1.Button1Click(Sender: TObject);
  3. begin
  4.   sWorksheetGrid1.Worksheet.WriteNumberFormat(0,0,nfGeneral);
  5. end;
  6.  
4. Run the example and enter in the cell A1 an hour i.e.:
10:30

5. Now try to change the cell A1, you can't.

6. Click on Button1 to change Cell-A1 format to default number.

7. Now you can edit the cell A1, but every time, when you enter a time the cell-format changes again to time-format and you cant edit anymore.

Soner

  • Sr. Member
  • ****
  • Posts: 305
Re: Timeformat-Cells are in TsWorksheetGrid not editable, bug or feature?
« Reply #1 on: August 04, 2018, 03:08:53 pm »
It seems to be a bug.
You can not change time entry to other time entry but you can change time to a number i.E:
Changing 3:30 to 4:30 is not allowed, but you can change in two steps. First to 4 then to 4:30 .

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Timeformat-Cells are in TsWorksheetGrid not editable, bug or feature?
« Reply #2 on: August 04, 2018, 05:51:32 pm »
Seems to be a left-over of some "optimization"...

Since I am expecting side-effects could you please try this:
  • Open fpspreadsheet.pas
  • Find procedure TsWorksheet.WriteCellValueAsString
  • There are several "if TryStrTo<Something>" calls.
  • Find the block with "if TryStrToDateTime" and replace it by this
Code: Pascal  [Select][+][-]
  1.   if TryStrToDateTime(AValue, number, AFormatSettings) then
  2.   begin
  3.     if (number < 1.0) or IsTimeFormat(numFmtParams) then          // this is a time alone
  4.     begin
  5.       ucValue := Uppercase(AValue);
  6.       isAMPM := (pos('AM', ucValue) > 0) or (pos('PM', ucValue) > 0);
  7.       isLongTime := IsLongTimeFormat(AValue, AFormatSettings.TimeSeparator);
  8.       WriteDateTime(ACell, number, TIME_FMT[isAMPM, isLongTime]);
  9.     end else
  10.     if frac(number) = 0.0 then  // this is a date alone
  11.     begin
  12.       if pos(' ', AValue) > 0 then
  13.         WriteDateTime(ACell, number, nfShortDateTime)
  14.       else
  15.         WriteDateTime(ACell, number, nfShortDate);
  16.     end else
  17.     if not IsDateTimeFormat(fmt.NumberFormat) then
  18.       WriteDateTime(ACell, number, nfShortDateTime)
  19.     else
  20.       WriteDateTime(ACell, number);
  21.     if IsTextFormat(numFmtParams) then
  22.     begin
  23.       WriteNumberFormat(ACell, nfText);
  24.       WriteText(ACell, AValue);
  25.     end;
  26.     exit;
  27.   end;

Soner

  • Sr. Member
  • ****
  • Posts: 305
Re: Timeformat-Cells are in TsWorksheetGrid not editable, bug or feature?
« Reply #3 on: August 04, 2018, 06:35:58 pm »
I did it in:
Code: Pascal  [Select][+][-]
  1. procedure TsWorksheet.WriteCellValueAsString(ACell: PCell; AValue: String;  const AFormatSettings: TFormatSettings);
  2. //...
  3.   // Check for a date/time value:
  4.   // Must be after float detection because StrToDateTime will accept a string
  5.   // "1" as a valid date/time.
  6.  
  7.   // ^after this comment, from line ~#5209
  8.  
I used trunk version 6568 from lazarus-ccr (today ~12:00 O'Clock. )

It works.
But I can not say something about side effects because I don't use this component. Today, I took closer look to this component, because I am thinking to use it. Maybe I take KGrid and do calculations myself.


 There is second issue. I explain it with example.
When you have a formula in a3 like this:
=a1+a2
And the cells a1 have the value 1 and a2 2 then the result is 3 and that is right.
Now when you change the value a1 to some string like this 'hello' then the result of formula 2, because fpspreadsheet calculates the string cells as 0.
That is wrong. It should something like "NaN", "Not a Number" or something like this.
The user have to see that something is wrong with entries and correct it.


wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Timeformat-Cells are in TsWorksheetGrid not editable, bug or feature?
« Reply #4 on: August 05, 2018, 05:51:39 pm »
Fixed in r6570.

Soner

  • Sr. Member
  • ****
  • Posts: 305
Re: Timeformat-Cells are in TsWorksheetGrid not editable, bug or feature?
« Reply #5 on: August 06, 2018, 09:58:45 am »
Thanks.

 

TinyPortal © 2005-2018