示例#1
0
        GetGroupCommandsToEnable
        (
            Microsoft.Office.Interop.Excel.Workbook workbook
        )
        {
            // Various worksheets must be activated to read their selection.  Save
            // the active worksheet state.

            ExcelActiveWorksheetRestorer oExcelActiveWorksheetRestorer =
                new ExcelActiveWorksheetRestorer(workbook);

            ExcelActiveWorksheetState oExcelActiveWorksheetState =
                oExcelActiveWorksheetRestorer.GetActiveWorksheetState();

            GroupCommands eGroupCommandsToEnable;

            try
            {
                eGroupCommandsToEnable =
                    GetGroupCommandsToEnableInternal(workbook);
            }
            finally
            {
                oExcelActiveWorksheetRestorer.Restore(oExcelActiveWorksheetState);
            }

            return(eGroupCommandsToEnable);
        }
示例#2
0
        ThisWorkbook_AttributesEditedInGraph
        (
            Object sender,
            AttributesEditedEventArgs e
        )
        {
            Debug.Assert(e != null);
            AssertValid();

            // The key is the row ID stored in the table's ID column and the value
            // is the one-based row number relative to the worksheet.

            Dictionary <Int32, Int32> oRowIDDictionary;

            if (
                e.EditedEdgeAttributes == null
                ||
                !m_oSheets1And2Helper.TableExists
                ||
                !m_oSheets1And2Helper.TryGetAllRowIDs(out oRowIDDictionary)
                )
            {
                return;
            }

            Microsoft.Office.Interop.Excel.ListObject oEdgeTable =
                Edges.InnerObject;

            Globals.ThisWorkbook.ShowWaitCursor = true;

            // Get the columns that might need to be updated.  These columns are
            // not required.

            Microsoft.Office.Interop.Excel.Range oColorColumnData,
                                                 oWidthColumnData, oStyleColumnData, oAlphaColumnData,
                                                 oVisibilityColumnData, oLabelColumnData,
                                                 oLabelTextColorColumnData, oLabelFontSizeColumnData;

            Object [,] aoColorValues          = null;
            Object [,] aoWidthValues          = null;
            Object [,] aoStyleValues          = null;
            Object [,] aoAlphaValues          = null;
            Object [,] aoVisibilityValues     = null;
            Object [,] aoLabelValues          = null;
            Object [,] aoLabelTextColorValues = null;
            Object [,] aoLabelFontSizeValues  = null;

            ExcelTableUtil.TryGetTableColumnDataAndValues(oEdgeTable,
                                                          EdgeTableColumnNames.Color, out oColorColumnData,
                                                          out aoColorValues);

            ExcelTableUtil.TryGetTableColumnDataAndValues(oEdgeTable,
                                                          EdgeTableColumnNames.Width, out oWidthColumnData,
                                                          out aoWidthValues);

            ExcelTableUtil.TryGetTableColumnDataAndValues(oEdgeTable,
                                                          EdgeTableColumnNames.Style, out oStyleColumnData,
                                                          out aoStyleValues);

            ExcelTableUtil.TryGetTableColumnDataAndValues(oEdgeTable,
                                                          CommonTableColumnNames.Alpha, out oAlphaColumnData,
                                                          out aoAlphaValues);

            ExcelTableUtil.TryGetTableColumnDataAndValues(oEdgeTable,
                                                          CommonTableColumnNames.Visibility, out oVisibilityColumnData,
                                                          out aoVisibilityValues);

            ExcelTableUtil.TryGetTableColumnDataAndValues(oEdgeTable,
                                                          EdgeTableColumnNames.Label, out oLabelColumnData,
                                                          out aoLabelValues);

            ExcelTableUtil.TryGetTableColumnDataAndValues(oEdgeTable,
                                                          EdgeTableColumnNames.LabelTextColor, out oLabelTextColorColumnData,
                                                          out aoLabelTextColorValues);

            ExcelTableUtil.TryGetTableColumnDataAndValues(oEdgeTable,
                                                          EdgeTableColumnNames.LabelFontSize, out oLabelFontSizeColumnData,
                                                          out aoLabelFontSizeValues);

            ColorConverter2    oColorConverter2    = new ColorConverter2();
            EdgeStyleConverter oEdgeStyleConverter = new EdgeStyleConverter();

            EdgeVisibilityConverter oEdgeVisibilityConverter =
                new EdgeVisibilityConverter();

            // Loop through the IDs of the edges whose attributes were edited
            // in the graph.

            EditedEdgeAttributes oEditedEdgeAttributes = e.EditedEdgeAttributes;

            foreach (Int32 iID in e.EdgeIDs)
            {
                // Look for the row that contains the ID.

                Int32 iRowOneBased;

                if (!oRowIDDictionary.TryGetValue(iID, out iRowOneBased))
                {
                    continue;
                }

                iRowOneBased -= oEdgeTable.Range.Row;

                if (oEditedEdgeAttributes.Color.HasValue && aoColorValues != null)
                {
                    aoColorValues[iRowOneBased, 1] =
                        oColorConverter2.GraphToWorkbook(
                            oEditedEdgeAttributes.Color.Value);
                }

                if (oEditedEdgeAttributes.Width.HasValue && aoWidthValues != null)
                {
                    aoWidthValues[iRowOneBased, 1] =
                        oEditedEdgeAttributes.Width.Value.ToString();
                }

                if (oEditedEdgeAttributes.Style.HasValue && aoStyleValues != null)
                {
                    aoStyleValues[iRowOneBased, 1] =
                        oEdgeStyleConverter.GraphToWorkbook(
                            oEditedEdgeAttributes.Style.Value);
                }

                if (oEditedEdgeAttributes.Alpha.HasValue && aoAlphaValues != null)
                {
                    aoAlphaValues[iRowOneBased, 1] =
                        oEditedEdgeAttributes.Alpha.Value.ToString();
                }

                if (oEditedEdgeAttributes.Visibility.HasValue &&
                    aoVisibilityValues != null)
                {
                    aoVisibilityValues[iRowOneBased, 1] =
                        oEdgeVisibilityConverter.GraphToWorkbook(
                            oEditedEdgeAttributes.Visibility.Value);
                }

                if (!String.IsNullOrEmpty(oEditedEdgeAttributes.Label))
                {
                    aoLabelValues[iRowOneBased, 1] = oEditedEdgeAttributes.Label;
                }

                if (oEditedEdgeAttributes.LabelTextColor.HasValue &&
                    aoLabelTextColorValues != null)
                {
                    aoLabelTextColorValues[iRowOneBased, 1] =
                        oColorConverter2.GraphToWorkbook(
                            oEditedEdgeAttributes.LabelTextColor.Value);
                }

                if (oEditedEdgeAttributes.LabelFontSize.HasValue &&
                    aoLabelFontSizeValues != null)
                {
                    aoLabelFontSizeValues[iRowOneBased, 1] =
                        oEditedEdgeAttributes.LabelFontSize.Value.ToString();
                }
            }

            // Activate this worksheet first, because writing to an inactive
            // worksheet causes problems with the selection in Excel.

            ExcelActiveWorksheetRestorer oExcelActiveWorksheetRestorer =
                m_oSheets1And2Helper.GetExcelActiveWorksheetRestorer();

            ExcelActiveWorksheetState oExcelActiveWorksheetState =
                oExcelActiveWorksheetRestorer.ActivateWorksheet(this.InnerObject);

            try
            {
                m_oSheets1And2Helper.SetColumnDataValues(
                    oColorColumnData, aoColorValues,
                    oWidthColumnData, aoWidthValues,
                    oStyleColumnData, aoStyleValues,
                    oAlphaColumnData, aoAlphaValues,
                    oVisibilityColumnData, aoVisibilityValues,
                    oLabelColumnData, aoLabelValues,
                    oLabelTextColorColumnData, aoLabelTextColorValues,
                    oLabelFontSizeColumnData, aoLabelFontSizeValues
                    );
            }
            finally
            {
                oExcelActiveWorksheetRestorer.Restore(oExcelActiveWorksheetState);
            }

            Globals.ThisWorkbook.ShowWaitCursor = false;
        }
