Наследование: Microsoft.Office.Tools.Excel.WorksheetBase
Пример #1
0
        TryRemoveSelectedVerticesFromGroups
        (
            Microsoft.Office.Interop.Excel.Workbook oWorkbook,
            Sheet2 oVertexWorksheet,
            out ICollection <String> oSelectedVertexNames
        )
        {
            Debug.Assert(oWorkbook != null);
            Debug.Assert(oVertexWorksheet != null);

            oSelectedVertexNames = oVertexWorksheet.GetSelectedVertexNames();

            ExcelTableUtil.RemoveTableRowsByStringColumnValues(oWorkbook,
                                                               WorksheetNames.GroupVertices, TableNames.GroupVertices,
                                                               GroupVertexTableColumnNames.VertexName, oSelectedVertexNames);

            return(true);
        }
Пример #2
0
        TrySelectGroupsWithSelectedVertices
        (
            Microsoft.Office.Interop.Excel.Workbook oWorkbook,
            Sheet2 oVertexWorksheet,
            Sheet5 oGroupWorksheet
        )
        {
            Debug.Assert(oWorkbook != null);
            Debug.Assert(oVertexWorksheet != null);
            Debug.Assert(oGroupWorksheet != null);

            // For each selected vertex, get the vertex's group name from the
            // group-vertex worksheet and select that group in the group worksheet.

            ICollection <String> oSelectedVertexNames =
                oVertexWorksheet.GetSelectedVertexNames();

            oGroupWorksheet.SelectGroups(
                NodeXLWorkbookUtil.GetGroupNamesByVertexName(oWorkbook,
                                                             oSelectedVertexNames));

            return(true);
        }
Пример #3
0
        TryAddSelectedVerticesToGroup
        (
            Microsoft.Office.Interop.Excel.Workbook oWorkbook,
            Sheet2 oVertexWorksheet
        )
        {
            Debug.Assert(oWorkbook != null);
            Debug.Assert(oVertexWorksheet != null);

            AddSelectedVerticesToGroupDialog oAddSelectedVerticesToGroupDialog =
                new AddSelectedVerticesToGroupDialog(oWorkbook);

            if (oAddSelectedVerticesToGroupDialog.ShowDialog() !=
                DialogResult.OK)
            {
                return(false);
            }

            // First, remove the selected vertices from any groups they belong to.

            ListObject           oGroupTable, oGroupVertexTable;
            ICollection <String> oSelectedVertexNames;

            if (
                !TryRemoveSelectedVerticesFromGroups(oWorkbook, oVertexWorksheet,
                                                     out oSelectedVertexNames)
                ||
                !ExcelTableUtil.TryGetTable(oWorkbook, WorksheetNames.Groups,
                                            TableNames.Groups, out oGroupTable)
                ||
                !ExcelTableUtil.TryGetTable(oWorkbook, WorksheetNames.GroupVertices,
                                            TableNames.GroupVertices, out oGroupVertexTable)
                )
            {
                return(false);
            }

            String sGroupName = oAddSelectedVerticesToGroupDialog.GroupName;

            if (oAddSelectedVerticesToGroupDialog.IsNewGroup)
            {
                // Add the new group to the group table.
                //
                // Note that the group table (and the group-vertex table, below)
                // needs to be activated before being written to.  If this isn't
                // done, the formula written to the group-vertex table below also
                // mysteriously appears in the vertex table on the vertex
                // worksheet.
                //
                // It's up to the caller to use the ExcelActiveWorksheetRestorer
                // class to save and restore the active worksheet.

                ExcelUtil.ActivateWorksheet(oGroupTable);

                ExcelTableUtil.AddTableRow(oGroupTable,

                                           GroupTableColumnNames.Name,
                                           sGroupName
                                           );

                SetVertexAttributesForAllGroups(oGroupTable);
            }

            // Add the selected vertices to the group-vertex table.

            ExcelUtil.ActivateWorksheet(oGroupVertexTable);

            foreach (String sSelectedVertexName in oSelectedVertexNames)
            {
                ExcelTableUtil.AddTableRow(oGroupVertexTable,

                                           GroupVertexTableColumnNames.GroupName,
                                           sGroupName,

                                           GroupVertexTableColumnNames.VertexName,
                                           sSelectedVertexName,

                                           GroupVertexTableColumnNames.VertexID,
                                           GetExcelFormulaForVertexID()
                                           );
            }

            return(true);
        }
