CreateVertexNames
(
Microsoft.Office.Interop.Excel.Worksheet oSourceWorksheet
)
{
Debug.Assert(oSourceWorksheet != null);
AssertValid();
String sA1String;
if ( !ExcelUtil.TryGetNonEmptyStringFromCell(oSourceWorksheet, 1, 1,
out sA1String) )
{
OnInvalidSourceWorkbook(
"In a matrix workbook that does not have vertex names, the"
+ " first edge weight number must be in A1.",
oSourceWorksheet, 1, 1
);
}
// To determine the size of the matrix, get the first row of edge
// weights.
Object [,] aoEdgeWeights;
if ( !ExcelUtil.TryGetContiguousValuesInRow(oSourceWorksheet, 1, 1,
out aoEdgeWeights) )
{
Debug.Assert(false);
}
Int32 iColumns = aoEdgeWeights.GetUpperBound(1);
// Compare to the first column of edge weights.
if ( !ExcelUtil.TryGetContiguousValuesInColumn(oSourceWorksheet, 1, 1,
out aoEdgeWeights) )
{
Debug.Assert(false);
}
Int32 iRows = aoEdgeWeights.GetUpperBound(0);
if (iRows != iColumns)
{
OnInvalidSourceWorkbook( String.Format(
"The matrix workbook must have an equal number of rows and"
+ " columns. Judging from the first empty cell in column 1"
+ " and the first empty cell in row 1, it looks like there"
+ " are {0} {1} and {2} {3}."
,
iRows,
StringUtil.MakePlural("row", iRows),
iColumns,
StringUtil.MakePlural("column", iColumns)
),
oSourceWorksheet, 1, 1
);
}
// Generate the vertex names.
String [] asVertexNames = new String[iRows];
for (Int32 i = 0; i < iRows; i++)
{
asVertexNames[i] = "Vertex " + (i + 1).ToString();
}
return (asVertexNames);
}