title: Copy cells with format from an excel worksheet to another workbook worksheet in Delphi
body: <blockquote>
    <p>In a worksheet there is:</p>
  </blockquote>
  
  <p><img src="https://i.stack.imgur.com/Tz2tS.png" alt="This is a header"></p>
  
  <p>I want unmerge the B2:C2 cell and copy with its format to the other sheet (in another workbook) at A1, then the value (in C3) to the B1 cell of the other sheet, D2 to A2, E2 to B2 and so...
  How can I do?</p>
  
  <p><img src="https://i.stack.imgur.com/vdsPJ.png" alt="This is a detail"></p>
  
  <pre><code>procedure Something;
  const root = 'C:\vial\$$652791.xls';
       filename = 'C:\vial\abarajame.xls';
  var xlsH, xlsD: TExcelApplication;
      sheetH,sheetD: _Worksheet;
      DestRange: OleVariant;
      format: string;
  begin
      xlsH := TExcelApplication.Create(Self);
      xlsD := TExcelApplication.Create(Self);
      xlsH.Workbooks.Open(root, EmptyParam, EmptyParam, EmptyParam, EmptyParam,
      EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam,
      EmptyParam, EmptyParam, EmptyParam, EmptyParam, 0 );
      xlsD.Workbooks.Open(filename, EmptyParam, EmptyParam, EmptyParam, EmptyParam,
      EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam,
      EmptyParam, EmptyParam, EmptyParam, EmptyParam, 0 );
      sheetH := xlsH.Worksheets[1] as _Worksheet;
      sheetD := xlsD.Worksheets[1] as _Worksheet;
      //Insert 5 empty rows
      sheetD.Rows.Range['A1','A5'].EntireRow.Insert(xlShiftDown, Null);
      //1st. col.
      sheetH.Cells.Range['B2','I2'].MergeCells := False;
      DestRange := sheetH.Cells.Range['B2','I2'];
      format    := sheetH.Cells.Range['B2','I2'].NumberFormat;
      sheetD.Cells.Range['A1','A1'].Copy(DestRange);
      sheetD.Cells.Range['A1','A1'].NumberFormat := format;
      DestRange := sheetH.Range['C3','C3'];
      format    := sheetH.Range['C3','C3'].NumberFormat;
      sheetD.Range['A2','A2'].Copy(DestRange);
      sheetD.Range['A2','A2'].NumberFormat := format;
      //2nd. col.
      DestRange := xlsH.Range['D2','D2'];
      xlsD.Range['B1','B1'].Copy(DestRange);
      DestRange := xlsH.Range['C4','C4'];
      hojaD.Range['B2','B2'].Copy(DestRange);
      xlsd.SaveWorkspace;
      xlsH.Workbooks.Close(0);
      xlsD.Workbooks.Close(0);
      FreeAndNil(xlsH);
      FreeAndNil(xlsD);
  end;
  </code></pre>
  
  <p>I've tested with differents ways, Cells.Range, Range from Sheet,from Cells from ExcelApplication, but nothing does!!</p>
  
  <p>Result must be:</p>
  
  <p><img src="https://i.stack.imgur.com/RW5iM.png" alt="That I want to do"></p>