コード例 #1
0
        //*************************************************************************
        //  Method: AutoFillWorkbook()
        //
        /// <summary>
        /// Runs the application's autofill feature on a workbook.
        /// </summary>
        ///
        /// <param name="workbook">
        /// The workbook to autofill.
        /// </param>
        ///
        /// <param name="autoFillUserSettings">
        /// Specifies one or more source-to-destination column mappings.
        /// </param>
        ///
        /// <remarks>
        /// See the class topic for information on the AutoFill feature.
        ///
        /// <para>
        /// In addition to autofilling one or more columns, this method stores the
        /// results of the autofill as an <see cref="AutoFillWorkbookResults" />
        /// using <see cref="PerWorkbookSettings" />.
        /// </para>
        ///
        /// </remarks>
        //*************************************************************************
        public static void AutoFillWorkbook(
            Microsoft.Office.Interop.Excel.Workbook workbook,
            AutoFillUserSettings autoFillUserSettings
            )
        {
            Debug.Assert(workbook != null);
            Debug.Assert(autoFillUserSettings != null);

            Application oApplication = workbook.Application;

            oApplication.ScreenUpdating = false;

            try
            {
            AutoFillWorkbookInternal(workbook, autoFillUserSettings);
            }
            finally
            {
            oApplication.ScreenUpdating = true;
            }
        }
コード例 #2
0
        //*************************************************************************
        //  Method: AutoFillWorkbookInternal()
        //
        /// <summary>
        /// Runs the application's AutoFill feature on a workbook.
        /// </summary>
        ///
        /// <param name="oWorkbook">
        /// The workbook to autofill.
        /// </param>
        ///
        /// <param name="oAutoFillUserSettings">
        /// Specifies one or more source-to-destination column mappings.
        /// </param>
        //*************************************************************************
        private static void AutoFillWorkbookInternal(
            Microsoft.Office.Interop.Excel.Workbook oWorkbook,
            AutoFillUserSettings oAutoFillUserSettings
            )
        {
            Debug.Assert(oWorkbook != null);
            Debug.Assert(oAutoFillUserSettings != null);

            // Populate the vertex worksheet with the name of each unique vertex in
            // the edge worksheet.

            ( new VertexWorksheetPopulator() ).PopulateVertexWorksheet(
            oWorkbook, false);

            ListObject oTable;
            ExcelHiddenColumns oHiddenColumns;

            AutoFillWorkbookResults oAutoFillWorkbookResults =
            new AutoFillWorkbookResults();

            if ( ExcelUtil.TryGetTable(oWorkbook, WorksheetNames.Edges,
            TableNames.Edges, out oTable) )
            {
            // The TableColumnMapper class that does the actual autofilling
            // fills only visible cells.  Temporarily show all hidden columns
            // in the table.

            oHiddenColumns = ExcelColumnHider.ShowHiddenColumns(oTable);

            try
            {
                AutoFillEdgeTable(oTable, oAutoFillUserSettings,
                    oAutoFillWorkbookResults);
            }
            finally
            {
                ExcelColumnHider.RestoreHiddenColumns(oTable, oHiddenColumns);
            }
            }

            if ( ExcelUtil.TryGetTable(oWorkbook, WorksheetNames.Vertices,
            TableNames.Vertices, out oTable) )
            {
            oHiddenColumns = ExcelColumnHider.ShowHiddenColumns(oTable);

            try
            {
                AutoFillVertexTable(oTable, oAutoFillUserSettings,
                    oAutoFillWorkbookResults);
            }
            finally
            {
                ExcelColumnHider.RestoreHiddenColumns(oTable, oHiddenColumns);
            }
            }

            // Save the results.

            ( new PerWorkbookSettings(oWorkbook) ).AutoFillWorkbookResults =
            oAutoFillWorkbookResults;
        }
