Page 1 of 1
64 Bits
Posted: Mon Nov 24, 2014 2:19 pm
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
Very strange
Any help appreciated
Eric
Re: 64 Bits
Posted: Wed Nov 26, 2014 8:48 am
by larsa
Hello
Don't use Range. It's obsolete. Use CmdFormat instead. See FormatCells sample for more details.
Re: 64 Bits
Posted: Thu Nov 27, 2014 3:56 pm
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
Re: 64 Bits
Posted: Fri Nov 28, 2014 11:05 am
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.
Re: 64 Bits
Posted: Fri Nov 28, 2014 11:12 am
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
Re: 64 Bits
Posted: Fri Nov 28, 2014 11:15 am
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
Re: 64 Bits
Posted: Fri Nov 28, 2014 11:49 am
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
Re: 64 Bits
Posted: Fri Nov 28, 2014 12:13 pm
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