Click here to Skip to main content
15,904,817 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i need to create a function that will capture the values which user pasted from excel. i only able to get the first row, however how to get the second row and onward?

this is my code:
C#
protected void btnSubmit_Click(object sender, EventArgs e)
{
    string rowA, rowB, rowC;

    string str = this.TextBox1.Text;
    string[] tokens = str.Split('\t');
    string retVal = tokens[0] + " " + tokens[1];
    rowA = retVal; //result for first row
    rowB = "";     //result for second row
    rowC = "";     //result for third row
}


sample Data user paste from excel:
User ID	Column1	Column2	Column3	Column4
1	100	120	110	80
2	80	90	95	115


Expected result:
rowA = 210 (Column1 + Column3, 001 only)
rowB = 185 (Column2 + Column3, 002 only)
if u notice, the calculation for rowA and rowB is different, the formula is already predefined

please help me, thanks :)
Posted
Updated 5-May-14 5:13am
v2

you may have multiple lines

C#
string[] rows = TextBox1.Text.Split (new string[]{System.Environment.NewLine}, StringSplitOptions.None );
string[] row1 = rows[1].Split();
var rowA  = int.Parse(row1[1]) +int.Parse(row1[3]);
string[] row2 = rows[2].Split();
var rowB  = int.Parse(row2[2]) +int.Parse(row2[3]);
 
Share this answer
 
v2
Comments
melvintcs 5-May-14 9:06am    
thank you. but the result return the whole row.
how to get the data for only 'second row with second column'?
DamithSL 5-May-14 10:22am    
can you update the question with sample data in text box and what you expected as rowa, rowB, RowC etc..
melvintcs 5-May-14 11:13am    
updated, please check :)
Try
C#
rowA = tokens[0]; //result for first row
rowB = tokens[1];     //result for second row
rowC = tokens[2];     //result for third row
 
Share this answer
 
Comments
melvintcs 4-May-14 23:47pm    
tokens[0] is column 1 not row 1

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