Recent

Author Topic: fpSpreadSheet headers and visible columns  (Read 1054 times)

carlangas

  • Jr. Member
  • **
  • Posts: 57
fpSpreadSheet headers and visible columns
« on: November 04, 2021, 04:58:48 pm »
I don't find any property to change the header of each column instead of the letters. Is it possible?

Another thing I would want to limit would be the number of visible columns. I can use the ColCount property, but if I navigate the table, it keeps adding columns.

I have used a few times StringGrid and I managed to do what I want with them, but I am afraid I cannot display rich text in these cells. Namely, I need to display text in varied colours in the same cell. Would it be possible in a StringGrid?

Thanks for your help.

wp

  • Hero Member
  • *****
  • Posts: 9157
Re: fpSpreadSheet headers and visible columns
« Reply #1 on: November 04, 2021, 06:50:56 pm »
I don't find any property to change the header of each column instead of the letters. Is it possible?
TsWorksheetGrid has an event OnGetColHeaderText in which you can change the column titles (likewise OnGetRowHeaderText for the row headers):
Code: Pascal  [Select][+][-]
  1. procedure TForm1.sWorksheetGrid1GetColHeaderText(Sender: TObject;
  2.   AIndex: Integer; var AText: String);
  3. begin
  4.   case AIndex of
  5.     0: AText := '';
  6.     1: AText := 'Hello';
  7.     2: AText := 'World';
  8.     else AText := 'Column ' + IntToStr(AIndex);
  9.   end;
  10. end;

Another thing I would want to limit would be the number of visible columns. I can use the ColCount property, but if I navigate the table, it keeps adding columns.
Remove the option aeNavigation from the AutoExpand property of the WorksheetGrid.

I have used a few times StringGrid and I managed to do what I want with them, but I am afraid I cannot display rich text in these cells. Namely, I need to display text in varied colours in the same cell. Would it be possible in a StringGrid?
Using fpspreadsheet just to draw painted text appears to be too heavy to me. Yes, you can owner-draw the stringgrid. But you must add some parsing code to identify which characters are to be painted in which color.

The fpspreadsheet grid does this by converting the rich text to html. Unfortunately the related unit depends too much on fpspreadsheet. But a html parser is contained in the JVCL library which can be extracted more easily into a stand-alone unit (https://forum.lazarus.freepascal.org/index.php/topic,55971.msg416110.html#msg416110). The attached demo can help you to get started.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

carlangas

  • Jr. Member
  • **
  • Posts: 57
Re: fpSpreadSheet headers and visible columns
« Reply #2 on: November 04, 2021, 10:17:50 pm »
Thanks a lot. I had been tinkering around with everything that sounded likely to solve it with no luck.

This is what I needed.

I prefer using fpSpreadSheet because it gives me the possibility of importing and importing to various formats. Using a common grid was a choice in case I did not find a way to do what I wanted with fpSpreadSheet. Anyway, I'll take a look at your suggestion to learn a bit about how to enhance my controls.

 

TinyPortal © 2005-2018