ASP.net中的Excel导入错误 [英] Excel Import Error in ASP.net

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

问题描述

我试图通过数据集从asp.net网站导入数据库的数据库。

这是我的第一部分。





I am trying to import an excel to databse from asp.net website through dataset.
here is my first part.


int xlColCount = 1;
       wb = app.Workbooks.Open(FilePath, 0, false, 5, "", "", true, Ex.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
       ws = (Ex.Worksheet)wb.ActiveSheet;
       xlColCount = ws.Columns.Count;
       xlColCount = ws.UsedRange.Columns.Count;


       ws.Columns.ClearFormats();

       xlColCount = ws.UsedRange.Columns.Count;

       //creating datacolumns
                   for (int i = 0; i < xlColCount; i++)
                   {

                       try
                       {
                           DSname.Tables[0].Columns.Add(((Ex.Range)ws.Cells[1,strColArr[i]]).Value2.ToString().Trim());
                       }
                       catch(Exception ex)
                       {
                           //error occured
                       }
                   }





首先我根据excel标题创建列名称到数据集列。其中xlColCount = 198(来自excel模板的总列数并且所有列都被填充)但是当达到第172列时(i = 172) )它给索引超出范围错误。



原因可能是什么。我需要创建一个包含所有excel coulmn名称的coulmn名称的数据集。



任何人请帮助它是紧急的....



first i am creating the column name based on the excel heading into dataset column.here xlColCount=198(total no.of columns from the excel template and all are filled ) but when reaching 172th column(i=172) it is giving index out of range error.

what could be the reason.I need to create a dataset with coulmn names from all excel coulmn names.

Anyone pls help it is urgent....

推荐答案

strColArr [i]阵列容量是问题所在。它初始化为171个大小。
strColArr[i] array capacity was the problem.It was initialized with 171 in size.


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

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