コード例 #3
0
        //*************************************************************************
        //  Method: AutoFillEdgeTable()
        //
        /// <summary>
        /// Runs the application's AutoFill feature on the edge table.
        /// </summary>
        ///
        /// <param name="oEdgeTable">
        /// The table to autofill.
        /// </param>
        ///
        /// <param name="oAutoFillUserSettings">
        /// Specifies one or more source-to-destination column mappings.
        /// </param>
        ///
        /// <param name="oAutoFillWorkbookResults">
        /// Stores the autofill results.
        /// </param>
        //*************************************************************************
        private static void AutoFillEdgeTable(
            ListObject oEdgeTable,
            AutoFillUserSettings oAutoFillUserSettings,
            AutoFillWorkbookResults oAutoFillWorkbookResults
            )
        {
            Debug.Assert(oEdgeTable != null);
            Debug.Assert(oAutoFillUserSettings != null);
            Debug.Assert(oAutoFillWorkbookResults != null);

            Double dSourceCalculationNumber1, dSourceCalculationNumber2;
            Int32 iDecimalPlaces;

            if ( TryAutoFillColorColumn(oEdgeTable,
                oAutoFillUserSettings.EdgeColorSourceColumnName,
                EdgeTableColumnNames.Color,
                oAutoFillUserSettings.EdgeColorDetails,
                out dSourceCalculationNumber1, out dSourceCalculationNumber2,
                out iDecimalPlaces
                ) )
            {
            oAutoFillWorkbookResults.EdgeColorResults =
                new AutoFillColorColumnResults(
                    oAutoFillUserSettings.EdgeColorSourceColumnName,
                    dSourceCalculationNumber1, dSourceCalculationNumber2,
                    iDecimalPlaces,
                    oAutoFillUserSettings.EdgeColorDetails.DestinationColor1,
                    oAutoFillUserSettings.EdgeColorDetails.DestinationColor2
                    );
            }

            if ( TryAutoFillNumericRangeColumn(oEdgeTable,
                oAutoFillUserSettings.EdgeWidthSourceColumnName,
                EdgeTableColumnNames.Width,
                oAutoFillUserSettings.EdgeWidthDetails,
                out dSourceCalculationNumber1, out dSourceCalculationNumber2,
                out iDecimalPlaces
                ) )
            {
            oAutoFillWorkbookResults.EdgeWidthResults =
                new AutoFillNumericRangeColumnResults(
                    oAutoFillUserSettings.EdgeWidthSourceColumnName,
                    dSourceCalculationNumber1, dSourceCalculationNumber2,
                    iDecimalPlaces,
                    oAutoFillUserSettings.EdgeWidthDetails.DestinationNumber1,
                    oAutoFillUserSettings.EdgeWidthDetails.DestinationNumber2
                    );
            }

            if ( TryAutoFillNumericRangeColumn(oEdgeTable,
                oAutoFillUserSettings.EdgeAlphaSourceColumnName,
                CommonTableColumnNames.Alpha,
                oAutoFillUserSettings.EdgeAlphaDetails,
                out dSourceCalculationNumber1, out dSourceCalculationNumber2,
                out iDecimalPlaces
                ) )
            {
            oAutoFillWorkbookResults.EdgeAlphaResults =
                new AutoFillNumericRangeColumnResults(
                    oAutoFillUserSettings.EdgeAlphaSourceColumnName,
                    dSourceCalculationNumber1, dSourceCalculationNumber2,
                    iDecimalPlaces,
                    oAutoFillUserSettings.EdgeAlphaDetails.DestinationNumber1,
                    oAutoFillUserSettings.EdgeAlphaDetails.DestinationNumber2
                    );
            }

            AutoFillNumericComparisonColumn(oEdgeTable,
            oAutoFillUserSettings.EdgeVisibilitySourceColumnName,
            CommonTableColumnNames.Visibility,
            oAutoFillUserSettings.EdgeVisibilityDetails
            );

            AutoFillColumnViaCopy(oEdgeTable,
            oAutoFillUserSettings.EdgeLabelSourceColumnName,
            EdgeTableColumnNames.Label
            );
        }
