且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在c#中的datagridview中打开excel文件

更新时间:2023-02-08 14:04:55

,con); // 获取数据

dt = new DataTable();

da.Fill(dt); // 将数据保存或放入数据表
.dataGridView1.DataSource = dt; / / 在网格视图中显示表格
", con);//get the data dt = new DataTable(); da.Fill(dt);//save or put the data in data table this.dataGridView1.DataSource = dt;//show the table in grid view


Excel表格看起来像什么?



L只有整个表在A1中开始,数据列之间没有空列且数据行之间没有空行,Excel表中的oading数据才有效。



如果您试图在整个地方加载包含数据和文本的整个工作表,那么它就不会起作用。它只会加载看起来像表格的数据。
What does you Excel sheet look like?

Loading data from an Excel sheet will only work so long as the entire table starts in A1, has no empty columns between columns of data and no empty rows between rows of data.

If you're trying to load the entire sheet with data and text all over the place, it's not going to work. It will only load data that looks like a table.