Click here to Skip to main content
15,886,075 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have an excel file with 2 columns ? iwant to get one column and all the rows of that column and then second column and all the rows of that column and those two column should continuously for 12 columns


C#
for (int Cnum = 1; Cnum <= ShtRange.Columns.Count; Cnum++)
              {

                  if (Cnum == 1)
                  {
                      dt.Columns.Add((ShtRange.Cells[1, Cnum] as Excel.Range).Value2.ToString());
                      for (int Rnum = 1; Rnum <= 9; Rnum++)
                      {
                          dt.Rows.Add((ShtRange.Cells[Rnum, 1] as Excel.Range).Value2.ToString());

                      }
                  }
                  else if (Cnum == 2)
                  {

                      dt.Columns.Add((ShtRange.Cells[1, Cnum] as Excel.Range).Value2.ToString());


                      for (int Rnum = 1; Rnum <= 9; Rnum++)
                      {

                          dt.Rows.Add((ShtRange.Cells[Rnum, Cnum] as Excel.Range).Value2);


                      }
                  }
Posted

1 solution

 
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