示例#3
0
文件: Sheet2.cs 项目: yesbb12/NetMap
        OnVertexAttributesEditedInGraph
        (
            VertexAttributesEditedEventArgs e
        )
        {
            Debug.Assert(e != null);
            AssertValid();

            Microsoft.Office.Interop.Excel.ListObject oVertexTable =
                Vertices.InnerObject;

            // Get a dictionary containing the ID of each row in the table.

            Dictionary <Int32, Int32> oRowIDDictionary;

            if (!m_oSheets1And2Helper.TryGetAllRowIDs(out oRowIDDictionary))
            {
                // Nothing can be done without the IDs.

                return;
            }

            Globals.ThisWorkbook.ShowWaitCursor = true;

            // Get the columns that might need to be updated.  These columns are
            // not required.

            Microsoft.Office.Interop.Excel.Range oColorColumnData,
                                                 oShapeColumnData, oRadiusColumnData, oAlphaColumnData,
                                                 oVisibilityColumnData, oLabelPositionColumnData, oLockedColumnData,
                                                 oMarkedColumnData;

            Object [,] aoColorValues         = null;
            Object [,] aoShapeValues         = null;
            Object [,] aoRadiusValues        = null;
            Object [,] aoAlphaValues         = null;
            Object [,] aoVisibilityValues    = null;
            Object [,] aoLabelPositionValues = null;
            Object [,] aoLockedValues        = null;
            Object [,] aoMarkedValues        = null;

            ExcelUtil.TryGetTableColumnDataAndValues(oVertexTable,
                                                     VertexTableColumnNames.Color, out oColorColumnData,
                                                     out aoColorValues);

            ExcelUtil.TryGetTableColumnDataAndValues(oVertexTable,
                                                     VertexTableColumnNames.Shape, out oShapeColumnData,
                                                     out aoShapeValues);

            ExcelUtil.TryGetTableColumnDataAndValues(oVertexTable,
                                                     VertexTableColumnNames.Radius, out oRadiusColumnData,
                                                     out aoRadiusValues);

            ExcelUtil.TryGetTableColumnDataAndValues(oVertexTable,
                                                     CommonTableColumnNames.Alpha, out oAlphaColumnData,
                                                     out aoAlphaValues);

            ExcelUtil.TryGetTableColumnDataAndValues(oVertexTable,
                                                     CommonTableColumnNames.Visibility, out oVisibilityColumnData,
                                                     out aoVisibilityValues);

            ExcelUtil.TryGetTableColumnDataAndValues(oVertexTable,
                                                     VertexTableColumnNames.LabelPosition, out oLabelPositionColumnData,
                                                     out aoLabelPositionValues);

            ExcelUtil.TryGetTableColumnDataAndValues(oVertexTable,
                                                     VertexTableColumnNames.Locked, out oLockedColumnData,
                                                     out aoLockedValues);

            if (TryGetMarkedColumnData(out oMarkedColumnData))
            {
                aoMarkedValues = ExcelUtil.GetRangeValues(oMarkedColumnData);
            }

            ColorConverter2 oColorConverter2 = new ColorConverter2();

            VertexShapeConverter oVertexShapeConverter =
                new VertexShapeConverter();

            VertexVisibilityConverter oVertexVisibilityConverter =
                new VertexVisibilityConverter();

            VertexLabelPositionConverter oVertexLabelPositionConverter =
                new VertexLabelPositionConverter();

            BooleanConverter oBooleanConverter = new BooleanConverter();

            // Loop through the IDs of the vertices whose attributes were edited
            // in the graph.

            EditedVertexAttributes oEditedVertexAttributes =
                e.EditedVertexAttributes;

            foreach (Int32 iID in e.VertexIDs)
            {
                // Look for the row that contains the ID.

                Int32 iRowOneBased;

                if (!oRowIDDictionary.TryGetValue(iID, out iRowOneBased))
                {
                    continue;
                }

                iRowOneBased -= oVertexTable.Range.Row;

                if (oEditedVertexAttributes.Color.HasValue &&
                    aoColorValues != null)
                {
                    aoColorValues[iRowOneBased, 1] =
                        oColorConverter2.GraphToWorkbook(
                            oEditedVertexAttributes.Color.Value);
                }

                if (oEditedVertexAttributes.Shape.HasValue &&
                    aoShapeValues != null)
                {
                    aoShapeValues[iRowOneBased, 1] =
                        oVertexShapeConverter.GraphToWorkbook(
                            oEditedVertexAttributes.Shape.Value);
                }

                if (oEditedVertexAttributes.Radius.HasValue &&
                    aoRadiusValues != null)
                {
                    aoRadiusValues[iRowOneBased, 1] =
                        oEditedVertexAttributes.Radius.Value.ToString();
                }

                if (oEditedVertexAttributes.Alpha.HasValue &&
                    aoAlphaValues != null)
                {
                    aoAlphaValues[iRowOneBased, 1] =
                        oEditedVertexAttributes.Alpha.Value.ToString();
                }

                if (oEditedVertexAttributes.Visibility.HasValue &&
                    aoVisibilityValues != null)
                {
                    aoVisibilityValues[iRowOneBased, 1] =
                        oVertexVisibilityConverter.GraphToWorkbook(
                            oEditedVertexAttributes.Visibility.Value);
                }

                if (oEditedVertexAttributes.LabelPosition.HasValue &&
                    aoLabelPositionValues != null)
                {
                    aoLabelPositionValues[iRowOneBased, 1] =
                        oVertexLabelPositionConverter.GraphToWorkbook(
                            oEditedVertexAttributes.LabelPosition.Value);
                }

                if (oEditedVertexAttributes.Locked.HasValue &&
                    aoLockedValues != null)
                {
                    aoLockedValues[iRowOneBased, 1] =
                        oBooleanConverter.GraphToWorkbook(
                            oEditedVertexAttributes.Locked.Value);
                }

                if (oEditedVertexAttributes.Marked.HasValue &&
                    aoMarkedValues != null)
                {
                    aoMarkedValues[iRowOneBased, 1] =
                        oBooleanConverter.GraphToWorkbook(
                            oEditedVertexAttributes.Marked.Value);
                }
            }

            // Activate this worksheet first, because writing to an inactive
            // worksheet causes problems with the selection in Excel.

            ExcelActiveWorksheetRestorer oExcelActiveWorksheetRestorer =
                GetExcelActiveWorksheetRestorer();

            ExcelActiveWorksheetState oExcelActiveWorksheetState =
                oExcelActiveWorksheetRestorer.ActivateWorksheet(this.InnerObject);

            try
            {
                if (aoColorValues != null)
                {
                    oColorColumnData.set_Value(Missing.Value, aoColorValues);
                }

                if (aoShapeValues != null)
                {
                    oShapeColumnData.set_Value(Missing.Value, aoShapeValues);
                }

                if (aoRadiusValues != null)
                {
                    oRadiusColumnData.set_Value(Missing.Value, aoRadiusValues);
                }

                if (aoAlphaValues != null)
                {
                    oAlphaColumnData.set_Value(Missing.Value, aoAlphaValues);
                }

                if (aoVisibilityValues != null)
                {
                    oVisibilityColumnData.set_Value(Missing.Value,
                                                    aoVisibilityValues);
                }

                if (aoLabelPositionValues != null)
                {
                    oLabelPositionColumnData.set_Value(Missing.Value,
                                                       aoLabelPositionValues);
                }

                if (aoLockedValues != null)
                {
                    oLockedColumnData.set_Value(Missing.Value, aoLockedValues);
                }

                if (aoMarkedValues != null)
                {
                    oMarkedColumnData.set_Value(Missing.Value, aoMarkedValues);
                }
            }
            finally
            {
                oExcelActiveWorksheetRestorer.Restore(oExcelActiveWorksheetState);
            }

            Globals.ThisWorkbook.ShowWaitCursor = false;
        }
