SecureMeters
asked on
Excel Sheet color
i have to copy the excel sheet from one excel work book to another workbook at run time using the delphi code.
source excel sheet is formated with some colors
i have done it sucessfully.
but when i newly created work sheet entire work sheet is painted with Green color
can some body give me idea how to retain the same color format in the new work sheet?
source excel sheet is formated with some colors
i have done it sucessfully.
but when i newly created work sheet entire work sheet is painted with Green color
can some body give me idea how to retain the same color format in the new work sheet?
Can you show the code you're using to perfom the sheet copy?
ASKER
procedure TForm1.Button8Click(Sender : TObject);
var
wbSource : _WorkBook;
wbDestination: _WorkBook;
fileLocationSource : String;
fileLocationDestination : String;
FileAvail:boolean;
Sheets: Variant;
begin
try
Exlapp:=TExcelApplication. Create(nil );
OpenDialog1.Execute;
fileLocationSource := OpenDialog1.FileName;
fileLocationDestination := 'D:\111.xls';
exlapp.Visible[0]:=true;
//opening both the source and the destination workbooks
Exlapp.Workbooks.Open(file LocationSo urce,Empty Param,Empt yParam,Emp tyParam
,EmptyParam,EmptyParam,Emp tyParam,Em ptyParam
,EmptyParam,EmptyParam,Emp tyParam,Em ptyParam,E mptyParam, 0);
wbSource := (exlapp.ActiveWorkbook);
wbDestination := Exlapp.Workbooks.add(Null, 0);
wbDestination := (exlapp.ActiveWorkbook);
FileAvail:=FileExists(file LocationDe stination) ;
if not FileExists(fileLocationDes tination) then
begin
wbDestination.SaveAs(fileL ocationDes tination,E mptyParam, EmptyParam ,EmptyPara m,
EmptyParam,EmptyParam,0,
EmptyParam,EmptyParam,Empt yParam,
EmptyParam,0);
end;
Exlapp.Workbooks.Open(file LocationDe stination, EmptyParam ,EmptyPara m,EmptyPar am
,EmptyParam,EmptyParam,Emp tyParam,Em ptyParam
,EmptyParam,EmptyParam,Emp tyParam,Em ptyParam,E mptyParam, 0);
wbDestination := (exlapp.ActiveWorkbook);
wbSource.Worksheets.Copy(n ull,wbDest ination.Wo rksheets[w bDestinati on.Workshe ets.count] ,0);
if not FileAvail then
begin
Sheets := Exlapp.Sheets;
while Sheets.count<>1 do
Sheets.item[1].delete;
end;
OleVariant(Exlapp.ActiveWo rkbook.Wor ksheets[1] ).Name :='aaa';
wbDestination.Save(0);
wbDestination.Close(emptyp aram,empty param,empt yparam,0);
wbsource.Close(emptyparam, emptyparam ,emptypara m,0);
finally
exlapp.Free;
end;
end;
var
wbSource : _WorkBook;
wbDestination: _WorkBook;
fileLocationSource : String;
fileLocationDestination : String;
FileAvail:boolean;
Sheets: Variant;
begin
try
Exlapp:=TExcelApplication.
OpenDialog1.Execute;
fileLocationSource := OpenDialog1.FileName;
fileLocationDestination := 'D:\111.xls';
exlapp.Visible[0]:=true;
//opening both the source and the destination workbooks
Exlapp.Workbooks.Open(file
,EmptyParam,EmptyParam,Emp
,EmptyParam,EmptyParam,Emp
wbSource := (exlapp.ActiveWorkbook);
wbDestination := Exlapp.Workbooks.add(Null,
wbDestination := (exlapp.ActiveWorkbook);
FileAvail:=FileExists(file
if not FileExists(fileLocationDes
begin
wbDestination.SaveAs(fileL
EmptyParam,EmptyParam,0,
EmptyParam,EmptyParam,Empt
EmptyParam,0);
end;
Exlapp.Workbooks.Open(file
,EmptyParam,EmptyParam,Emp
,EmptyParam,EmptyParam,Emp
wbDestination := (exlapp.ActiveWorkbook);
wbSource.Worksheets.Copy(n
if not FileAvail then
begin
Sheets := Exlapp.Sheets;
while Sheets.count<>1 do
Sheets.item[1].delete;
end;
OleVariant(Exlapp.ActiveWo
wbDestination.Save(0);
wbDestination.Close(emptyp
wbsource.Close(emptyparam,
finally
exlapp.Free;
end;
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.