Recent

Author Topic: Reading and setting cell format, stuck  (Read 1149 times)

zxandris

  • Full Member
  • ***
  • Posts: 170
Reading and setting cell format, stuck
« on: August 07, 2025, 09:16:01 am »
Hey there I'm using Lazarus 2.2.6 and frpsheet 2.0 and I'm a little confused and stuck.  I need to set the cell format and then read that later for a custom save.

I found cellFmt := wsGrid.Worksheet.ReadCellFormat(); but the param list shows a colon between them and the docs I found on copilot seem to indicate that it should be row, col, format.  With my version in mind can any one help me at all this is really got me stuck.  I just don't understand the params there at all.  Or perhaps I'm going about that entirely the wrong way.  Again, I need to set the format, at least the font, size, bold, italic and underline and then I need to be able to read those at a later date.

Please help :)

Thanks,

CJ

wp

  • Hero Member
  • *****
  • Posts: 13484
Re: Reading and setting cell format, stuck
« Reply #1 on: August 07, 2025, 10:34:53 am »
See attached mini project (needs package laz_fpspreadsheet in requirements).

but the param list shows a colon between them[...]
This is Pascal. The arguments of functions are always separated by semicolons in their declaration. But when the function is called, you must use a comma.


zxandris

  • Full Member
  • ***
  • Posts: 170
Re: Reading and setting cell format, stuck
« Reply #2 on: August 07, 2025, 11:13:02 am »
See attached mini project (needs package laz_fpspreadsheet in requirements).

but the param list shows a colon between them[...]
This is Pascal. The arguments of functions are always separated by semicolons in their declaration. But when the function is called, you must use a comma.

Okay I think i see what's going on there but how to I retrieve a cell to put into the variable rather than having to write it.  I did look at the param list on my grid but nothing leapt out at me.  Bear in mind I'm doing this visually and I want to offer buttons that add/remove formatting.

If you'd help a poor confused soul I would be grateful :)

CJ

wp

  • Hero Member
  • *****
  • Posts: 13484
Re: Reading and setting cell format, stuck
« Reply #3 on: August 07, 2025, 11:53:39 am »
Sorry there is not enough information so that I don't understand what you mean.

how to I retrieve a cell to put into the variable rather than having to write it.
Maybe this:
Code: Pascal  [Select][+][-]
  1. var
  2.   cell: PCell;
  3. ...
  4.   cell := worksheet.Findcell(row, column);  // Finds a cell, returns nil when there is no cell at row/column
  5.  

I did look at the param list on my grid [...]
Grid? Which kind of grid? A TStringGrid or a TsWorksheetGrid? In the latter there are lots of properties to access cell formatting, e.g.
Code: Pascal  [Select][+][-]
  1.   sWorksheetGrid.CellFontName[col, row] := 'Arial';  
  2.   // Note that in the grid column and row indices are exchanged compared to the worksheet.
  3.   // And indices begin at 1 (but at 0 in the worksheet)

I want to offer buttons that add/remove formatting.
When you use the fpspreadsheet visual controls then the easiest way to do this is by adding FPSpreadsheet actions to an actionList and/or adding TsCellComboboxes to the form. See https://wiki.lazarus.freepascal.org/FPSpreadsheet_tutorial:_Writing_a_mini_spreadsheet_application#Formatting_of_cells,
« Last Edit: August 07, 2025, 02:18:51 pm by wp »

zxandris

  • Full Member
  • ***
  • Posts: 170
Re: Reading and setting cell format, stuck
« Reply #4 on: August 07, 2025, 01:27:40 pm »
I would imagine it's
Code: Pascal  [Select][+][-]
  1. cell := worksheet.Findcell(row, column);

I will try that soon.  In short and it's a little odd.  I'm working with a very limited file format, and can't just attach a sheet file format into the file.  That doesn't work unfortunately.  So I'm essentially saving content myself which works and I can save the col and row sizes fine.  But I'm having issues with saving the formating.  Or even setting it.  Now I think with your help I can set it okay and read it but I will get back to you on that :).

It's a little odd and VERY slow and may well be a pipe dream.  I'm not joking how limited the file format is and I'm now regretting the decision to stick to the original format with this project.  But I'm stuck with it now and when I say limited I mean it's basically a compressed ini file, so yeah...that bad and that slow.

But it means that I'm doing this from scratch, and its a visual application.  So I need to personally read/write the format on a cell, and I don't THINK I can just use the actions.  Though I will give that a go, but will still need to read the cell format.  I'm using a TsWorksheet grid, not a drawgrid, and version 2...I think in lazarus 2.2.6 which I am aware is rather old now.  But upgrading isn't possible at current. (Hopefully soon).

So you can see this is perhaps more complicated than it could be but right now I am stuck with my limitations.

Thanks for all the help so far, I feel like we're getting there!

CJ

 

TinyPortal © 2005-2018