Import Sheets from another Excelfile

Questions and answers on how to use XLSReadWriteII 3/4/5.
Post Reply
braune
Posts: 12
Joined: Tue Feb 01, 2005 3:21 pm

Import Sheets from another Excelfile

Post by braune »

Hello,

all the Excelfiles creates with XLSReadWriteII4 and i can read this files but i can't copy the Sheets from extern file.

Please help me...

function XLSReport_multi(Reports: TStrings): boolean;
var
i : integer;
XLSFrom : TXLSReadWriteII4;
XLSTo : TXLSReadWriteII4;
begin
Result := false;
try
XLSTo := TXLSReadWriteII4.Create(nil);
XLSFrom := TXLSReadWriteII4.Create(nil);
with XLSTo do try
Clear;
Version := xvExcel97;
FileName := 'c:\test.xls';
for i:=0 to Reports.Count-1 do begin
with Sheets.Add do begin
XLSFrom.Clear;
XLSFrom.Filename := Reports[i];
XLSFrom.Read;
// Here copy the first Sheet to created Sheet
....
end;
end;
Write;
Result := true;
finally
XLSFrom.Free;
free;
end;
except
On E: Exception do MessageBox(E.Messages);
end;
end;

BBCode only OFF???

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

Re: Import Sheets from another Excelfile

Post by larsa »

Hello

There is no method for copying sheets from external files.
Lars Arvidsson, Axolot Data
braune
Posts: 12
Joined: Tue Feb 01, 2005 3:21 pm

Re: Import Sheets from another Excelfile

Post by braune »

Hello,

you wrote me 2006:

[quote]
... This will be added to a future upgrade ... and ...
The feature to copy sheets between components is on the to do list, but I can't tell when it will be ready.
[/quote]

... and now 2012 you wrote:

[quote]
There is no method for copying sheets from external files.
[/quote]

This is very unsatisfactory. I thought in version 4 works.

How can I copy the data without method?

Please help me urgently ...

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

Re: Import Sheets from another Excelfile

Post by larsa »

Hello

You can copy sheets cell by cell, something like this (untested):

for R := SrcSheet.FirstRow to SrcSheet.LastRow do begin
for C := SrcSheet.FirstCol to SrcSheet.LastCol do begin
DestSheet.AsVariant[C,R] := SrcSheet.AsVariant[C,R];
end;
end;
Lars Arvidsson, Axolot Data
braune
Posts: 12
Joined: Tue Feb 01, 2005 3:21 pm

Re: Import Sheets from another Excelfile

Post by braune »

Hello,

Fine, this works.

But i need all data on the sheet - Formats, Charts, Printing Range an so on ...

Over OLE i do this:

[code]
function XLSReport_multi(Reports: TStrings; aToFile: string): boolean;
var
Excel : OleVariant;
CopyBook : OleVariant;
CopySheet : OleVariant;
WorkBook : OleVariant;
WorkSheet : OleVariant;
i : integer;
begin
Result := false;
try
if (Reports.Count>0) then begin
try
Excel := CreateOLEObject('Excel.Application');
Excel.Application.DisplayAlerts := False;
for i:=0 to Reports.Count-1 do begin
CopyBook := Excel.WorkBooks.Open(Reports[i]);
CopySheet := CopyBook.Sheets[1];
if (i=0) then begin
WorkBook := Excel.WorkBooks.Add;
WorkSheet := WorkBook.Sheets[1];
while (WorkBook.WorkSheets.Count>1) do
WorkBook.Sheets[WorkBook.WorkSheets.Count].Delete;
end;
CopySheet.Copy(WorkSheet);
CopyBook.Close;
end;
WorkBook.Sheets[WorkBook.WorkSheets.Count].Delete;
WorkBook.Sheets[1].Activate;
WorkBook.SaveAs(aToFile);
Result := true;
finally
Excel.Application.Quit;
Excel.Quit;
CopyBook := UnAssigned;
CopySheet := UnAssigned;
WorkBook := UnAssigned;
WorkSheet := UnAssigned;
end;
end;
except
ON E: Exception do DoErrMsg(E);
end;
end;
[/code]


Uwe Braune
braune
Posts: 12
Joined: Tue Feb 01, 2005 3:21 pm

Re: Import Sheets from another Excelfile

Post by braune »

... but I do not want to use OLE I bought XLSReadWriteII :P

Please help me

Uwe Braune
braune
Posts: 12
Joined: Tue Feb 01, 2005 3:21 pm

Re: Import Sheets from another Excelfile

Post by braune »

... no response?
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: Import Sheets from another Excelfile

Post by larsa »

Hello

Sorry, but this is not possible, and there is no easy fix for this.
Lars Arvidsson, Axolot Data
braune
Posts: 12
Joined: Tue Feb 01, 2005 3:21 pm

Re: Import Sheets from another Excelfile

Post by braune »

Hello,

oh no! :cry: Is there no way over a stream (XLSStream) or step by step.
... or can i hope in the next version gives a copysheet function?
braune
Posts: 12
Joined: Tue Feb 01, 2005 3:21 pm

Re: Import Sheets from another Excelfile

Post by braune »

:cry: no response???
braune
Posts: 12
Joined: Tue Feb 01, 2005 3:21 pm

Re: Import Sheets from another Excelfile

Post by braune »

Hello,
just wanted to ask again as the state of "Import Sheets from external Excelfile" is.
Post Reply