I think you have to show more code:
What is "fGetTextBold"?
What is "SL"? A stringlist?
What is the "SLCount" good for? The count of items in the string list? You cannot add items to a stringlist by incrementing a count variable, only by calling "Add" or "Insert" of the "items" of the stringlist.
The project below which is essentially your code runs without issues:
program Project1;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes, laz_fpspreadsheet, fpstypes, fpspreadsheet, xlsbiff8;
var
workbook: TsWorkbook;
worksheet: TsWorksheet;
rownum: Integer;
strText: String;
begin
workbook := TsWorkbook.Create;
try
worksheet := workbook.AddWorksheet('test');
rownum := 2;
worksheet.MergeCells(rowNum,0,rowNum,4);
worksheet.WriteFontStyle(rowNum,1,[fssBold]);
//strText:= fGetTextBold(SL[c]);
strText := 'abc';
worksheet.WriteUTF8Text(rowNum,0,strText);
workbook.WriteToFile('test.xls', sfExcel8, true);
finally
workbook.Free;
end;
end.
Since you are using merged cell ranges I should note that only the top/left cell of a merged range can accept data and formats, the other cells of the range are ignored. Assuming for simplicity that your rownum is 0 then you merge the cells A1:E1. You write the strText into cell A1 - this is fine because this is the top-left cell. But in the commented part you write a format (bold font) to cell B1 - this is a cell within the merged range. The format will be neglected because the cell is not the top/left cell of the range. In order to set the entire merged range to bold you have to write the fontstyle to cell A1.
But this does not cause an out-of-bounds error. Assuming that SL is a stringlist I'd guess that "c" is too large, it must be less than the count of the stringlist items.
Learn how to use the debugger, how to set breakpoints and how to query the value of variables.