64 Bits

Questions and answers on how to use XLSReadWriteII 5.
Post Reply
etwoss
Posts: 12
Joined: Tue Jul 15, 2014 7:50 am

64 Bits

Post by etwoss »

Hi

This code works fine on 32 bits but results in an Index out of bounds when saving the file.

Code: Select all

    R := FSheet.Range.Items[FFirstColumn, FCurrentRow, FFirstColumn + FColumnCount - 1, FCurrentRow];
    R.FontColor := clWhite;
    R.FillPatternForeColor := RGB(128, 128, 128);  // Beware Excel used BGR
    R.FontStyle := [];
    R.BorderLeftStyle := cbsThin;
    R.BorderLeftColor := IndexColorToXc12(xcAutomatic).ARGB;
    R.BorderRightStyle := cbsThin;
    R.BorderRightColor := IndexColorToXc12(xcAutomatic).ARGB;
    R.BorderBottomStyle := cbsThin;
    R.BorderBottomColor := IndexColorToXc12(xcAutomatic).ARGB;
    R.BorderTopStyle := cbsThin;
    R.BorderTopColor := IndexColorToXc12(xcAutomatic).ARGB;

    if (Length(ATitles) > 1) then
    begin
      R.BorderInsideVertStyle := cbsThin;
      R.BorderInsideVertColor := IndexColorToXc12(xcAutomatic).ARGB;
    end;

I started commenting this code line by line
if i comment all the Border..Color properties and at least one of the BorderStyle properties the error on the save is gone :shock:
Very strange

Any help appreciated

Eric
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: 64 Bits

Post by larsa »

Hello

Don't use Range. It's obsolete. Use CmdFormat instead. See FormatCells sample for more details.
Lars Arvidsson, Axolot Data
etwoss
Posts: 12
Joined: Tue Jul 15, 2014 7:50 am

Re: 64 Bits

Post by etwoss »

Hi

Changed my code to

Code: Select all

procedure TExcelReportSheet.WriteHeader(const ATitles: array of String; const AApplyFormating: Boolean);
var
  i: Integer;
  j: Integer;
begin
  if (AApplyFormating) then
    Inc(FCurrentRow);

  FColumnCount := Length(ATitles);
  FHeaderRow := FCurrentRow;

  for i := Low(ATitles) to High(ATitles) do
    FSheet.AsString[FFirstColumn + i, FCurrentRow] := ATitles[i];

  if (AApplyFormating) then
  begin
    ExcelObject.CmdFormat.Mode := xcfmMerge;
    ExcelObject.CmdFormat.BeginEdit(ExcelObject[0]);
    ExcelObject.CmdFormat.Fill.BackgroundColor.RGB := RGB(128, 128, 128);
    ExcelObject.CmdFormat.Font.Color.RGB  :=  $FFFFFF;

    for j := Low(ATitles) to High(ATitles) do
    begin
      ExcelObject[0].Cell[FFirstColumn + j ,FCurrentRow].BorderLeftStyle   := cbsThin;
      ExcelObject[0].Cell[FFirstColumn + j ,FCurrentRow].BorderRightStyle  := cbsThin;
      ExcelObject[0].Cell[FFirstColumn + j ,FCurrentRow].BorderTopStyle    := cbsThin;
      ExcelObject[0].Cell[FFirstColumn + j ,FCurrentRow].BorderBottomStyle := cbsThin;

      ExcelObject[0].Cell[FFirstColumn + j ,FCurrentRow].BorderLeftColor   := xcBlack;
      ExcelObject[0].Cell[FFirstColumn + j ,FCurrentRow].BorderRightColor  := xcBlack;
      ExcelObject[0].Cell[FFirstColumn + j ,FCurrentRow].BorderTopColor    := xcBlack;
      ExcelObject[0].Cell[FFirstColumn + j ,FCurrentRow].BorderBottomColor := xcBlack;
    end;

    ExcelObject.CmdFormat.Apply(FFirstColumn, FCurrentRow, FFirstColumn + FColumnCount - 1, FCurrentRow);
  end;
  Inc(FCurrentRow);
end;
Still Index out of bounds when saving the file!

Also its not possible to recompile SampleFormatCells demo to 64 bits
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: 64 Bits

Post by larsa »

Hello

1. Please create samples that will compile.

2. If I replace the missing variables in your sample with my guesses, it works fine with 64-bit.

3. Follow the guidelines in FormatCells sample. That is, there is no point using CmdFormat if you assign values to the Cell object. Use CmdFormat.

4. The FormatCellsSample did not compile in 64-bit because of a wrong typecast on the line ShellExecute(...). Comment out that line.
Lars Arvidsson, Axolot Data
etwoss
Posts: 12
Joined: Tue Jul 15, 2014 7:50 am

Re: 64 Bits

Post by etwoss »

Hi

What do you mean with:

If I replace the missing variables in your sample with my guesses, it works fine with 64-bit.

Eric
etwoss
Posts: 12
Joined: Tue Jul 15, 2014 7:50 am

Re: 64 Bits

Post by etwoss »

Hi

When compiling SampleFormatCells

I get Undeclared Identifier ApplyCols

on XLS.CmdFormat.ApplyCols(1,5);

and

I get Undeclared Identifier ApplyRows

on XLS.CmdFormat.ApplyRows(1,5);


Eric
etwoss
Posts: 12
Joined: Tue Jul 15, 2014 7:50 am

Re: 64 Bits

Post by etwoss »

Hi

Hmm...

While making little demo i notice my problem is in the

ExcelObject[0].Cell[ part

Especially the [0]

I have a Simple demo working now.
What i need to know is with which value i need to replace my [0]

Eric
etwoss
Posts: 12
Joined: Tue Jul 15, 2014 7:50 am

Re: 64 Bits

Post by etwoss »

Hi

Found the problem :-)

Code: Select all

  if (AApplyFormating) then
  begin
    ExcelObject.CmdFormat.Mode := xcfmMerge;
    ExcelObject.CmdFormat.BeginEdit(ExcelObject[0]);
    ExcelObject.CmdFormat.Fill.BackgroundColor.RGB := RGB(128, 128, 128);
    ExcelObject.CmdFormat.Font.Color.RGB  :=  $FFFFFF;

    // Border color and style.
    ExcelObject.CmdFormat.Border.Color.RGB := $000000;
    ExcelObject.CmdFormat.Border.Style := cbsThin;
    // Set the border outline of the cells.
    ExcelObject.CmdFormat.Border.Preset(cbspOutline);

    // Border style of lines inside.
    ExcelObject.CmdFormat.Border.Style := cbsThin;
    ExcelObject.CmdFormat.Border.Preset(cbspInside);

    ExcelObject.CmdFormat.Apply(FFirstColumn, FCurrentRow, FFirstColumn + FColumnCount - 1, FCurrentRow);
  end;
Working!

Thanks!

Eric
Post Reply