C#读取excel到dataGridView问题,求指点

.Net技术 码拜 9年前 (2016-04-30) 1202次浏览
有一个这样的表,本人需要把红线和红色框内的数据截取出来作为列怎么做?剩余的数据全部不要。
本人是新手,只会把数据读取到winform的dataGridView控件里显示出来了,
但是本人想把里面需要的十三列读取出来显示到dataGridView里,最后插入SQLserver里。
求高手解答C#读取excel到dataGridView问题,求指点
C#读取excel到dataGridView问题,求指点C#读取excel到dataGridView问题,求指点
表里面的一些数据:
中国银联直联商户清算交易明细表
商户编号:      302440382493001         商户名称:      深圳市深港机动车驾驶培        收单机构:    中信银行深圳分行
清算日期:      20160217                生成日期:        20160218
终端编号     交易日期时间   主账号                  发卡行                          交易金额      商户费用          结算金额  系统参考号     系统跟踪号   交易渠道          交易类型
______________________________________________________________________________________________________________________________________________________________________________________________________

30231134    0217092831      601382*********7279     中国银行                         5566.00        -26.00           5540.00  000001000388  699223        有线销售点终端(P  消费
30231134    0217152922      621485******9281        招商银行                         7566.00        -26.00           7540.00  000001000389  191137        有线销售点终端(P  消费
30231135    0217102709      518718******8825        招商银行深圳分行                  300.00         -1.89            298.11  000001000500  023480        有线销售点终端(P  消费
30231135    0217125648      601382*********6609     中国银行                         5566.00        -26.00           5540.00  000001000501  098341        有线销售点终端(P  消费
30231135    0217141952      621081*********5404     建设银行                         5566.00        -26.00           5540.00  000001000502  141990        有线销售点终端(P  消费
30231135    0217184543      621226*********5388     工商银行深圳分行                 5566.00        -26.00           5540.00  000001000503  327981        有线销售点终端(P  消费
30231135    0217184648      438088******3989        中国银行                         5566.00        -26.00           5540.00  000001000504  334004        有线销售点终端(P  消费
30231136    0217152601      622576******2553        招商银行                         5566.00        -26.00           5540.00  000001000200  187594        有线销售点终端(P  消费
30231137    0217114015      434910******7686        交通银行                         2000.00        -12.60           1987.40  000001000443  063053        有线销售点终端(P  消费
30231171    0217183319      621483******5274        招商银行                         1432.00         -9.02           1422.98  000001000306  318772        有线销售点终端(P  消费
30231181    0217194711      622202*********0297     工商银行深圳分行                10932.00        -26.00          10906.00  000001000068  367771        有线销售点终端(P  消费
30231182    0217125618      622202*********6045     工商银行深圳分行                 5566.66        -26.00           5540.66  000001000371  100473        有线销售点终端(P  消费
30231182    0217153108      621798*********0902     邮储银行                         5566.00        -26.00           5540.00  000001000372  191180        有线销售点终端(P  消费
30231182    0217153202      621798*********0902     邮储银行                         5566.00        -26.00           5540.00  000001000373  193925        有线销售点终端(P  消费
30231182    0217161207      458123******4487        交通银行                         5880.00        -26.00           5854.00  000001000374  221277        有线销售点终端(P  消费
终端编号                  交易笔数                交易金额          商户费用        结算金额
____________________________________________________________________________________________
30231134                  2                       13132.00            -52.00        13080.00
30231135                  5                       22564.00           -105.89        22458.11
30231136                  1                        5566.00            -26.00         5540.00
30231137                  4                       18798.00            -87.07        18710.93
30231138                  3                       11712.00            -53.76        11658.24
30231139                  2                       11732.00            -52.00        11680.00
30231142                  2                       11132.00            -52.00        11080.00
30231143                  1                        5566.00            -26.00         5540.00
30231149                  1                           0.00              0.00            0.00
30231152                  3                       19412.00            -78.00        19334.00

解决方案

45

这个很简单啊,你现在遇到什么问题?不会读取excel还是怎样?

5

找到这些数据的行列坐标,然后取值
Excel.Application xApp = new Excel.ApplicationClass();
Excel.Workbook xBook = xApp.Workbooks.Open(filePath,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);
xApp.Visible = false;
Excel._Worksheet sh = (Excel._Worksheet)xApp.Worksheets.get_Item(1);
int i = 2;
while (((Excel.Range)sh.Cells[i, 1]).Text.ToString() != “”)
{
((Excel.Range)sh.Cells[i, 1]).Text.ToString();
i++;
}

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明C#读取excel到dataGridView问题,求指点
喜欢 (1)
[1034331897@qq.com]
分享 (0)