我正在通过我的Excel中的GridView数据绑定读取excel文件我有600列但是当excel数据与gridview绑定时它只显示250列如何在gridview中显示整个600列我正在使用此代码请查看它谢谢。
conStr = String.Format(conStr, FilePath, isHDR);
OleDbConnection connExcel = new OleDbConnection(conStr);
OleDbCommand cmdExcel = new OleDbCommand();
OleDbDataAdapter oda = new OleDbDataAdapter();
DataTable dt = new DataTable();
dt.MinimumCapacity = 242433;
cmdExcel.Connection = connExcel;
//Get the name of First Sheet
connExcel.Open();
DataTable dtExcelSchema;
dtExcelSchema = connExcel.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
string SheetName = dtExcelSchema.Rows[0]["TABLE_NAME"].ToString();
connExcel.Close();
//Read Data from First Sheet
connExcel.Open();
cmdExcel.CommandText = "SELECT * From [" + SheetName + "]";
oda.SelectCommand = cmdExcel;
oda.Fill(dt);
connExcel.Close();
//Bind Data to GridView
GridView1.Caption = Path.GetFileName(FilePath);
GridView1.DataSource = dt;
GridView1.DataBind();
答案 0 :(得分:1)
你使用microsoft.office.interop.excel扩展引用这里是一个例子来看看 http://www.devcurry.com/2009/07/import-excel-data-into-aspnet-gridview_06.html