示例#4
0
文件: Sheet2.cs 项目: yesbb12/NetMap
        OnGraphLaidOut
        (
            GraphLaidOutEventArgs e
        )
        {
            Debug.Assert(e != null);
            AssertValid();

            // This method gathers some necessary information and returns without
            // doing anything else if some of the information is missing.

            Microsoft.Office.Interop.Excel.ListObject oVertexTable =
                Vertices.InnerObject;

            // Get the ID column data from the vertex table.  This excludes the
            // header.

            Microsoft.Office.Interop.Excel.Range oIDColumnData;

            if (!ExcelUtil.TryGetTableColumnData(oVertexTable,
                                                 CommonTableColumnNames.ID, out oIDColumnData))
            {
                return;
            }

            // Get the location columns from the vertex table.  These are the
            // entire table columns, including the headers.

            Microsoft.Office.Interop.Excel.ListColumn oXColumn, oYColumn;

            if (
                !ExcelUtil.TryGetTableColumn(oVertexTable,
                                             VertexTableColumnNames.X, out oXColumn)
                ||
                !ExcelUtil.TryGetTableColumn(oVertexTable,
                                             VertexTableColumnNames.Y, out oYColumn)
                )
            {
                return;
            }

            // The vertex table may be filtered.  Get the visible range, which may
            // contain multiple areas.

            Microsoft.Office.Interop.Excel.Range oDataBodyRange =
                Vertices.DataBodyRange;

            if (oDataBodyRange == null)
            {
                return;
            }

            Microsoft.Office.Interop.Excel.Range oVisibleDataBodyRange;

            if (!ExcelUtil.TryGetVisibleRange(oDataBodyRange,
                                              out oVisibleDataBodyRange))
            {
                return;
            }

            // The necessary information has been gathered.  Move on to the actual
            // work.  Activate this worksheet first, because writing to an inactive
            // worksheet causes problems with the selection in Excel.

            ExcelActiveWorksheetRestorer oExcelActiveWorksheetRestorer =
                GetExcelActiveWorksheetRestorer();

            ExcelActiveWorksheetState oExcelActiveWorksheetState =
                oExcelActiveWorksheetRestorer.ActivateWorksheet(this.InnerObject);

            try
            {
                OnGraphLaidOut(e, oVertexTable, oDataBodyRange,
                               oVisibleDataBodyRange, oIDColumnData, oXColumn, oYColumn);
            }
            finally
            {
                oExcelActiveWorksheetRestorer.Restore(oExcelActiveWorksheetState);
            }
        }
