Hi all,

Thanks for any help you can give... this has been bugging me for a while.

I have a table that has 2 rows that are used for column headings.  However, 
some cells span more than one cell.  This results in the incorrect calculation 
of the column.

Instead of using a "hard coded" index value, I am using a method that finds the 
column by heading text and then uses that as the index to reference the cell.  
This way if I add or delete columns my code wont break.

But because the header row is made of 2 rows not 1, and the cells might span 
more than 1 cell, the calculation is wrong.

EG:
row1 header:  4 cells - "ID", "Desc", "Cost", "Savings"
row2 header:  4 cells - "", "Album Title", "Artist", "Year", "Format", "", ""

  in header row2, "Description" spans several cells:  "Album Title", "Artist", 
"Year", "Format"

Data row: 7 cells - "ID", "Album Title", "Artist", "Year", "Format", "Cost", 
"Savings"

So the data row contains a total of 7 columns.  And If i look for "Cost" it 
will give me an index of 3, but when I use that index to get my value I get the 
"Artist" cell value.

I tried getting column_count() but each row returns 4, so that is not helping.

Here is code for my Find column index.  It returns column index or nil if not 
found.

  def find_table_column(tableName, columnName)
    tableName = convertToRegex(tableName)
    columnName = convertToRegex(columnName)
    count = 0
    col = nil
    [EMAIL PROTECTED] { |t| t.text =~ /#{tableName}/ }
    header_row = t.rows.find { |r| r.text =~ /#{columnName}/ }
    if (header_row)
      header_row.each { |cell| 
        count += 1
        if ((cell ? cell.text : '') =~ /#{columnName}/i ) 
          col = count
        end
      }
    end
    return col
  end

EG 2:
In the first example, it could be fixed by just replacing "Desc" with the 4 
columns, but that is not available to me.  In addition, i have tables that work 
the other way,  several cells in the 1st row are spanned by 1 cell in the 2nd 
row.

So a solution should cover both these cases.
Thanks again for any input.

Qaos!
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.openqa.org/thread.jspa?threadID=6897&messageID=19883#19883
_______________________________________________
Wtr-general mailing list
Wtr-general@rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general

Reply via email to