Page 1 of 1

Column formatting problem

Posted: Thu Dec 10, 2015 10:31 am
by ykarapinar
The code below should format 4 columns. It works for the first 3 columns, but leaves the fourth column unformatted.

Code: Select all

var
  ct: Integer;
begin
  try
    XLSReadWriteII51.FileName:='C:\XLSReadWriteII.xlsx';

    XLSReadWriteII51.Sheets[0].Range.ItemsRef['A1:D10'].BorderInsideVertStyle  := cbsThin;
    XLSReadWriteII51.Sheets[0].Range.ItemsRef['A1:D10'].BorderInsideHorizStyle := cbsThin;
    XLSReadWriteII51.Sheets[0].Range.ItemsRef['A1:D10'].BorderOutlineStyle     := cbsThin;

    XLSReadWriteII51.CmdFormat.BeginEdit(XLSReadWriteII51[0]);
    XLSReadWriteII51.CmdFormat.Clear;
    XLSReadWriteII51.CmdFormat.Fill.BackgroundColor.RGB := clYellow;
    XLSReadWriteII51.CmdFormat.Font.Name := 'MS Sans Serif';
    XLSReadWriteII51.CmdFormat.Font.Size := 8;
    XLSReadWriteII51.CmdFormat.Number.Format:='@';
    XLSReadWriteII51.CmdFormat.Apply(0, 0, 3, 9);
    for ct:=0 to 9 do
    begin
      XLSReadWriteII51.Sheets[0].AsString[0, ct]:=IntToStr(ct);
      XLSReadWriteII51.Sheets[0].AsString[1, ct]:=IntToStr(ct);
      XLSReadWriteII51.Sheets[0].AsString[2, ct]:=IntToStr(ct);
      XLSReadWriteII51.Sheets[0].AsString[3, ct]:=IntToStr(ct);
    end;
  finally
    XLSReadWriteII51.Write;
  end;
end;

Re: Column formatting problem

Posted: Mon Dec 21, 2015 10:04 am
by larsa
Hello

Use CmdFormat instead. Example:

Code: Select all

XLS.CmdFormat.Border.Style := cbsThin;
XLS.CmdFormat.Border.Preset(cbspOutlineAndInside);