Column titles on row #0

Mar 8, 2010 at 2:20 PM
Edited Mar 8, 2010 at 5:44 PM

I'm using the following code to validate a worksheet that has been selected by the user. Except for the first column; "Status", none of the other columns are being found. The .IndexOf() method is returning "-1". However, looking at the contents of the list in the debugger and the contents of the columnTitle and columnIndex variables are what they should be, including case. My question is this... is NPOI doing something wierd? Here's another thing... if I remove all the spaces from the column titles in the generic list; i.e. "Project ID #" := "ProjectID#", and do the same when I retrieve the columnTitle, all columns are found w/o any problems. Has anyone else run into this oddity?


        HSSFSheet ws = this.openWorksheet(xlsFile, 1);
        HSSFRow row = ws.GetRow(0);

        List<string> columnTitles = new List<string>();
        columnTitles.Add("Project ID #");
        columnTitles.Add("Project Name");
        columnTitles.Add("Owner Name");
        columnTitles.Add("Start Year");
        columnTitles.Add("Total AIS Value");
        columnTitles.Add("Total Capital");
        columnTitles.Add("Total O&M");
        columnTitles.Add("Financial Value");
        columnTitles.Add("Business Value");
        columnTitles.Add("Stakeholders Value");
        columnTitles.Add("Strategic Alignment Value");
        columnTitles.Add("System Value");

        foreach (HSSFCell cell in row)
          // get the contents of the column, and it's offset in the row
          string columnTitle = cell.ToString();
          int columnIndex = cell.ColumnIndex;

          // if column not found at the expected position...
          // except for the 1st column; "Status", none of the other columns are being found; .IndexOf() is returning -1
          if (columnTitles.IndexOf(columnTitle) != columnIndex)
            Debug.WriteLine(string.Format("Column \"{0}\" not found in list, expected at index {1}", columnTitle, columnIndex));
            //throw new ArgumentException(string.Format("{0} is not in the expected format", Path.GetFileName(xlsFile)));