Recent

Author Topic: Check whether the column width is too small (cell displayed as '########')  (Read 1295 times)

kjteng

  • Sr. Member
  • ****
  • Posts: 259
I want to check (programmatically) whether a specific cell is displayed as '######' (column width too small) . Is there an easy way to do this?

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: Check whether the column width is too small (cell displayed as '########')
« Reply #1 on: November 23, 2019, 11:13:03 am »
There is no built-in routine for that. You must check it yourself. The # characters appear when
- the column width is less than the length of the text, and
- the cell does not contain a string (cell^.ContentType <> cctUTF8String), and
- the number format is not nfGeneral

Or maybe like this:
Code: Pascal  [Select][+][-]
  1. type
  2.   TMyWorksheetGrid = class(TsWorksheetGrid);
  3.  
  4. function TForm1.HashMarkedCell(ACell: PCell): Boolean;
  5. var
  6.   s1, s2: String;
  7. begin
  8.   Result := false;
  9.   if ACell = nil then exit;
  10.  
  11.   s1 := sWorksheetGrid1.Worksheet.ReadAsText(ACell);
  12.   s2 := TMyWorksheetGrid(sWorksheetGrid1).TrimToCell(ACell);
  13.   Result := (s1 <> s2) and (s2[1] = '#');
  14. end;
« Last Edit: November 23, 2019, 12:03:19 pm by wp »

kjteng

  • Sr. Member
  • ****
  • Posts: 259
Re: Check whether the column width is too small (cell displayed as '########')
« Reply #2 on: November 24, 2019, 01:34:36 pm »
Thanks master.  TrimToCell works for me.
BTW I noticed that the protected functions can only called in the specific way (i.e. typecast to TMyWorksheetGrid) but TsWorksheetGrid(sWorksheetGrid1).TrimToCell(ACell) would not compile.  May I know what is the reason?

 

TinyPortal © 2005-2018