private static string CopyRowsToNewWorkSheet(Worksheet sourceWs, int startRow, int endRow, string sheetName) { sheetName = XlHlp.SafeSheetName(sheetName); Worksheet destinationWS = XlHlp.NewWorksheet(sheetName, afterSheetName: "LAST"); XlHlp.XlLocation insertAt = new XlHlp.XlLocation(destinationWS, row: 5, column: 1); insertAt.MarkStart(XlHlp.MarkType.GroupTable); CreateLogWorkSheetHeader(insertAt); insertAt.AddRowX(); // HACK(crhodes) // // There are 14 columns normally, grab five more just in case // We can do better than this by finding the last active column. // Extra columns can appear when an exception messes up the formatting of the log file. Range sourceRng; sourceRng = sourceWs.Range[sourceWs.Cells[startRow, 1], sourceWs.Cells[endRow, 19]]; //.Cells[startRow, 1]; sourceRng.Copy(); insertAt.GetCurrentRange().PasteSpecial(); destinationWS.Activate(); // Things come over messed up. Unfreeze //Globals.ThisAddIn.Application.ActiveWindow.FreezePanes = false; Range rng; rng = destinationWS.Cells[5, 1]; Int32 lastRow = rng.SpecialCells(XlCellType.xlCellTypeLastCell).Row; Int32 lastColumn = rng.SpecialCells(XlCellType.xlCellTypeLastCell).Column; XlHlp.DisplayInWatchWindow(string.Format("{0}() row:({1}) col:({2})", MethodBase.GetCurrentMethod().Name, lastRow, lastColumn)); insertAt.SetRow(lastRow + 1); insertAt.SetColumn(lastColumn); insertAt.MarkEnd(VNC.AddinHelper.Excel.MarkType.GroupTable, string.Format("tbl_{0}", destinationWS.Name)); //rng = destinationWS.Columns["E:K"]; //rng.Columns.Group(); destinationWS.Columns["E:K"].Columns.Group(); //destinationWS.Cells[6, 14].Select(); //destinationWS.Application.ActiveWindow.FreezePanes = true; // TODO(crhodes) // Figure out what to do to make outlining work. //sourceWs.Outline.SummaryColumn = XlSummaryColumn.xlSummaryOnLeft; //sourceWs.Outline.SummaryRow = XlSummaryRow.xlSummaryAbove; return(sheetName); }