btnOK_Click ( object sender, System.EventArgs e ) { if (!DoDataExchange(true)) { return; } try { ImportFromEdgeWorkbook(); } catch (ImportWorkbookException oImportWorkbookException) { this.ShowWarning(oImportWorkbookException.Message); return; } catch (Exception oException) { ErrorUtil.OnException(oException); return; } DialogResult = DialogResult.OK; this.Close(); }
btnOK_Click ( object sender, EventArgs e ) { AssertValid(); if (!DoDataExchange(true)) { return; } this.UseWaitCursor = true; try { GroupByVertexAttribute(); this.DialogResult = DialogResult.OK; this.Close(); } catch (Exception oException) { ErrorUtil.OnException(oException); } finally { this.UseWaitCursor = false; } }
TryExportToNodeXLGraphGallery ( Microsoft.Office.Interop.Excel.Workbook oWorkbook, NodeXLControl oNodeXLControl ) { Debug.Assert(oWorkbook != null); Debug.Assert(oNodeXLControl != null); ExportToNodeXLGraphGalleryUserSettings oExportToNodeXLGraphGalleryUserSettings = new ExportToNodeXLGraphGalleryUserSettings(); String sAuthor, sPassword; GetGraphGalleryAuthorAndPassword( oExportToNodeXLGraphGalleryUserSettings, out sAuthor, out sPassword); // Note that a graph summary is used for the description. try { (new NodeXLGraphGalleryExporter()).ExportToNodeXLGraphGallery( oWorkbook, oNodeXLControl, GraphTitleCreator.CreateGraphTitle(oWorkbook), GraphSummarizer.SummarizeGraph(oWorkbook), oExportToNodeXLGraphGalleryUserSettings.SpaceDelimitedTags, sAuthor, sPassword, oExportToNodeXLGraphGalleryUserSettings .ExportWorkbookAndSettings, oExportToNodeXLGraphGalleryUserSettings.ExportGraphML, oExportToNodeXLGraphGalleryUserSettings.UseFixedAspectRatio ); return(true); } catch (Exception oException) { String sMessage; if (NodeXLGraphGalleryExceptionHandler .TryGetMessageForRecognizedException( oException, out sMessage)) { FormUtil.ShowWarning(sMessage); } else { ErrorUtil.OnException(oException); } return(false); } }
GetRequiredTables ( Microsoft.Office.Interop.Excel.Workbook oWorkbook, out ListObject oEdgeTable, out ListObject oVertexTable ) { Debug.Assert(oWorkbook != null); AssertValid(); // Get the required table that contains edge data. GetEdgeTable() // checks for the required vertex name columns. EdgeWorksheetReader oEdgeWorksheetReader = new EdgeWorksheetReader(); oEdgeTable = oEdgeWorksheetReader.GetEdgeTable(oWorkbook); // Normally, the vertex table isn't required, but to avoid having to // create the table in code if it's missing, require it here. if (ExcelTableUtil.TryGetTable(oWorkbook, WorksheetNames.Vertices, TableNames.Vertices, out oVertexTable)) { // Make sure the vertex name column exists. ListColumn oColumn; if (!ExcelTableUtil.TryGetTableColumn(oVertexTable, VertexTableColumnNames.VertexName, out oColumn)) { oVertexTable = null; } } else { oVertexTable = null; } if (oVertexTable == null) { throw new WorkbookFormatException(String.Format( "To use this feature, there must be a worksheet named \"{0}\"" + " that contains a table named \"{1}\", and that table must" + " contain a column named \"{2}\"." + "\r\n\r\n" + "{3}" , WorksheetNames.Vertices, TableNames.Vertices, VertexTableColumnNames.VertexName, ErrorUtil.GetTemplateMessage() )); } }
GetEdgeTable ( Microsoft.Office.Interop.Excel.Workbook workbook ) { Debug.Assert(workbook != null); AssertValid(); // Get the worksheet that contains edge data. Worksheet oEdgeWorksheet; if (!ExcelUtil.TryGetWorksheet(workbook, WorksheetNames.Edges, out oEdgeWorksheet)) { OnWorkbookFormatError(String.Format( "The workbook must contain a worksheet named \"{0}\" that" + " contains edge data.\r\n\r\n{1}" , WorksheetNames.Edges, ErrorUtil.GetTemplateMessage() )); } // Get the table (ListObject) that contains edge data. ListObject oEdgeTable; if (!ExcelTableUtil.TryGetTable(oEdgeWorksheet, TableNames.Edges, out oEdgeTable)) { OnWorkbookFormatError(String.Format( "The worksheet named \"{0}\" must have a table named \"{1}\"" + " that contains edge data.\r\n\r\n{2}" , WorksheetNames.Edges, TableNames.Edges, ErrorUtil.GetTemplateMessage() )); } // Make sure the vertex name columns exist. GetTableColumnIndex(oEdgeTable, EdgeTableColumnNames.Vertex1Name, true); GetTableColumnIndex(oEdgeTable, EdgeTableColumnNames.Vertex2Name, true); return(oEdgeTable); }
StartImageCreation() { AssertValid(); Debug.Assert(m_oWorkbook != null); Debug.Assert(m_oSelectedVertexNames != null); // Read the workbook into a new IGraph. IGraph oGraph; try { oGraph = ReadWorkbook(m_oWorkbook); } catch (Exception oException) { ErrorUtil.OnException(oException); this.State = DialogState.Idle; return; } lblStatus.Text = "Creating subgraph images."; ICollection <IVertex> oSelectedVertices = new IVertex[0]; if (m_oCreateSubgraphImagesDialogUserSettings.SelectedVerticesOnly) { // Get the vertices corresponding to the selected rows in the // vertex worksheet. oSelectedVertices = GetSelectedVertices( oGraph, m_oSelectedVertexNames); } m_oSubgraphImageCreator.CreateSubgraphImagesAsync( oGraph, oSelectedVertices, m_oCreateSubgraphImagesDialogUserSettings.Levels, m_oCreateSubgraphImagesDialogUserSettings.SaveToFolder, m_oCreateSubgraphImagesDialogUserSettings.Folder, m_oCreateSubgraphImagesDialogUserSettings.ImageSizePx, m_oCreateSubgraphImagesDialogUserSettings.ImageFormat, m_oCreateSubgraphImagesDialogUserSettings.InsertThumbnails, m_oCreateSubgraphImagesDialogUserSettings.ThumbnailSizePx, m_oCreateSubgraphImagesDialogUserSettings.SelectedVerticesOnly, m_oCreateSubgraphImagesDialogUserSettings.SelectVertex, m_oCreateSubgraphImagesDialogUserSettings.SelectIncidentEdges, new GeneralUserSettings(), new LayoutUserSettings() ); }
OpenSampleNodeXLWorkbook() { // To create the sample workbook, an empty NodeXL workbook is created // from the NodeXL template, and then a GraphML file containing the // sample data is imported into it. It would be simpler to just // distribute a complete sample workbook with NodeXL, but that workbook // would have to be updated every time the NodeXL template changes. // This way, the latest template is always used. String sSampleNodeXLWorkbookSubfolderPath = Path.Combine( GetApplicationFolder(), SampleNodeXLWorkbookSubfolder); XmlDocument oGraphMLDocument = new XmlDocument(); try { oGraphMLDocument.Load(Path.Combine( sSampleNodeXLWorkbookSubfolderPath, SampleNodeXLWorkbookAsGraphMLFileName)); } catch (Exception oException) { ErrorUtil.OnException(oException); return; } // The sample workbook data contains placeholders for the path to the // image files used in the workbook. Replace those placeholders with a // real image path. String sImagePath = Path.Combine(sSampleNodeXLWorkbookSubfolderPath, SampleNodeXLWorkbookImageSubfolder); oGraphMLDocument.LoadXml(oGraphMLDocument.OuterXml.Replace( SampleNodeXLWorkbookImagePlaceholder, sImagePath)); try { GraphMLToNodeXLWorkbookConverter.SaveGraphToNodeXLWorkbook( oGraphMLDocument, null, null, null, false); } catch (ConvertGraphMLToNodeXLWorkbookException oConvertGraphMLToNodeXLWorkbookException) { FormUtil.ShowWarning( oConvertGraphMLToNodeXLWorkbookException.Message); } }
WriteGraphMetricColumnsToWorkbook ( GraphMetricColumn [] aoGraphMetricColumns ) { Debug.Assert(aoGraphMetricColumns != null); AssertValid(); Microsoft.Office.Interop.Excel.Application oApplication = m_oWorkbook.Application; GraphMetricWriter oGraphMetricWriter = new GraphMetricWriter(); oApplication.ScreenUpdating = false; try { oGraphMetricWriter.WriteGraphMetricColumnsToWorkbook( aoGraphMetricColumns, m_oWorkbook); if (m_bActivateRelevantWorksheetWhenDone) { // Let the user know that graph metrics have been calculated. oGraphMetricWriter.ActivateRelevantWorksheet( aoGraphMetricColumns, m_oWorkbook); } } catch (Exception oException) { oApplication.ScreenUpdating = true; ErrorUtil.OnException(oException); this.Close(); return; } oApplication.ScreenUpdating = true; }
OnLoad ( EventArgs e ) { AssertValid(); base.OnLoad(e); // Start the calculations. try { if (m_oGraphMetricCalculators != null) { // Use the specified graph metric calculators. m_oGraphMetricCalculationManager.CalculateGraphMetricsAsync( m_oGraph, m_oWorkbook, m_oGraphMetricCalculators); } else { // Use a default list of graph metric calculators. m_oGraphMetricCalculationManager.CalculateGraphMetricsAsync( m_oGraph, m_oWorkbook); } } catch (Exception oException) { // An exception was thrown from the synchronous code within // CalculateGraphMetricsAsync(). (Exceptions thrown from the // asynchronous code are handled by the // GraphMetricCalculationCompleted event handler.) ErrorUtil.OnException(oException); this.Close(); } }
TryAutoFillWorkbook ( ThisWorkbook oThisWorkbook ) { Debug.Assert(oThisWorkbook != null); try { WorkbookAutoFiller.AutoFillWorkbook( oThisWorkbook.InnerObject, new AutoFillUserSettings()); oThisWorkbook.OnWorkbookAutoFilled(false); return(true); } catch (Exception oException) { ErrorUtil.OnException(oException); return(false); } }
GraphMetricCalculationManager_GraphMetricCalculationCompleted ( object sender, RunWorkerCompletedEventArgs e ) { AssertValid(); Exception oException = e.Error; if (oException != null) { if (oException is GraphMetricException) { // This is a known exception. this.ShowWarning(oException.Message); } else { // The exception is unexpected. ErrorUtil.OnException(oException); } } else if (!e.Cancelled) { Debug.Assert(e.Result is GraphMetricColumn[]); WriteGraphMetricColumnsToWorkbook( ( GraphMetricColumn[] )e.Result); // Everything succeeded. this.DialogResult = DialogResult.OK; } this.Close(); }
GraphMLFilesImporter_ImportationCompleted ( object sender, RunWorkerCompletedEventArgs e ) { AssertValid(); EnableControls(); if (e.Cancelled) { } else if (e.Error != null) { Exception oException = e.Error; if (oException is ConvertGraphMLToNodeXLWorkbookException) { this.ShowWarning(oException.Message); } else { ErrorUtil.OnException(oException); } slStatusLabel.Text = String.Empty; } else { // The final status message is a summary of what was done. Show it // in a message box in addition to the StatusLabel. this.ShowInformation(slStatusLabel.Text); CheckForInvalidGraphMLFileNames(); this.Close(); } }
btnOK_Click ( object sender, EventArgs e ) { AssertValid(); if (!DoDataExchange(true)) { return; } if (m_eMode == DialogMode.Normal) { NodeXLGraphGalleryExporter oNodeXLGraphGalleryExporter = new NodeXLGraphGalleryExporter(); this.Cursor = Cursors.WaitCursor; try { Debug.Assert(m_oNodeXLControl != null); oNodeXLGraphGalleryExporter.ExportToNodeXLGraphGallery( m_oWorkbook, m_oNodeXLControl, txbTitle.Text, txbDescription.Text, m_oExportToNodeXLGraphGalleryUserSettings. SpaceDelimitedTags, m_oExportToNodeXLGraphGalleryUserSettings.Author, m_oExportToNodeXLGraphGalleryUserSettings.UseCredentials ? m_oPasswordUserSettings.NodeXLGraphGalleryPassword : null, m_oExportToNodeXLGraphGalleryUserSettings. ExportWorkbookAndSettings, m_oExportToNodeXLGraphGalleryUserSettings.ExportGraphML, m_oExportToNodeXLGraphGalleryUserSettings .UseFixedAspectRatio ); } catch (Exception oException) { String sMessage; if (NodeXLGraphGalleryExceptionHandler .TryGetMessageForRecognizedException(oException, out sMessage) ) { this.ShowWarning(sMessage); } else { ErrorUtil.OnException(oException); } return; } finally { this.Cursor = Cursors.Default; } } m_oExportToNodeXLGraphGalleryUserSettings.Save(); m_oPasswordUserSettings.Save(); this.DialogResult = DialogResult.OK; this.Close(); }
OnEdgeOrVertexTableSelectionChange ( Boolean bChangeInEdgeTable ) { AssertValid(); Sheets1And2Helper oSheets1And2Helper = bChangeInEdgeTable ? m_oEdgeWorksheet.Sheets1And2Helper : m_oVertexWorksheet.Sheets1And2Helper; if (IgnoreTableSelectionChange(oSheets1And2Helper)) { return; } m_bIgnoreSelectionEvents = true; try { // (The following comments are for the bChangeInEdgeTable=true // case. // Get an array of unique row IDs for all edge rows that have at // least one cell selected. ICollection <Int32> oSelectedRowIDs = oSheets1And2Helper.GetSelectedRowIDs(); // Select those edges (and possibly their adjacent vertices) in the // TaskPane. This will cause the TaskPane.SelectionChangedInGraph // event to fire, but this class will ignore it because // m_bIgnoreSelectionEvents is currently set to true. if (bChangeInEdgeTable) { m_oTaskPane.SetSelectedEdgesByRowID(oSelectedRowIDs); } else { m_oTaskPane.SetSelectedVerticesByRowID(oSelectedRowIDs); } // The selection in the vertex table may now be out of sync with // the TaskPane. Ideally, the vertex table would be updated right // now. However, you can't select rows in a worksheet that isn't // active. As a workaround, set a flag that will cause the // selection in the vertex table to be updated the next time the // vertex worksheet is activated. // // It would be possible to avoid deferring the selection by turning // off screen updating and temporarily selecting the vertex // worksheet. Selecting a worksheet is slow, however, even with // screen updating turned off. It takes about 250ms on a fast // machine. That's too slow to keep up with the user if he is // scrolling through a table with the down-arrow key, for example. if (bChangeInEdgeTable) { m_bUpdateVertexSelectionOnActivation = true; } else { m_bUpdateEdgeSelectionOnActivation = true; } // Selecting an edge or vertex invalidates any selected groups. m_bUpdateGroupSelectionOnActivation = true; // Enable the "set visual attribute" buttons in the Ribbon. m_oThisWorkbook.EnableSetVisualAttributes(); } catch (COMException) { // A user reported a bug in which Application.Intersect() throws a // COMException with an HRESULT of 0x800AC472. // (Application.Intersect() gets called indirectly by // OnSelectionChangedInTable().) The bug occurred while switching // windows. I couldn't reproduce the bug, but the following post // suggests that the HRESULT, which is VBA_E_IGNORE, occurs when an // object model call is made while the object model is "suspended." // // http://social.msdn.microsoft.com/forums/en-US/vsto/thread/ // 9168f9f2-e5bc-4535-8d7d-4e374ab8ff09/ // // Other posts also mention that it can occur during window // switches. // // I can't reproduce the bug and I'm not sure of the root cause, // but catching and ignoring the error should lead to nothing worse // than a mouse click being ignored. // // Update, May 2012: // // ExcelUtil.TryGetIntersection() now retries the // Application.Intersect() call if it fails with a COMException. // If it fails repeatedly, the exception will eventually get // rethrown here. } catch (Exception oException) { ErrorUtil.OnException(oException); } finally { m_bIgnoreSelectionEvents = false; } }
TryExportToEmail ( Microsoft.Office.Interop.Excel.Workbook oWorkbook, NodeXLControl oNodeXLControl ) { Debug.Assert(oWorkbook != null); Debug.Assert(oNodeXLControl != null); ExportToEmailUserSettings oExportToEmailUserSettings = new ExportToEmailUserSettings(); String sSmtpPassword = (new PasswordUserSettings()).SmtpPassword; if (!ExportToEmailUserSettingsAreComplete( oExportToEmailUserSettings, sSmtpPassword)) { FormUtil.ShowWarning( "The graph can't be exported to email because all required" + " email options haven't been specified yet. Go to NodeXL," + " Graph, Automate to fix this." ); return(false); } try { (new EmailExporter()).ExportToEmail( oWorkbook, oNodeXLControl, oExportToEmailUserSettings.SpaceDelimitedToAddresses.Split(' '), oExportToEmailUserSettings.FromAddress, GraphTitleCreator.CreateGraphTitle(oWorkbook), oExportToEmailUserSettings.MessageBody, oExportToEmailUserSettings.SmtpHost, oExportToEmailUserSettings.SmtpPort, oExportToEmailUserSettings.UseSslForSmtp, oExportToEmailUserSettings.SmtpUserName, sSmtpPassword, oExportToEmailUserSettings.ExportWorkbookAndSettings, oExportToEmailUserSettings.ExportGraphML, oExportToEmailUserSettings.UseFixedAspectRatio ); return(true); } catch (Exception oException) { String sMessage; if (EmailExceptionHandler.TryGetMessageForRecognizedException( oException, out sMessage)) { FormUtil.ShowWarning(sMessage); } else { ErrorUtil.OnException(oException); } return(false); } }
OnImageCreationCompleted ( RunWorkerCompletedEventArgs e ) { AssertValid(); Debug.Assert(m_oWorkbook != null); Debug.Assert(m_oSelectedVertexNames != null); if (e.Cancelled) { this.State = DialogState.Idle; lblStatus.Text = "Image creation stopped."; } else if (e.Error != null) { this.State = DialogState.Idle; Exception oException = e.Error; if (oException is System.IO.IOException) { lblStatus.Text = "Image creation error."; this.ShowWarning(oException.Message); } else { ErrorUtil.OnException(oException); } } else { // Success. Were temporary images created that need to be inserted // into the vertex worksheet? Debug.Assert(e.Result is TemporaryImages); TemporaryImages oTemporaryImages = (TemporaryImages)e.Result; if (oTemporaryImages.Folder != null) { // Yes. Insert them, then delete the temporary images. this.State = DialogState.PopulatingImageColumn; String sLastStatusFromSubgraphImageCreator = lblStatus.Text; lblStatus.Text = "Inserting subgraph thumbnails into the worksheet. Please" + " wait..."; SubgraphImageColumnPopulator.PopulateSubgraphImageColumn( m_oWorkbook, oTemporaryImages); lblStatus.Text = sLastStatusFromSubgraphImageCreator; } this.State = DialogState.Idle; if (m_eMode == DialogMode.Automate) { this.Close(); } } }
AutomateOneWorkbookIndirect ( String nodeXLWorkbookFilePath, String workbookSettings ) { Debug.Assert(!String.IsNullOrEmpty(nodeXLWorkbookFilePath)); Debug.Assert(!String.IsNullOrEmpty(workbookSettings)); // Ideally, the Excel API would be used here to open the workbook // and run the AutomateOneWorkbook() method on it. Two things // make that impossible: // // 1. When you open a workbook using // Application.Workbooks.Open(), you get only a native Excel // workbook, not an "extended" ThisWorkbook object. // // Although a GetVstoObject() extension method is available to // convert a native Excel workbook to an extended workbook, // that method doesn't work on a native workbook opened via // the Excel API -- it always returns null. // // It might be possible to refactor AutomateOneWorkbook() to // require only a native workbook. However, problem 2 would // still make things impossible... // // 2. If this method is being run from a modal dialog, which it // is (see AutomateTasksDialog), then code in the workbook // that needs to be automated doesn't run until the modal // dialog closes. // // The following code works around these problems. Microsoft.Office.Interop.Excel.Application oExcelApplication = null; ExcelApplicationKiller oExcelApplicationKiller = null; try { // Use a new Application object for each workbook. If the same // Application object is reused, the memory used by each // workbook is never released and the machine will eventually // run out of memory. oExcelApplication = new Microsoft.Office.Interop.Excel.Application(); if (oExcelApplication == null) { throw new Exception("Excel couldn't be opened."); } // ExcelApplicationKiller requires that the application be // visible. oExcelApplication.Visible = true; oExcelApplicationKiller = new ExcelApplicationKiller( oExcelApplication); // Store an "automate tasks on open" flag in the workbook, // indicating that task automation should be run on it the next // time it's opened. This can be done via the Excel API. Microsoft.Office.Interop.Excel.Workbook oWorkbookToAutomate = ExcelUtil.OpenWorkbook(nodeXLWorkbookFilePath, oExcelApplication); PerWorkbookSettings oPerWorkbookSettings = new PerWorkbookSettings(oWorkbookToAutomate); oPerWorkbookSettings.WorkbookSettings = workbookSettings; oPerWorkbookSettings.AutomateTasksOnOpen = true; oWorkbookToAutomate.Save(); oWorkbookToAutomate.Close(false, Missing.Value, Missing.Value); oExcelApplication.Quit(); } catch (Exception oException) { ErrorUtil.OnException(oException); return; } finally { // Quitting the Excel application does not remove it from // memory. Kill its process. oExcelApplicationKiller.KillExcelApplication(); oExcelApplication = null; oExcelApplicationKiller = null; } try { // Now open the workbook in another instance of Excel, which // bypasses problem 2. Code in the workbook's Ribbon will // detect the flag's presence, run task automation on it, close // the workbook, and close the other instance of Excel. OpenWorkbookToAutomate(nodeXLWorkbookFilePath, 60 * 60); } catch (Exception oException) { ErrorUtil.OnException(oException); return; } }
btnCustomizeVertexMenu_Click ( object sender, EventArgs e ) { AssertValid(); const String Message = "Use this to add custom menu items to the menu that appears when" + " you right-click a vertex in the graph pane." + "\r\n\r\n" + "Clicking \"Yes\" below will add a pair of columns to the" + " Vertices worksheet -- one for menu item text and another for" + " the action to take when the menu item is selected." + "\r\n\r\n" + "For example, if you add the column pair and enter \"Send Mail" + " To\" for a vertex's menu item text and \"mailto:[email protected]\"" + " for the action, then right-clicking the vertex in the NodeXL" + " graph and selecting \"Send Mail To\" from the right-click menu" + " will open a new email message addressed to [email protected]." + "\r\n\r\n" + "If you want to open a Web page when the menu item is selected," + " enter an URL for the action." + "\r\n\r\n" + "If you want to add more than one custom menu item to a vertex's" + " right-click menu, run this again to add another pair of" + " columns." + "\r\n\r\n" + "Do you want to add a pair of columns to the Vertices worksheet?" ; if (MessageBox.Show(Message, this.ApplicationName, MessageBoxButtons.YesNo, MessageBoxIcon.Information) != DialogResult.Yes) { return; } // Create and use the object that adds the columns to the vertex // table. TableColumnAdder oTableColumnAdder = new TableColumnAdder(); this.UseWaitCursor = true; try { oTableColumnAdder.AddColumnPair(m_oWorkbook, WorksheetNames.Vertices, TableNames.Vertices, VertexTableColumnNames.CustomMenuItemTextBase, CustomMenuItemTextColumnWidth, VertexTableColumnNames.CustomMenuItemActionBase, CustomMenuItemActionColumnWidth ); this.UseWaitCursor = false; } catch (Exception oException) { this.UseWaitCursor = false; ErrorUtil.OnException(oException); } }
btnOK_Click ( object sender, System.EventArgs e ) { if (!DoDataExchange(true)) { return; } m_oAutomateTasksUserSettings.Save(); try { if (m_eMode == DialogMode.EditOnly) { // (Just close the dialog.) } else if (m_oAutomateTasksUserSettings.AutomateThisWorkbookOnly) { Debug.Assert(m_oNodeXLControl != null); TaskAutomator.AutomateOneWorkbook(m_oThisWorkbook, m_oNodeXLControl, m_oAutomateTasksUserSettings.TasksToRun, m_oAutomateTasksUserSettings.FolderToSaveWorkbookTo); } else { // The user settings for this workbook will be used for and // stored in each workbook in the specified folder. CommandDispatcher.SendCommand(this, new RunNoParamCommandEventArgs( NoParamCommand.SaveUserSettings)); String sWorkbookSettings = (new PerWorkbookSettings( m_oThisWorkbook.InnerObject)).WorkbookSettings; TaskAutomator.AutomateFolder( m_oAutomateTasksUserSettings.FolderToAutomate, sWorkbookSettings); } } catch (UnauthorizedAccessException oUnauthorizedAccessException) { // This occurs when a workbook is read-only. this.ShowWarning( "A problem occurred while running tasks. Details:" + "\r\n\r\n" + oUnauthorizedAccessException.Message ); return; } catch (Exception oException) { ErrorUtil.OnException(oException); return; } this.DialogResult = DialogResult.OK; this.Close(); }
ImportGraph ( IGraph sourceGraph, String [] edgeAttributes, String [] vertexAttributes, Boolean clearTablesFirst, Microsoft.Office.Interop.Excel.Workbook destinationNodeXLWorkbook ) { Debug.Assert(sourceGraph != null); Debug.Assert(destinationNodeXLWorkbook != null); if (clearTablesFirst) { NodeXLWorkbookUtil.ClearAllNodeXLTables(destinationNodeXLWorkbook); } // Get the required table that contains edge data. GetEdgeTable() // throws an exception if the table is missing. EdgeWorksheetReader oEdgeWorksheetReader = new EdgeWorksheetReader(); ListObject oEdgeTable = oEdgeWorksheetReader.GetEdgeTable(destinationNodeXLWorkbook); // Get the required columns. Range oVertex1NameColumnData = null; Range oVertex2NameColumnData = null; if ( !ExcelTableUtil.TryGetTableColumnData(oEdgeTable, EdgeTableColumnNames.Vertex1Name, out oVertex1NameColumnData) || !ExcelTableUtil.TryGetTableColumnData(oEdgeTable, EdgeTableColumnNames.Vertex2Name, out oVertex2NameColumnData) ) { ErrorUtil.OnMissingColumn(); } // Import the edges and their attributes into the workbook. ImportEdges(sourceGraph, edgeAttributes, oEdgeTable, oVertex1NameColumnData, oVertex2NameColumnData, !clearTablesFirst); // Populate the vertex worksheet with the name of each unique vertex in // the edge worksheet. (new VertexWorksheetPopulator()).PopulateVertexWorksheet( destinationNodeXLWorkbook, false); // Get the table that contains vertex data. ListObject oVertexTable; Range oVertexNameColumnData = null; Range oVisibilityColumnData = null; if ( !ExcelTableUtil.TryGetTable(destinationNodeXLWorkbook, WorksheetNames.Vertices, TableNames.Vertices, out oVertexTable) || !ExcelTableUtil.TryGetTableColumnData(oVertexTable, VertexTableColumnNames.VertexName, out oVertexNameColumnData) || !ExcelTableUtil.TryGetTableColumnData(oVertexTable, CommonTableColumnNames.Visibility, out oVisibilityColumnData) ) { ErrorUtil.OnMissingColumn(); } // Import isolated vertices and the attributes for all the graph's // vertices. ImportVertices(sourceGraph, vertexAttributes, oVertexTable, oVertexNameColumnData, oVisibilityColumnData); }
Open() { Debug.Assert(m_oDynamicFilterSettingsTable == null); AssertValid(); // Get the table that contains the dynamic filter settings. if (!ExcelTableUtil.TryGetTable(m_oWorkbook, WorksheetNames.Miscellaneous, TableNames.DynamicFilterSettings, out m_oDynamicFilterSettingsTable)) { OnWorkbookFormatError(String.Format( "A table that is required to use this feature is missing." + "\r\n\r\n{0}" , ErrorUtil.GetTemplateMessage() )); } foreach (ExcelTableReader.ExcelTableRow oRow in (new ExcelTableReader(m_oDynamicFilterSettingsTable)).GetRows()) { String sTableName, sColumnName; Double dSelectedMinimum, dSelectedMaximum; if ( oRow.TryGetNonEmptyStringFromCell( DynamicFilterSettingsTableColumnNames.TableName, out sTableName) && oRow.TryGetNonEmptyStringFromCell( DynamicFilterSettingsTableColumnNames.ColumnName, out sColumnName) && oRow.TryGetDoubleFromCell( DynamicFilterSettingsTableColumnNames.SelectedMinimum, out dSelectedMinimum) && oRow.TryGetDoubleFromCell( DynamicFilterSettingsTableColumnNames.SelectedMaximum, out dSelectedMaximum) ) { // Create a SettingsForOneFilter object for each filter and // store it in a dictionary. SettingsForOneFilter oSettingsForOneFilter = new SettingsForOneFilter(); oSettingsForOneFilter.SelectedMinimum = (Decimal)dSelectedMinimum; oSettingsForOneFilter.SelectedMaximum = (Decimal)dSelectedMaximum; oSettingsForOneFilter.SelectedMinimumAddress = ExcelUtil.GetRangeAddressAbsolute( oRow.GetRangeForCell( DynamicFilterSettingsTableColumnNames.SelectedMinimum) ); oSettingsForOneFilter.SelectedMaximumAddress = ExcelUtil.GetRangeAddressAbsolute( oRow.GetRangeForCell( DynamicFilterSettingsTableColumnNames.SelectedMaximum) ); m_oDynamicFilterSettingsDictionary.Add( GetDictionaryKey(sTableName, sColumnName), oSettingsForOneFilter); } } }
AddColumnPair ( Microsoft.Office.Interop.Excel.Workbook workbook, String worksheetName, String tableName, String column1NameBase, Double column1WidthChars, String column2NameBase, Double column2WidthChars ) { Debug.Assert(workbook != null); Debug.Assert(!String.IsNullOrEmpty(worksheetName)); Debug.Assert(!String.IsNullOrEmpty(tableName)); Debug.Assert(!String.IsNullOrEmpty(column1NameBase)); Debug.Assert(column1WidthChars == ExcelTableUtil.AutoColumnWidth || column1WidthChars >= 0); Debug.Assert(!String.IsNullOrEmpty(column2NameBase)); Debug.Assert(column2WidthChars == ExcelTableUtil.AutoColumnWidth || column2WidthChars >= 0); AssertValid(); ListObject oTable; if (!ExcelTableUtil.TryGetTable(workbook, worksheetName, tableName, out oTable)) { throw new WorkbookFormatException(String.Format( "To use this feature, there must be a worksheet named \"{0}\"" + " that contains a table named \"{1}\"." + "\r\n\r\n" + "{2}" , worksheetName, tableName, ErrorUtil.GetTemplateMessage() )); } Int32 iMaximumAppendedNumber = Math.Max( GetMaximumAppendedNumber(oTable, column1NameBase), GetMaximumAppendedNumber(oTable, column2NameBase) ); if (iMaximumAppendedNumber != 0) { String sStringToAppend = " " + (iMaximumAppendedNumber + 1).ToString(); column1NameBase += sStringToAppend; column2NameBase += sStringToAppend; } ListColumn oListColumn1, oListColumn2; if ( !ExcelTableUtil.TryAddTableColumn(oTable, column1NameBase, column1WidthChars, null, out oListColumn1) || !ExcelTableUtil.TryAddTableColumn(oTable, column2NameBase, column2WidthChars, null, out oListColumn2) ) { FormUtil.ShowWarning("The columns weren't added."); } ExcelUtil.ActivateWorksheet(oTable); }
btnOK_Click ( object sender, System.EventArgs e ) { AssertValid(); if (!DoDataExchange(true)) { return; } this.Cursor = Cursors.WaitCursor; Exception oExpectedException = null; try { OpenUcinetFile(); } catch (IOException oIOException) { oExpectedException = oIOException; } catch (UnauthorizedAccessException oUnauthorizedAccessException) { oExpectedException = oUnauthorizedAccessException; } catch (FormatException oFormatException) { oExpectedException = oFormatException; } catch (Exception oUnexpectedException) { ErrorUtil.OnException(oUnexpectedException); return; } finally { this.Cursor = Cursors.Default; } if (oExpectedException != null) { String sMessage = "The file could not be opened. Details:\n\n" + oExpectedException.Message; if (oExpectedException is FormatException) { sMessage += "\n\nThis does not appear to be a UCINET full matrix DL" + " file. " + FormatMessage ; } this.ShowWarning(sMessage); return; } DialogResult = DialogResult.OK; this.Close(); }
btnOK_Click ( object sender, EventArgs e ) { AssertValid(); if (!DoDataExchange(true)) { return; } if (m_eMode == DialogMode.Normal) { this.Cursor = Cursors.WaitCursor; try { (new EmailExporter()).ExportToEmail( m_oWorkbook, m_oNodeXLControl, m_oExportToEmailUserSettings .SpaceDelimitedToAddresses.Split(' '), m_oExportToEmailUserSettings.FromAddress, txbSubject.Text, m_oExportToEmailUserSettings.MessageBody, m_oExportToEmailUserSettings.SmtpHost, m_oExportToEmailUserSettings.SmtpPort, m_oExportToEmailUserSettings.UseSslForSmtp, m_oExportToEmailUserSettings.SmtpUserName, m_oPasswordUserSettings.SmtpPassword, m_oExportToEmailUserSettings.ExportWorkbookAndSettings, m_oExportToEmailUserSettings.ExportGraphML, m_oExportToEmailUserSettings.UseFixedAspectRatio ); } catch (Exception oException) { String sMessage; if (EmailExceptionHandler .TryGetMessageForRecognizedException(oException, out sMessage)) { if (oException is EmailAddressFormatException) { switch (((EmailAddressFormatException)oException) .EmailAddressType) { case EmailAddressType.To: OnInvalidTextBox(txbToAddresses, sMessage); break; case EmailAddressType.From: OnInvalidTextBox(txbFromAddress, sMessage); break; default: Debug.Assert(false); break; } } else { this.ShowWarning(sMessage); } } else { ErrorUtil.OnException(oException); } return; } finally { this.Cursor = Cursors.Default; } } m_oExportToEmailUserSettings.Save(); m_oPasswordUserSettings.Save(); this.DialogResult = DialogResult.OK; this.Close(); }