Oh, you are right. It looks as if ReadCellFontIndex was added after releasing fps1.6, and my description in above post was not quite correct: there is no WriteFontIndex method in trunk either, it is called WriteFont and exists already in 1.6.
There are two options for you:
- Switch to the trunk version of fpspreadsheet. This provides the missing method ReadFontIndex.
- Or, if you want to stay with 1.6 you could patch the fpspreadsheet.pas unit and add this code:
interface
...
type
TWorksheet = class
...
public
...
function ReadCellFontIndex(ACell: PCell): Integer;
end;
...
implementation
...
function TsWorksheet.ReadCellFontIndex(ACell: PCell): Integer;
var
fmt: PsCellFormat;
begin
Result := DEFAULT_FONTINDEX;
if ACell <> nil then
begin
fmt := Workbook.GetPointerToCellFormat(ACell^.FormatIndex);
Result := fmt^.FontIndex;
end;
end;
...
Note that - in order to reduce the number of overloaded methods - I decided to implement ReadCellFont only as a variant which gets a pointer to the cell as a parameter, not row/column as in other cases. Therefore, you must search the cell first if you only know its row and column indexes:
var
font_index: Integer;
begin
font_index := Worksheet.ReadCellFontIndex(Worksheet.Findcell(ARow, ACol));
...
or, if you want to extract some more information from the same cell and maybe write to it again, it is advisable to store the pointer to the cell and used it in the subsequent methods:
var
cell: PCell;
font_index: Integer;
borders: TsCellBorders;
begin
cell := Worksheet.Findcell(ARow, ACol);
if cell <> nil then
begin
font_index := Worksheet.ReadCellFontIndex(cell);
borders := Worksheet.ReadCellBorders(cell);
end else
begin
font_index := -1;
borders := [];
end;
...
Instead of FindCell you can also use GetFont. This has the
disadvantage that a new empty cell is created if there is no cell at the queried location, and it has the
advantage that the check for nil is not required for this reason.
One comment on your code, probably you know this, but just in case you don't: Row and column indexes in fpspreadsheet always begin at 0, the fixed cells knows from a TStringGrid are not considered. I mention this because you begin the i loops (row index) always at index 1 (probably intentionally).