Пример #4
0
        //*************************************************************************
        //  Constructor: SelectionCoordinator()
        //
        /// <summary>
        /// Initializes a new instance of the <see cref="SelectionCoordinator" />
        /// class.
        /// </summary>
        ///
        /// <param name="thisWorkbook">
        /// The Excel workbook.
        /// </param>
        ///
        /// <param name="edgeWorksheet">
        /// The edge worksheet in the Excel workbook.
        /// </param>
        ///
        /// <param name="edgeTable">
        /// The edge table on the edge worksheet.
        /// </param>
        ///
        /// <param name="vertexWorksheet">
        /// The vertex worksheet in the Excel workbook.
        /// </param>
        ///
        /// <param name="vertexTable">
        /// The vertex table on the vertex worksheet.
        /// </param>
        ///
        /// <param name="groupWorksheet">
        /// The group worksheet in the Excel workbook.
        /// </param>
        ///
        /// <param name="groupTable">
        /// The group table on the group worksheet.
        /// </param>
        ///
        /// <param name="groupVertexWorksheet">
        /// The group-vertex worksheet in the Excel workbook.
        /// </param>
        ///
        /// <param name="taskPane">
        /// The TaskPane.
        /// </param>
        //*************************************************************************

        public SelectionCoordinator
        (
            ThisWorkbook thisWorkbook,
            Sheet1 edgeWorksheet,
            Microsoft.Office.Tools.Excel.ListObject edgeTable,
            Sheet2 vertexWorksheet,
            Microsoft.Office.Tools.Excel.ListObject vertexTable,
            Sheet5 groupWorksheet,
            Microsoft.Office.Tools.Excel.ListObject groupTable,
            Sheet6 groupVertexWorksheet,
            TaskPane taskPane
        )
        {
            Debug.Assert(thisWorkbook != null);
            Debug.Assert(edgeWorksheet != null);
            Debug.Assert(edgeTable != null);
            Debug.Assert(vertexWorksheet != null);
            Debug.Assert(vertexTable != null);
            Debug.Assert(groupWorksheet != null);
            Debug.Assert(groupTable != null);
            Debug.Assert(groupVertexWorksheet != null);
            Debug.Assert(taskPane != null);

            m_oThisWorkbook         = thisWorkbook;
            m_oEdgeWorksheet        = edgeWorksheet;
            m_oVertexWorksheet      = vertexWorksheet;
            m_oGroupWorksheet       = groupWorksheet;
            m_oGroupTable           = groupTable;
            m_oGroupVertexWorksheet = groupVertexWorksheet;
            m_oTaskPane             = taskPane;

            m_bIgnoreSelectionEvents             = false;
            m_bUpdateVertexSelectionOnActivation = false;
            m_bUpdateEdgeSelectionOnActivation   = false;
            m_bUpdateGroupSelectionOnActivation  = false;


            edgeTable.SelectionChange += new DocEvents_SelectionChangeEventHandler(
                EdgeTable_SelectionChange);

            edgeTable.Deselected += new DocEvents_SelectionChangeEventHandler(
                EdgeTable_Deselected);

            m_oEdgeWorksheet.ActivateEvent += new DocEvents_ActivateEventHandler(
                EdgeWorksheet_ActivateEvent);


            vertexTable.SelectionChange +=
                new DocEvents_SelectionChangeEventHandler(
                    VertexTable_SelectionChange);

            vertexTable.Deselected += new DocEvents_SelectionChangeEventHandler(
                VertexTable_Deselected);

            m_oVertexWorksheet.ActivateEvent += new DocEvents_ActivateEventHandler(
                VertexWorksheet_ActivateEvent);


            m_oGroupTable.SelectionChange +=
                new DocEvents_SelectionChangeEventHandler(
                    GroupTable_SelectionChange);

            m_oGroupTable.Deselected += new DocEvents_SelectionChangeEventHandler(
                GroupTable_Deselected);

            m_oGroupWorksheet.ActivateEvent += new DocEvents_ActivateEventHandler(
                GroupWorksheet_ActivateEvent);


            m_oTaskPane.SelectionChangedInGraph +=
                new EventHandler <EventArgs>(this.TaskPane_SelectionChangedInGraph);
        }
