Column formatting problem

Questions and answers on how to use XLSReadWriteII 5.
Post Reply
ykarapinar
Posts: 22
Joined: Fri May 17, 2013 7:59 am

Column formatting problem

Post 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;
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: Column formatting problem

Post by larsa »

Hello

Use CmdFormat instead. Example:

Code: Select all

XLS.CmdFormat.Border.Style := cbsThin;
XLS.CmdFormat.Border.Preset(cbspOutlineAndInside);
Lars Arvidsson, Axolot Data
Post Reply