Exception with MoveCells

Questions and answers on how to use XLSReadWriteII 3/4/5.
Post Reply
Lothar
Posts: 3
Joined: Wed May 28, 2008 8:59 am

Exception with MoveCells

Post by Lothar »

Hello,

I get always exceptions "access violation" when I use MoveCells. Here a simple excample:

procedure TForm1.btn_MoveClick(Sender: TObject);
var
intC,intR : integer;
XLS: TXLSReadWriteII4;
begin
XLS := TXLSReadWriteII4.Create(Self);
XLS.Filename := 'Move1.xls';
for intC := 0 to 20 do
begin
XLS.Sheet[0].AsString[intC, 0] := 'Text '+IntToStr(intC);
XLS.Sheet[0].AsFloat[intC, 3] := 100+intC;
end;
XLS.MoveCells(0,0,3,10,4,0,0,6,CopyAllCells);
XLS.Write;
XLS.Free;
end;

I just want to move row 3 and 4 to row 6 as an excample. (But not the whole row)

I use ComponentVersion 4.00.00, Delphi 6 or 2007

Thank you
Lothar
Lothar
Posts: 3
Joined: Wed May 28, 2008 8:59 am

Solution

Post by Lothar »

I found the solution myself:

I just searched further for this problem, and I found - Longword(Row1 + DestRow));

That means, that the sign gets turned for the DestRow, and indeed, when I call the procedure with row -6 then it works !



So corrected would be:

TCell(Cells).SetPos(TCell(Cells).Col - Col1 + DestCol,TCell(Cells).Row - Longword(Row1) + Longword(DestRow));

procedure TXLSReadWriteII4.MoveCells(SrcSheet, Col1, Row1, Col2, Row2, DestSheet, DestCol, DestRow: integer; CopyOptions: TCopyCellsOptions);

………

………

for i := 0 to Cells.Count - 1 do begin

TCell(Cells).SetPos(TCell(Cells).Col - Col1 + DestCol,TCell(Cells).Row - Longword(Row1 + DestRow));

FSheets[DestSheet]._Int_Cells.CellsNotChangeFmt[TCell(Cells).Col,TCell(Cells).Row] := Cells;

if (ccoAdjustCells in CopyOptions) and (FSheets[DestSheet]._Int_Cells[TCell(Cells).Col,TCell(Cells[i]).Row] is TFormulaCell) then begin

if TFormulaCell(Cells[i]).IsEx12 then

FFormulaHandler.EncodeEx12(DestSheet,TCell(Cells[i]).Col,TCell(Cells[i]).Row);

AdjustCell(FVersion = xvExcel97,TFormulaCell(Cells[i]).PTGS,TFormulaCell(Cells[i]).FormulaSize,DestCol - Col1,DestRow - Row1,ccoLockStartRow in CopyOptions,ccoForceAdjust in CopyOptions);

end;

end;
Post Reply