コード例 #4
0
        //*************************************************************************
        //  Method: AutoFillVertexTable()
        //
        /// <summary>
        /// Runs the application's AutoFill feature on the vertex table.
        /// </summary>
        ///
        /// <param name="oVertexTable">
        /// The table to autofill.
        /// </param>
        ///
        /// <param name="oAutoFillUserSettings">
        /// Specifies one or more source-to-destination column mappings.
        /// </param>
        ///
        /// <param name="oAutoFillWorkbookResults">
        /// Stores the autofill results.
        /// </param>
        //*************************************************************************
        private static void AutoFillVertexTable(
            ListObject oVertexTable,
            AutoFillUserSettings oAutoFillUserSettings,
            AutoFillWorkbookResults oAutoFillWorkbookResults
            )
        {
            Debug.Assert(oVertexTable != null);
            Debug.Assert(oAutoFillUserSettings != null);
            Debug.Assert(oAutoFillWorkbookResults != null);

            Double dSourceCalculationNumber1, dSourceCalculationNumber2;
            Int32 iDecimalPlaces;

            if ( TryAutoFillColorColumn(oVertexTable,
                oAutoFillUserSettings.VertexColorSourceColumnName,
                VertexTableColumnNames.Color,
                oAutoFillUserSettings.VertexColorDetails,
                out dSourceCalculationNumber1,
                out dSourceCalculationNumber2,
                out iDecimalPlaces
                ) )
            {
            oAutoFillWorkbookResults.VertexColorResults =
                new AutoFillColorColumnResults(
                    oAutoFillUserSettings.VertexColorSourceColumnName,
                    dSourceCalculationNumber1, dSourceCalculationNumber2,
                    iDecimalPlaces,
                    oAutoFillUserSettings.VertexColorDetails.DestinationColor1,
                    oAutoFillUserSettings.VertexColorDetails.DestinationColor2
                    );
            }

            AutoFillNumericComparisonColumn(oVertexTable,
            oAutoFillUserSettings.VertexShapeSourceColumnName,
            VertexTableColumnNames.Shape,
            oAutoFillUserSettings.VertexShapeDetails
            );

            if ( TryAutoFillNumericRangeColumn(oVertexTable,
                oAutoFillUserSettings.VertexRadiusSourceColumnName,
                VertexTableColumnNames.Radius,
                oAutoFillUserSettings.VertexRadiusDetails,
                out dSourceCalculationNumber1, out dSourceCalculationNumber2,
                out iDecimalPlaces
                ) )
            {
            oAutoFillWorkbookResults.VertexRadiusResults =
                new AutoFillNumericRangeColumnResults(
                    oAutoFillUserSettings.VertexRadiusSourceColumnName,
                    dSourceCalculationNumber1, dSourceCalculationNumber2,
                    iDecimalPlaces,
                    oAutoFillUserSettings.VertexRadiusDetails.
                        DestinationNumber1,
                    oAutoFillUserSettings.VertexRadiusDetails.
                        DestinationNumber2
                    );
            }

            if ( TryAutoFillNumericRangeColumn(oVertexTable,
                oAutoFillUserSettings.VertexAlphaSourceColumnName,
                CommonTableColumnNames.Alpha,
                oAutoFillUserSettings.VertexAlphaDetails,
                out dSourceCalculationNumber1, out dSourceCalculationNumber2,
                out iDecimalPlaces
                ) )
            {
            oAutoFillWorkbookResults.VertexAlphaResults =
                new AutoFillNumericRangeColumnResults(
                    oAutoFillUserSettings.VertexAlphaSourceColumnName,
                    dSourceCalculationNumber1, dSourceCalculationNumber2,
                    iDecimalPlaces,
                    oAutoFillUserSettings.VertexAlphaDetails.DestinationNumber1,
                    oAutoFillUserSettings.VertexAlphaDetails.DestinationNumber2
                    );
            }

            AutoFillColumnViaCopy(oVertexTable,
            oAutoFillUserSettings.VertexLabelSourceColumnName,
            VertexTableColumnNames.Label
            );

            TryAutoFillColorColumn(oVertexTable,
            oAutoFillUserSettings.VertexLabelFillColorSourceColumnName,
            VertexTableColumnNames.LabelFillColor,
            oAutoFillUserSettings.VertexLabelFillColorDetails,
            out dSourceCalculationNumber1, out dSourceCalculationNumber2,
            out iDecimalPlaces
            );

            AutoFillColumnViaCopy(oVertexTable,
            oAutoFillUserSettings.VertexToolTipSourceColumnName,
            VertexTableColumnNames.ToolTip
            );

            AutoFillNumericComparisonColumn(oVertexTable,
            oAutoFillUserSettings.VertexVisibilitySourceColumnName,
            CommonTableColumnNames.Visibility,
            oAutoFillUserSettings.VertexVisibilityDetails
            );

            TryAutoFillNumericRangeColumn(oVertexTable,
            oAutoFillUserSettings.VertexLayoutOrderSourceColumnName,
            VertexTableColumnNames.LayoutOrder,
            oAutoFillUserSettings.VertexLayoutOrderDetails,
            out dSourceCalculationNumber1, out dSourceCalculationNumber2,
            out iDecimalPlaces
            );

            Boolean bXAutoFilled = TryAutoFillNumericRangeColumn(oVertexTable,
            oAutoFillUserSettings.VertexXSourceColumnName,
            VertexTableColumnNames.X,
            oAutoFillUserSettings.VertexXDetails,
            out dSourceCalculationNumber1, out dSourceCalculationNumber2,
            out iDecimalPlaces
            );

            Double dYSourceCalculationNumber1, dYSourceCalculationNumber2;

            Boolean bYAutoFilled = TryAutoFillNumericRangeColumn(oVertexTable,
            oAutoFillUserSettings.VertexYSourceColumnName,
            VertexTableColumnNames.Y,
            oAutoFillUserSettings.VertexYDetails,
            out dYSourceCalculationNumber1, out dYSourceCalculationNumber2,
            out iDecimalPlaces
            );

            if (bXAutoFilled && bYAutoFilled)
            {
            // (Note that the decimal places for the Y column take precedence
            // here.)

            oAutoFillWorkbookResults.VertexXResults =
                new AutoFillNumericRangeColumnResults(
                    oAutoFillUserSettings.VertexXSourceColumnName,
                    dSourceCalculationNumber1, dSourceCalculationNumber2,
                    iDecimalPlaces,
                    oAutoFillUserSettings.VertexXDetails.DestinationNumber1,
                    oAutoFillUserSettings.VertexXDetails.DestinationNumber2
                    );

            oAutoFillWorkbookResults.VertexYResults =
                new AutoFillNumericRangeColumnResults(
                    oAutoFillUserSettings.VertexYSourceColumnName,
                    dYSourceCalculationNumber1, dYSourceCalculationNumber2,
                    iDecimalPlaces,
                    oAutoFillUserSettings.VertexYDetails.DestinationNumber1,
                    oAutoFillUserSettings.VertexYDetails.DestinationNumber2
                    );
            }

            TryAutoFillNumericRangeColumn(oVertexTable,
            oAutoFillUserSettings.VertexPolarRSourceColumnName,
            VertexTableColumnNames.PolarR,
            oAutoFillUserSettings.VertexPolarRDetails,
            out dSourceCalculationNumber1, out dSourceCalculationNumber2,
            out iDecimalPlaces
            );

            TryAutoFillNumericRangeColumn(oVertexTable,
            oAutoFillUserSettings.VertexPolarAngleSourceColumnName,
            VertexTableColumnNames.PolarAngle,
            oAutoFillUserSettings.VertexPolarAngleDetails,
            out dSourceCalculationNumber1, out dSourceCalculationNumber2,
            out iDecimalPlaces
            );
        }