Пример #5
0
        TryRunGroupCommand
        (
            GroupCommands groupCommand,
            Microsoft.Office.Interop.Excel.Workbook workbook,
            Sheet2 vertexWorksheet,
            Sheet5 groupWorksheet
        )
        {
            Debug.Assert(workbook != null);
            Debug.Assert(vertexWorksheet != null);
            Debug.Assert(groupWorksheet != null);

            switch (groupCommand)
            {
            case GroupCommands.None:

                return(true);

            case GroupCommands.CollapseSelectedGroups:

                return(TryCollapseOrExpandSelectedGroups(workbook, true));

            case GroupCommands.ExpandSelectedGroups:

                return(TryCollapseOrExpandSelectedGroups(workbook, false));

            case GroupCommands.CollapseAllGroups:

                return(TryCollapseOrExpandAllGroups(workbook, true));

            case GroupCommands.ExpandAllGroups:

                return(TryCollapseOrExpandAllGroups(workbook, false));

            case GroupCommands.SelectGroupsWithSelectedVertices:

                return(TrySelectGroupsWithSelectedVertices(workbook,
                                                           vertexWorksheet, groupWorksheet));

            case GroupCommands.SelectAllGroups:

                return(TrySelectAllGroups(workbook));

            case GroupCommands.AddSelectedVerticesToGroup:

                return(TryAddSelectedVerticesToGroup(workbook,
                                                     vertexWorksheet));

            case GroupCommands.RemoveSelectedVerticesFromGroups:

                ICollection <String> oSelectedVertexNames;

                return(TryRemoveSelectedVerticesFromGroups(workbook,
                                                           vertexWorksheet, out oSelectedVertexNames));

            case GroupCommands.RemoveSelectedGroups:

                return(TryRemoveSelectedGroups(workbook, groupWorksheet));

            case GroupCommands.RemoveAllGroups:

                return(TryRemoveAllGroups(workbook));

            default:

                Debug.Assert(false);
                return(false);
            }
        }
    //*************************************************************************
    //  Constructor: SelectionCoordinator()
    //
    /// <summary>
    /// Initializes a new instance of the <see cref="SelectionCoordinator" />
    /// class.
    /// </summary>
    ///
    /// <param name="thisWorkbook">
    /// The Excel workbook.
    /// </param>
    ///
    /// <param name="edgeWorksheet">
    /// The edge worksheet in the Excel workbook.
    /// </param>
    ///
    /// <param name="edgeTable">
    /// The edge table on the edge worksheet.
    /// </param>
    ///
    /// <param name="vertexWorksheet">
    /// The vertex worksheet in the Excel workbook.
    /// </param>
    ///
    /// <param name="vertexTable">
    /// The vertex table on the vertex worksheet.
    /// </param>
    ///
    /// <param name="groupWorksheet">
    /// The group worksheet in the Excel workbook.
    /// </param>
    ///
    /// <param name="groupTable">
    /// The group table on the group worksheet.
    /// </param>
    ///
    /// <param name="groupVertexWorksheet">
    /// The group-vertex worksheet in the Excel workbook.
    /// </param>
    ///
    /// <param name="taskPane">
    /// The TaskPane.
    /// </param>
    //*************************************************************************

    public SelectionCoordinator
    (
        ThisWorkbook thisWorkbook,
        Sheet1 edgeWorksheet,
        Microsoft.Office.Tools.Excel.ListObject edgeTable,
        Sheet2 vertexWorksheet,
        Microsoft.Office.Tools.Excel.ListObject vertexTable,
        Sheet5 groupWorksheet,
        Microsoft.Office.Tools.Excel.ListObject groupTable,
        Sheet6 groupVertexWorksheet,
        TaskPane taskPane
    )
    {
        Debug.Assert(thisWorkbook != null);
        Debug.Assert(edgeWorksheet != null);
        Debug.Assert(edgeTable != null);
        Debug.Assert(vertexWorksheet != null);
        Debug.Assert(vertexTable != null);
        Debug.Assert(groupWorksheet != null);
        Debug.Assert(groupTable != null);
        Debug.Assert(groupVertexWorksheet != null);
        Debug.Assert(taskPane != null);

        m_oThisWorkbook = thisWorkbook;
        m_oEdgeWorksheet = edgeWorksheet;
        m_oVertexWorksheet = vertexWorksheet;
        m_oGroupWorksheet = groupWorksheet;
        m_oGroupTable = groupTable;
        m_oGroupVertexWorksheet = groupVertexWorksheet;
        m_oTaskPane = taskPane;

        m_bIgnoreSelectionEvents = false;
        m_bUpdateVertexSelectionOnActivation = false;
        m_bUpdateEdgeSelectionOnActivation = false;
        m_bUpdateGroupSelectionOnActivation = false;


        edgeTable.SelectionChange += new DocEvents_SelectionChangeEventHandler(
            EdgeTable_SelectionChange);

        edgeTable.Deselected += new DocEvents_SelectionChangeEventHandler(
            EdgeTable_Deselected);

        m_oEdgeWorksheet.ActivateEvent += new DocEvents_ActivateEventHandler(
            EdgeWorksheet_ActivateEvent);


        vertexTable.SelectionChange +=
            new DocEvents_SelectionChangeEventHandler(
                VertexTable_SelectionChange);

        vertexTable.Deselected += new DocEvents_SelectionChangeEventHandler(
            VertexTable_Deselected);

        m_oVertexWorksheet.ActivateEvent += new DocEvents_ActivateEventHandler(
            VertexWorksheet_ActivateEvent);


        m_oGroupTable.SelectionChange +=
            new DocEvents_SelectionChangeEventHandler(
                GroupTable_SelectionChange);

        m_oGroupTable.Deselected += new DocEvents_SelectionChangeEventHandler(
            GroupTable_Deselected);

        m_oGroupWorksheet.ActivateEvent += new DocEvents_ActivateEventHandler(
            GroupWorksheet_ActivateEvent);


        m_oTaskPane.SelectionChangedInGraph +=
            new EventHandler<EventArgs>(this.TaskPane_SelectionChangedInGraph);
    }
