In FlexCel 3, to draw a border over a range of cells, you need to manually set the format of every cell to the corresponding border. While in FlexCel 5 there is a simpler way, drawing a border isn't too complex in v3 either.
procedure DrawBorder(fi: TFlexCelImport; r1, c1, r2, c2: integer; color: TColor);
var
fmt: TFlxFormat;
r, c: integer;
begin
//Top left corner
fi.GetCellFormatDef(r1 , c1, fmt);
fmt.Borders.Left.Style := fbs_Thin;
fmt.Borders.Left.ColorIndex := fi.NearestColorIndex(color);
fmt.Borders.Top.Style := fbs_Thin;
fmt.Borders.Top.ColorIndex := fi.NearestColorIndex(color);
fi.CellFormat[r1, c1] := fi.AddFormat(fmt);
//Top right corner
fi.GetCellFormatDef(r1 , c2, fmt);
fmt.Borders.Right.Style := fbs_Thin;
fmt.Borders.Right.ColorIndex := fi.NearestColorIndex(color);
fmt.Borders.Top.Style := fbs_Thin;
fmt.Borders.Top.ColorIndex := fi.NearestColorIndex(color);
fi.CellFormat[r1, c2] := fi.AddFormat(fmt);
//Bottom left corner
fi.GetCellFormatDef(r2 , c1, fmt);
fmt.Borders.Left.Style := fbs_Thin;
fmt.Borders.Left.ColorIndex := fi.NearestColorIndex(color);
fmt.Borders.Bottom.Style := fbs_Thin;
fmt.Borders.Bottom.ColorIndex := fi.NearestColorIndex(color);
fi.CellFormat[r2, c1] := fi.AddFormat(fmt);
//Bottom right corner
fi.GetCellFormatDef(r2 , c2, fmt);
fmt.Borders.Right.Style := fbs_Thin;
fmt.Borders.Right.ColorIndex := fi.NearestColorIndex(color);
fmt.Borders.Bottom.Style := fbs_Thin;
fmt.Borders.Bottom.ColorIndex := fi.NearestColorIndex(color);
fi.CellFormat[r2, c2] := fi.AddFormat(fmt);
//left and right lines
for r := r1 + 1 to r2 - 1 do
begin
fi.GetCellFormatDef(r , c1, fmt);
fmt.Borders.Left.Style := fbs_Thin;
fmt.Borders.Left.ColorIndex := fi.NearestColorIndex(color);
fi.CellFormat[r, c1] := fi.AddFormat(fmt);
fi.GetCellFormatDef(r , c2, fmt);
fmt.Borders.Right.Style := fbs_Thin;
fmt.Borders.Right.ColorIndex := fi.NearestColorIndex(color);
fi.CellFormat[r, c2] := fi.AddFormat(fmt);
end;
//top and bottom lines
for c := c1 + 1 to c2 - 1 do
begin
fi.GetCellFormatDef(r1 , c, fmt);
fmt.Borders.Top.Style := fbs_Thin;
fmt.Borders.Top.ColorIndex := fi.NearestColorIndex(color);
fi.CellFormat[r1, c] := fi.AddFormat(fmt);
fi.GetCellFormatDef(r2 , c, fmt);
fmt.Borders.Bottom.Style := fbs_Thin;
fmt.Borders.Bottom.ColorIndex := fi.NearestColorIndex(color);
fi.CellFormat[r2, c] := fi.AddFormat(fmt);
end;
end;
And call it like this:
procedure TForm35.FormCreate(Sender: TObject);
begin
FlexCelImport1.NewFile(1);
DrawBorder(FlexCelImport1, 1, 1, 5, 6, clBlack);
FlexCelImport1.Save('r:\test.xls');
end;
I am not 100% sure I understood the question, if what you wanted was to merge cells instead, then you can use:
or similar.
But if it is for formatting (borders, cell backgrounds, etc), just get the cell format with FlexCelImport.GetCellFormatDef, modify the format, and set the cell format again (as in my example above).
If I understood wrong the question, please explain me a little more what you want to do, it is most likely you will be able to do it with FlexCel 3.
Adrian.