コード例 #5
0
        //*************************************************************************
        //  Constructor: AutoFillWorkbookDialog()
        //
        /// <overloads>
        /// Initializes a new instance of the <see cref="AutoFillWorkbookDialog" />
        /// class.
        /// </overloads>
        ///
        /// <summary>
        /// Initializes a new instance of the <see cref="AutoFillWorkbookDialog" />
        /// class with an AutoFillUserSettings object.
        /// </summary>
        ///
        /// <param name="workbook">
        /// Workbook containing the graph data.
        /// </param>
        ///
        /// <param name="mode">
        /// Indicates the mode in which the dialog is being used.
        /// </param>
        //*************************************************************************
        public AutoFillWorkbookDialog(
            Microsoft.Office.Interop.Excel.Workbook workbook,
            DialogMode mode
            )
            : this()
        {
            Debug.Assert(workbook != null);

            m_oWorkbook = workbook;
            m_eMode = mode;

            m_oAutoFillUserSettings = new AutoFillUserSettings(workbook);

            if (m_eMode == DialogMode.EditOnly)
            {
            this.Text += " Options";
            btnAutoFill.Text = "OK";
            btnClose.Text = "Cancel";

            // The column header text "When Autofill is clicked..." makes no
            // sense when the "Autofill" button text has been changed to "OK".

            lblSourceColumnHeader.Text =
                lblSourceColumnHeader.Text.Replace("clicked", "run");
            }

            // Instantiate an object that retrieves and saves the position of this
            // dialog.  Note that the object automatically saves the settings when
            // the form closes.

            m_oAutoFillWorkbookDialogUserSettings =
            new AutoFillWorkbookDialogUserSettings(this);

            // Initialize the ComboBoxes used to specify the data sources for the
            // edge and vertex table columns.

            InitializeEdgeComboBoxes(m_oWorkbook);
            InitializeVertexComboBoxes(m_oWorkbook);

            DoDataExchange(false);

            AssertValid();
        }