Click here to Skip to main content
15,899,935 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a datatable that was imported from excel. Because of how it gets imported I need to Name the Columns based on the entries on the first row.
foreach (DataColumn c in spreadsheet.WorkbookData.Tables[0].Columns)
            {

                string cellValue = spreadsheet.WorkbookData.Tables[0].Rows[0][c].ToString();
                spreadsheet.WorkbookData.Tables[0].Columns[c.ToString()].ColumnName = cellValue;
            }

This works great, but when it hits a certain point the column names would start repeating. I want to make it so I just do a "m_" + cellValue when I come to where it starts repeating. I know where it starts repeating(I can open the excel file), but I want to be able to find that point based on a search(in this case at the second occurrence of "EDI_Std_Nomenclature") so the user could update the table if it ever changed.
Posted
Updated 5-Jan-10 20:33pm
v2

1 solution

If I understood the question right, you might try spreadsheet.WorkbookData.Tables[0].Columns[c.ToString()].Ordinal, which returns the position of the column
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900