示例#5
0
        SetLocations <TLocationInfo>
        (
            ICollection <TLocationInfo> locationInfo,
            System.Drawing.Rectangle graphRectangle,
            String xColumnName,
            String yColumnName,
            String lockedColumnName,
            TryGetRowIDAndLocation <TLocationInfo> tryGetRowIDAndLocation
        )
        {
            Debug.Assert(locationInfo != null);
            Debug.Assert(!String.IsNullOrEmpty(xColumnName));
            Debug.Assert(!String.IsNullOrEmpty(yColumnName));
            Debug.Assert(tryGetRowIDAndLocation != null);
            AssertValid();

            if (locationInfo.Count == 0)
            {
                return;
            }

            // Gather some required information.

            ListObject oTable = m_oTable.InnerObject;
            Range      oXColumnData, oYColumnData, oLockedColumnData;

            Object [,] aoLockedColumnValues = null;

            // The key is a row ID and the value is the row's one-based row number
            // relative to the worksheet.

            Dictionary <Int32, Int32> oRowIDDictionary;

            if (
                TryGetAllRowIDs(out oRowIDDictionary)
                &&
                ExcelTableUtil.TryGetTableColumnData(oTable, xColumnName,
                                                     out oXColumnData)
                &&
                ExcelTableUtil.TryGetTableColumnData(oTable, yColumnName,
                                                     out oYColumnData)
                &&
                (
                    lockedColumnName == null
                    ||
                    ExcelTableUtil.TryGetTableColumnDataAndValues(oTable,
                                                                  lockedColumnName, out oLockedColumnData,
                                                                  out aoLockedColumnValues)
                )
                )
            {
                // Activate this worksheet, because writing to an inactive
                // worksheet causes problems with the selection in Excel.

                ExcelActiveWorksheetRestorer oExcelActiveWorksheetRestorer =
                    GetExcelActiveWorksheetRestorer();

                ExcelActiveWorksheetState oExcelActiveWorksheetState =
                    oExcelActiveWorksheetRestorer.ActivateWorksheet(
                        m_oWorksheet.InnerObject);

                try
                {
                    SetLocations <TLocationInfo>(locationInfo, graphRectangle,
                                                 tryGetRowIDAndLocation, oRowIDDictionary, oXColumnData,
                                                 oYColumnData, aoLockedColumnValues);
                }
                finally
                {
                    oExcelActiveWorksheetRestorer.Restore(
                        oExcelActiveWorksheetState);
                }
            }
        }