TryCreateStackedTable ( Microsoft.Office.Interop.Excel.Workbook oWorkbook, String sWorksheetName, GraphMetricColumn oGraphMetricColumn, out ListObject oStackedTable ) { Debug.Assert(oWorkbook != null); Debug.Assert(!String.IsNullOrEmpty(sWorksheetName)); Debug.Assert(oGraphMetricColumn != null); AssertValid(); oStackedTable = null; Worksheet oWorksheet; Range oColumnARange; if ( !ExcelUtil.TryGetOrAddWorksheet(oWorkbook, sWorksheetName, out oWorksheet) || !ExcelUtil.TryGetRange(oWorksheet, "A:A", out oColumnARange) ) { return(false); } try { // The worksheet can contain multiple top-N-by tables, so we need // to find where to put the new table. Range oColumn1HeaderCell = GetColumn1HeaderCellForStackedTable( oWorksheet, oColumnARange); // Create just the first column. The table will auto-expand when // this class adds the table's other column. // // (It's assumed here that oGraphMetricColumn represents the // table's first column.) oColumn1HeaderCell.set_Value(Missing.Value, oGraphMetricColumn.ColumnName); Range oTableRange = oColumn1HeaderCell; ExcelUtil.ResizeRange(ref oTableRange, 2, 1); oStackedTable = ExcelTableUtil.AddTable(oWorksheet, oTableRange, oGraphMetricColumn.TableName, TableStyleNames.NodeXLTable); ExcelTableUtil.SetColumnWidth(oColumn1HeaderCell, oGraphMetricColumn.ColumnWidthChars); } catch (System.Runtime.InteropServices.COMException) { return(false); } return(true); }