Forum > FPSpreadsheet

fpSpreadSheet headers and visible columns

(1/1)

carlangas:
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:

--- Quote from: carlangas 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?

--- End quote ---
TsWorksheetGrid has an event OnGetColHeaderText in which you can change the column titles (likewise OnGetRowHeaderText for the row headers):

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.sWorksheetGrid1GetColHeaderText(Sender: TObject;   AIndex: Integer; var AText: String);begin  case AIndex of    0: AText := '';    1: AText := 'Hello';    2: AText := 'World';    else AText := 'Column ' + IntToStr(AIndex);  end;end;

--- Quote from: carlangas on November 04, 2021, 04:58:48 pm ---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.
--- End quote ---
Remove the option aeNavigation from the AutoExpand property of the WorksheetGrid.


--- Quote from: carlangas on November 04, 2021, 04:58:48 pm ---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?

--- End quote ---
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.

carlangas:
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.

Navigation

[0] Message Index

Go to full version