Forum > FPSpreadsheet

Invalid font index error

(1/1)

Bert_Plitt:
I want to add the ability to change the font of a selected cell or group of cells using a Font Dialog Box in a spreadsheet project I am working on.  As practice, I tried doing this with one of the demo projects in fpspreadsheet-1.10.1, but keep getting an error when I try to change the font.

To test my method, I opened project demo_ctrls.lpi contained in ...\fpspreadsheet-1.10.1\examples\visual\fpsctrls.  I added sFontDialogAction1 to ActionList1 and a glyph for the action to ImageList1.  I assigned the action's WorkbookSource property to sWorkbookSource1.  I added a ToolButton (ToolButton4) to ToolBar1 and assigned its Action property to sFontDialogAction1 in the properties window.  All other properties of all added items were left at their default values. 

The project compiles and runs OK.  But when I try to change the font using the new ToolButton, I get the error message "Invalid font index.  Press OK to ignore and risk data corruption.  Press Abort to kill the program."  What am I doing wrong?  I must be missing something.  Any help would be appreciated.

wp:
You should probably post the project here. Pack the .pas, .lfm, .lpi, .lpr files to a common zip which you can upload here (--> "Attachments and other options"). If required add the spreadsheet file too.

Bert_Plitt:
OK, here's the files.

wp:
A left-over from the mysterious Font #4 which does not exist in the old Excel files...

Please open fpspreadsheet.pas, find the implementation of procedure TsWorksheet.WriteFont and remove the "or (AFontIndex = 4)". The correct method should be like this:


--- 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 TsWorksheet.WriteFont(ACell: PCell; AFontIndex: Integer);var  fmt: TsCellFormat;begin  if ACell = nil then    exit;   if (AFontIndex < 0) or (AFontIndex >= Workbook.GetFontCount) then     raise EFPSpreadsheet.Create(rsInvalidFontIndex);   fmt := Workbook.GetCellFormat(ACell^.FormatIndex);  Include(fmt.UsedFormattingFields, uffFont);  fmt.FontIndex := AFontIndex;  ACell^.FormatIndex := Workbook.AddCellFormat(fmt);   ChangedFont(ACell^.Row, ACell^.Col);end;  
Recompile the package laz_fpspreadsheet.lpk, and the bug should be gone.

Bert_Plitt:
Yes, the bug is gone!  Thanks.

Navigation

[0] Message Index

Go to full version