Link to home
Start Free TrialLog in
Avatar of SecureMeters
SecureMetersFlag for India

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?
Avatar of Bongos
Bongos

Can you show the code you're using to perfom the sheet copy?
Avatar of SecureMeters

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(fileLocationSource,EmptyParam,EmptyParam,EmptyParam
                        ,EmptyParam,EmptyParam,EmptyParam,EmptyParam
                        ,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,0);
 wbSource := (exlapp.ActiveWorkbook);
 wbDestination := Exlapp.Workbooks.add(Null,0);
 wbDestination := (exlapp.ActiveWorkbook);
 FileAvail:=FileExists(fileLocationDestination);
 if not FileExists(fileLocationDestination) then
 begin
  wbDestination.SaveAs(fileLocationDestination,EmptyParam,EmptyParam,EmptyParam,
                      EmptyParam,EmptyParam,0,
                      EmptyParam,EmptyParam,EmptyParam,
                      EmptyParam,0);

 end;
 Exlapp.Workbooks.Open(fileLocationDestination,EmptyParam,EmptyParam,EmptyParam
                        ,EmptyParam,EmptyParam,EmptyParam,EmptyParam
                        ,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,0);
 wbDestination := (exlapp.ActiveWorkbook);
 wbSource.Worksheets.Copy(null,wbDestination.Worksheets[wbDestination.Worksheets.count],0);
  if not FileAvail then
  begin
   Sheets := Exlapp.Sheets;
   while Sheets.count<>1 do
    Sheets.item[1].delete;
  end;
  OleVariant(Exlapp.ActiveWorkbook.Worksheets[1]).Name :='aaa';
  wbDestination.Save(0);
  wbDestination.Close(emptyparam,emptyparam,emptyparam,0);
  wbsource.Close(emptyparam,emptyparam,emptyparam,0);

finally
  exlapp.Free;
 end;
end;
ASKER CERTIFIED SOLUTION
Avatar of Bongos
Bongos

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial