CopyTableToNewNodeXLWorkbook ( String sWorksheetName, String sTableName, String sTemplatePath, ref Workbook oNewNodeXLWorkbook ) { Debug.Assert(!String.IsNullOrEmpty(sWorksheetName)); Debug.Assert(!String.IsNullOrEmpty(sTableName)); Debug.Assert(!String.IsNullOrEmpty(sTemplatePath)); AssertValid(); ListObject oTable; Range oSelectedTableRange; if ( !ExcelTableUtil.TryGetSelectedTableRange(m_oWorkbookToExport, sWorksheetName, sTableName, out oTable, out oSelectedTableRange) || ExcelTableUtil.VisibleTableRangeIsEmpty(oTable) ) { return; } Range oVisibleSelectedTableRange; // CopyRowsToNewNodeXLWorkbook() can handle hidden rows, but not hidden // columns. Temporarily show all hidden columns in the table. ExcelHiddenColumns oHiddenColumns = ExcelColumnHider.ShowHiddenColumns(oTable); try { if (ExcelUtil.TryGetVisibleRange(oSelectedTableRange, out oVisibleSelectedTableRange)) { // Create the new workbook if necessary and copy the table's // selected rows to it. if (oNewNodeXLWorkbook == null) { oNewNodeXLWorkbook = m_oWorkbookToExport.Application.Workbooks.Add( sTemplatePath); } CopyRowsToNewNodeXLWorkbook(oTable, oVisibleSelectedTableRange, oNewNodeXLWorkbook); } } finally { ExcelColumnHider.RestoreHiddenColumns(oTable, oHiddenColumns); } }
GetGroupCommandsToEnableInternal ( Microsoft.Office.Interop.Excel.Workbook oWorkbook ) { Debug.Assert(oWorkbook != null); GroupCommands eGroupCommandsToEnable = GroupCommands.None; ListObject oGroupTable; Range oSelectedTableRange; // Are any groups selected in the group table? if (ExcelTableUtil.TryGetSelectedTableRange(oWorkbook, WorksheetNames.Groups, TableNames.Groups, out oGroupTable, out oSelectedTableRange)) { // Yes. eGroupCommandsToEnable |= ( GroupCommands.CollapseSelectedGroups | GroupCommands.ExpandSelectedGroups | GroupCommands.RemoveSelectedGroups ); } // Are any vertices selected in the vertex table? ListObject oVertexTable; Boolean bVerticesSelected = ExcelTableUtil.TryGetSelectedTableRange( oWorkbook, WorksheetNames.Vertices, TableNames.Vertices, out oVertexTable, out oSelectedTableRange); if (bVerticesSelected) { eGroupCommandsToEnable |= GroupCommands.AddSelectedVerticesToGroup; } // Are there any groups? if (!ExcelTableUtil.VisibleTableRangeIsEmpty(oGroupTable)) { // Yes. eGroupCommandsToEnable |= ( GroupCommands.CollapseAllGroups | GroupCommands.ExpandAllGroups | GroupCommands.SelectAllGroups | GroupCommands.RemoveAllGroups ); if (bVerticesSelected) { eGroupCommandsToEnable |= ( GroupCommands.SelectGroupsWithSelectedVertices | GroupCommands.RemoveSelectedVerticesFromGroups ); } } return(eGroupCommandsToEnable); }
FillIDColumn ( ListObject oTable ) { Debug.Assert(oTable != null); AssertValid(); // Read the range that contains visible data. If the table is // filtered, the range may contain multiple areas. Range oVisibleRange; ListColumn oIDColumn; if ( !ExcelTableUtil.TryGetVisibleTableRange(oTable, out oVisibleRange) || ExcelTableUtil.VisibleTableRangeIsEmpty(oTable) || !ExcelTableUtil.TryGetOrAddTableColumn(oTable, CommonTableColumnNames.ID, ExcelTableUtil.AutoColumnWidth, null, out oIDColumn) ) { return; } Int32 iIDColumnIndex = oIDColumn.Index; Range oDataBodyRange = oTable.DataBodyRange; Debug.Assert(oDataBodyRange != null); Debug.Assert(oTable.Parent is Worksheet); Worksheet oWorksheet = (Worksheet)oTable.Parent; foreach (Range oArea in oVisibleRange.Areas) { // Get the rows within the ID column that should be filled in. Int32 iAreaStartRowOneBased = oArea.Row; Int32 iRowsInArea = oArea.Rows.Count; Int32 iTableStartRowOneBased = oTable.Range.Row; Range oIDRange = oWorksheet.get_Range( (Range)oDataBodyRange.Cells[ iAreaStartRowOneBased - iTableStartRowOneBased, iIDColumnIndex], (Range)oDataBodyRange.Cells[ iAreaStartRowOneBased - iTableStartRowOneBased + iRowsInArea - 1, iIDColumnIndex] ); // Use the Excel row numbers as the unique IDs. Create a // one-column array, then fill it in with the row numbers. Int32 iRows = oIDRange.Rows.Count; Object [,] aoValues = ExcelUtil.GetSingleColumn2DArray(iRows); for (Int32 i = 1; i <= iRows; i++) { aoValues[i, 1] = iAreaStartRowOneBased + i - 1; } oIDRange.Value2 = aoValues; #if false // Note: Don't use the following clever code to fill in the row // numbers. On large worksheets, the calculations take forever. oIDRange.Value2 = "=ROW()"; oIDRange.Value2 = oIDRange.Value2; #endif } }