Would the following work? Create a second worksheet. Set up your template cells in that spreadsheet. Then use NeedCellData to populate the first worksheet?
And maybe delete the second worksheet after all the NeedCellData stuff is finished? Dunno, just an idea...
Haha... I just figured it out...
It's a bit counter-intuitive but if you use WriteFontStyle for cell 0,0 etc.... you create the template cells.
After that you're using NeedCellData to actually populate these cell's and the data (and styles in it)
will be deleted and replaced with the actually data and link to the style-index.
(It wasn't clear to me you used the sheet at first for creating the templates after which these will be destroyed and replaced.)
I'm not saying the building of the templates should be done during population (in NeedCellData) but i still think the building of the styles
could be done virtually (without using the worksheet) but that would mean rewriting the gathering of the styles (not from the sheet but from memory) and i'm not sure if that would mess up the other formats.
But the way you did it now
works good too. (It's just some getting used to using the first cells of the sheet when these will be thrown away)
There could even be a small object written which does all this work for you (without you needing to mess with the sheet yourself).
It could use the first row of the sheet and populating it with the styles you want.
It could use template-names for easy access.
MyTemplates := TTemplateCells.Create;
MyTemplates.WriteFontStyle('just_bold', [fssBold]);
MyTemplates.WriteFontStyle('bold_and_gray', [fssBold]);
MyTemplates.WriteBackground('bold_and_gray', scGray);
MyTemplates.WriteFontStyle('negative', [fssBold]);
MyTemplates.WriteBackground('negative', scRed);
MyTemplates.PopulateTemplateCells; // <- this will populate an internal PCell structure
and in NeedCellData
...
AData := myValue
if ARow = 0 then AStyle := MyTemplates.GetTemplate('just_bold');
if myvalue < 0 then AStyle := MyTemplates.GetTemplate('negative');
...
Internally in that object the WriteFontStyle would look up 'just_bold' in it's own index (TStringList) to see which row/column and set the style in the worksheet there.
Just a thought for someone (maybe me) to create later, because that would stand apart from fpspreadsheet itself.
(It would just be a small helper-object)