Пример #7
0
    TryRemoveSelectedVerticesFromGroups
    (
        Microsoft.Office.Interop.Excel.Workbook oWorkbook,
        Sheet2 oVertexWorksheet,
        out ICollection<String> oSelectedVertexNames
    )
    {
        Debug.Assert(oWorkbook != null);
        Debug.Assert(oVertexWorksheet != null);

        oSelectedVertexNames = oVertexWorksheet.GetSelectedVertexNames();

        ExcelTableUtil.RemoveTableRowsByStringColumnValues(oWorkbook,
            WorksheetNames.GroupVertices, TableNames.GroupVertices,
            GroupVertexTableColumnNames.VertexName, oSelectedVertexNames);

        return (true);
    }
Пример #8
0
    TryAddSelectedVerticesToGroup
    (
        Microsoft.Office.Interop.Excel.Workbook oWorkbook,
        Sheet2 oVertexWorksheet
    )
    {
        Debug.Assert(oWorkbook != null);
        Debug.Assert(oVertexWorksheet != null);

        AddSelectedVerticesToGroupDialog oAddSelectedVerticesToGroupDialog =
            new AddSelectedVerticesToGroupDialog(oWorkbook);

        if (oAddSelectedVerticesToGroupDialog.ShowDialog() !=
            DialogResult.OK)
        {
            return (false);
        }

        // First, remove the selected vertices from any groups they belong to.

        ListObject oGroupTable, oGroupVertexTable;
        ICollection<String> oSelectedVertexNames;

        if (
            !TryRemoveSelectedVerticesFromGroups(oWorkbook, oVertexWorksheet,
                out oSelectedVertexNames)
            ||
            !ExcelTableUtil.TryGetTable(oWorkbook, WorksheetNames.Groups,
                TableNames.Groups, out oGroupTable)
            ||
            !ExcelTableUtil.TryGetTable(oWorkbook, WorksheetNames.GroupVertices,
                TableNames.GroupVertices, out oGroupVertexTable)
            )
        {
            return (false);
        }

        String sGroupName = oAddSelectedVerticesToGroupDialog.GroupName;

        if (oAddSelectedVerticesToGroupDialog.IsNewGroup)
        {
            // Add the new group to the group table.
            //
            // Note that the group table (and the group-vertex table, below)
            // needs to be activated before being written to.  If this isn't
            // done, the formula written to the group-vertex table below also
            // mysteriously appears in the vertex table on the vertex
            // worksheet.
            //
            // It's up to the caller to use the ExcelActiveWorksheetRestorer
            // class to save and restore the active worksheet.

            ExcelUtil.ActivateWorksheet(oGroupTable);

            ExcelTableUtil.AddTableRow(oGroupTable,

                GroupTableColumnNames.Name,
                sGroupName
                );

            SetVertexAttributesForAllGroups(oGroupTable);
        }

        // Add the selected vertices to the group-vertex table.

        ExcelUtil.ActivateWorksheet(oGroupVertexTable);

        foreach (String sSelectedVertexName in oSelectedVertexNames)
        {
            ExcelTableUtil.AddTableRow(oGroupVertexTable,

                GroupVertexTableColumnNames.GroupName,
                sGroupName,

                GroupVertexTableColumnNames.VertexName,
                sSelectedVertexName,

                GroupVertexTableColumnNames.VertexID,
                GetExcelFormulaForVertexID()
                );
        }

        return (true);
    }
