TryCollapseOrExpandSelectedGroups ( Microsoft.Office.Interop.Excel.Workbook oWorkbook, Boolean bCollapse ) { Debug.Assert(oWorkbook != null); ListObject oGroupTable; Range oSelectedTableRange; if (ExcelTableUtil.TryGetSelectedTableRange(oWorkbook, WorksheetNames.Groups, TableNames.Groups, out oGroupTable, out oSelectedTableRange)) { // Store the new collapsed state in the group table. ExcelTableUtil.SetVisibleSelectedTableColumnData(oGroupTable, oSelectedTableRange, GroupTableColumnNames.Collapsed, (new BooleanConverter()).GraphToWorkbook(bCollapse)); return(true); } return(false); }
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); }
GetSelectedColumnValues <TValue> ( String columnName, ExcelUtil.TryGetValueFromCell <TValue> tryGetValueFromCell ) { Debug.Assert(!String.IsNullOrEmpty(columnName)); Debug.Assert(tryGetValueFromCell != null); AssertValid(); // Create a HashSet for the selected values. The HashSet key is the // cell value. HashSet <TValue> oSelectedValues = new HashSet <TValue>(); if (!this.TableExists) { goto Done; } // The selected range can extend outside the table. Get the // intersection of the table with the selection. Note that // ExcelUtil.TryGetSelectedTableRange() activates the worksheet. ListObject oTable; Range oSelectedTableRange; if (!ExcelTableUtil.TryGetSelectedTableRange( (Workbook)m_oWorksheet.Parent, m_oWorksheet.Name, m_oTable.Name, out oTable, out oSelectedTableRange)) { goto Done; } Range oDataBodyRange = m_oTable.DataBodyRange; Debug.Assert(oDataBodyRange != null); // Get data for the specified column. This includes hidden rows but // excludes the header row. Range oColumnData; Object [,] aoColumnValues; if (!ExcelTableUtil.TryGetTableColumnDataAndValues( m_oTable.InnerObject, columnName, out oColumnData, out aoColumnValues)) { goto Done; } // Read the column. foreach (Range oSelectedTableRangeArea in oSelectedTableRange.Areas) { Int32 iFirstRowOneBased = oSelectedTableRangeArea.Row - oDataBodyRange.Row + 1; Int32 iLastRowOneBased = iFirstRowOneBased + oSelectedTableRangeArea.Rows.Count - 1; for (Int32 iRowOneBased = iFirstRowOneBased; iRowOneBased <= iLastRowOneBased; iRowOneBased++) { TValue tValue; if (tryGetValueFromCell(aoColumnValues, iRowOneBased, 1, out tValue)) { oSelectedValues.Add(tValue); } } } Done: return(oSelectedValues); }