将Excel文件导入datagridview [英] importing of Excel file to datagridview

查看:194
本文介绍了将Excel文件导入datagridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含2列的excel文件?我想获得一列和该列的所有行,然后第二列和该列的所有行以及这两列应该连续12列





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


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);


                      }
                  }

推荐答案

请参阅此处,

http://stackoverflow.com/questions/16293643/import-excel-to-datagridview [ ^ ]


这篇关于将Excel文件导入datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