Пример #9
0
    TrySelectGroupsWithSelectedVertices
    (
        Microsoft.Office.Interop.Excel.Workbook oWorkbook,
        Sheet2 oVertexWorksheet,
        Sheet5 oGroupWorksheet
    )
    {
        Debug.Assert(oWorkbook != null);
        Debug.Assert(oVertexWorksheet != null);
        Debug.Assert(oGroupWorksheet != null);

        // For each selected vertex, get the vertex's group name from the 
        // group-vertex worksheet and select that group in the group worksheet.

        ICollection<String> oSelectedVertexNames =
            oVertexWorksheet.GetSelectedVertexNames();

        oGroupWorksheet.SelectGroups(
            NodeXLWorkbookUtil.GetGroupNamesByVertexName(oWorkbook,
                oSelectedVertexNames) );

        return (true);
    }
Пример #10
0
    TryRunGroupCommand
    (
        GroupCommands groupCommand,
        Microsoft.Office.Interop.Excel.Workbook workbook,
        Sheet2 vertexWorksheet,
        Sheet5 groupWorksheet
    )
    {
        Debug.Assert(workbook != null);
        Debug.Assert(vertexWorksheet != null);
        Debug.Assert(groupWorksheet != null);

        switch (groupCommand)
        {
            case GroupCommands.None:

                return (true);

            case GroupCommands.CollapseSelectedGroups:

                return ( TryCollapseOrExpandSelectedGroups(workbook, true) );

            case GroupCommands.ExpandSelectedGroups:

                return ( TryCollapseOrExpandSelectedGroups(workbook, false) );

            case GroupCommands.CollapseAllGroups:

                return ( TryCollapseOrExpandAllGroups(workbook, true) );

            case GroupCommands.ExpandAllGroups:

                return ( TryCollapseOrExpandAllGroups(workbook, false) );

            case GroupCommands.SelectGroupsWithSelectedVertices:

                return ( TrySelectGroupsWithSelectedVertices(workbook,
                    vertexWorksheet, groupWorksheet) );

            case GroupCommands.SelectAllGroups:

                return ( TrySelectAllGroups(workbook) );

            case GroupCommands.AddSelectedVerticesToGroup:

                return ( TryAddSelectedVerticesToGroup(workbook,
                    vertexWorksheet) );

            case GroupCommands.RemoveSelectedVerticesFromGroups:

                ICollection<String> oSelectedVertexNames;

                return ( TryRemoveSelectedVerticesFromGroups(workbook,
                    vertexWorksheet, out oSelectedVertexNames) );

            case GroupCommands.RemoveSelectedGroups:

                return ( TryRemoveSelectedGroups(workbook, groupWorksheet) );

            case GroupCommands.RemoveAllGroups:

                return ( TryRemoveAllGroups(workbook) );

            default:

                Debug.Assert(false);
                return (false);
        }
    }