title: Can I specify a header row when sorting in a script?
body: <p>I have a spreadsheet that I'd like to sort by multiple columns many times as I work on the document. This is a multi-step process using the GUI, and seemed far too time-consuming. I have to check the box for a header row, set up the first sorting parameter, and then add another one. Phew! It gets old quick.</p>
  
  <p>Sorting the sheet was no problem, but the header row was also sorted! I don't find any way to specify that I have a header row as a parameter to the sort() function, nor do I see any way to globally define a header row that will be automatically noticed by sort().</p>
  
  <p>In lieu of that, I saved the header row, deleted the first row, sorted the sheet, inserted a new row at the very top, re-created the header row, and formatted the header row. Wow! It didn't take that long to write and it works well, but it's awfully complicated!</p>
  
  <p>From the user perspective, the header row briefly disappears before popping back up. It's not too bad, but it's plainly obvious something is going on.</p>
  
  <p>So finally I get around to my question: Have I overlooked the ability to acknowledge the presence of a header row when I'm sorting? Or does sorting a sheet with a header row present in a script also sort the header row, with no recourse?</p>
  
  <p>If my method, or one like it, is required to avoid including the header row in the sort process, is there somewhere that I can notify the Google Apps team so they can consider adding this feature? Since specifying the existence of a header row exists in the GUI with a simple checkbox, I hope it's present or can be added when sorting within a script.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>My original code (with documentation/comments removed):</p>
  
  <pre><code>sheet.deleteRow(1);
  
  rows.sort([&lt;1st col&gt;, &lt;2nd col&gt;]);
  
  sheet.insertRowsBefore(1, 1);
  for (var j = 0; j &lt;= (numCols - 1); j++) {
    sheet.getRange(1, (j + 1)).setValue(firstRow[j]);
  }
  
  sheet.getRange(1, 1, 1, numCols).setFontWeight("bold");
  sheet.getRange(1, 1, 2, numCols).setBorder(true, true, true, true, true, true);
  </code></pre>
  
  <p>What I've tried in place of the above code thanks for Thomas' suggestion:</p>
  
  <pre><code>sheet.setFrozenRows(1);
  sheet.sort(&lt;2nd col&gt;);
  sheet.sort(&lt;1st col&gt;);
  sheet.setFrozenRows(0);
  </code></pre>
  
  <p>Unfortunately, this just sorts by column, not by row. Replacing the 2 <code>sheet.sort();</code> calls with the <code>rows.short();</code> line in the first code block doesn't work. Trying this results in the initial problem I reported in my comment where the header row is sorted along with the other data, even though the first row is frozen before sorting.</p>
  
  <p>Also, unless another line of code is added below this I get a perpetual "Working..." notification at the top of the spreadsheet. It doesn't seem to affect anything, however.</p>
  
  <p>In all cases, <code>var sheet = SpreadsheetApp.getActiveSheet();</code>, <code>var rows = sheet.getDataRange();</code>, and <code>firstRow</code> is an array of the header row data.</p>