Copy & paste whole excel lines

Hello,


I would need to copy from one excel file one row (to many rows) at once to another excel-file. What would be the best to do?

Sincerely

Peter
Peter,
The method you are looking for is InsertAndCopyRange. FlexCel has 5 basic manipulation methods:
InsertAndCopyRange
MoveRange
DeleteRange
InsertAndCopySheet
DeleteSheet

And if you are going to remember just one of those, make sure it is InsertAndCopyRange.It has tons of options, and it allows you to insert, copy or insertandcopy a range of cells, a number of rows or columns, from one place to another in the same sheet, in a different sheet, or in a different file.

Here is an example to copy from row 2 in the source to rows 5, 6 and 7 in the target file:


program Project11;


{$APPTYPE CONSOLE}


{$R *.res}


uses
  System.SysUtils, VCL.FlexCel.Core, FlexCel.XlsAdapter;


const
  rowToCopy = 2;
  destRow = 5;
  destCount = 3;
var
  XlsIn, XlsOut: TXlsFile;
begin
  XlsIn := TXlsFile.Create('r:\test.xlsx');
  try
    XlsOut := TXlsFile.Create(1, TExcelFileFormat.v2013, true);
    XlsOut.InsertAndCopyRange(TXlsCellRange.Create(rowToCopy, 1, rowToCopy, 1),
      destRow, 1, destCount,
      TFlxInsertMode.ShiftRowDown, TRangeCopyMode.All, XlsIn, XlsIn.ActiveSheet);


    XlsOut.Save('r:\restult.xlsx');
  finally
    XlsIn.Free;
  end;
end.