title: Copy value and format from a sheet to a new google Spreadsheet document?
body: <p>I need to copy a sheet on google SpreadSheet to another SpreadSheet document.</p>
  
  <p>I´ve done my research, and I found two methods that do this, however both have problems that I don´t know how to fix.</p>
  
  <p>The first method copies the sheet with format, but it keeps the referenced cells, so I get a reference error in the new document (#ref). I need a function that copies the format and the values (not references). </p>
  
  <pre><code>function copySheet() {
     var source = SpreadsheetApp.getActiveSpreadsheet();
     var sheet = source.getSheets()[0];
     var destination = SpreadsheetApp.openById("15ucPbZrIYXZAOCYVdpK6OA0oyQT1NcsmuiJmDRfdpHQ");
  
     sheet.copyTo(destination);
  }
  </code></pre>
  
  <p>This second method copies the values without references, however it copies only values, without format. </p>
  
  <pre><code>function copySheetValues()
  {
    var source = SpreadsheetApp.getActiveSheet();
    var sourcename = source.getSheetName();
    var sourceDataRange = source.getDataRange();
    var sourceSheetValues = sourceDataRange.getValues();
    var sourceRows = sourceDataRange.getNumRows();
    var sourceColumns = sourceDataRange.getNumColumns();
  
    var destination = SpreadsheetApp.openById('15ucPbZrIYXZAOCYVdpK6OA0oyQT1NcsmuiJmDRfdpHQ');
    destination.insertSheet(sourcename, 0);
    destination.getDataRange().offset(0, 0, sourceRows, sourceColumns).setValues(sourceSheetValues);
  
  }
  </code></pre>
  
  <p>How do I write a function that keeps the format and copies the values? </p>