C# .net 从 .xls 读取缺少内容为 1 的单元格
我尝试使用 oledb 从 xls 文件读取数据。该工作表有一列,所有单元格中都有数字。当我执行代码时,每次都会缺少特定的列。我使用的代码是:
OleDbConnection excel_connection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + file_name + ";Extended Properties=Excel 8.0");
excel_connection.Open();
DataSet excel_data = new DataSet();
OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT * FROM [XX$]", excel_connection);
myCommand.Fill(excel_data);
excel_connection.Close();
int index = 0;
string excel_columns;
foreach (DataRow excel_row in excel_data.Tables[0].Rows)
{
excel_columns = String.Join(",", cells);
richTextBox1.AppendText(excel_columns);
}
为什么会发生这种情况?
I tried to read data from a xls file using oledb. The sheet had a column which has numbers in all the cells. When I executed the code that particular column alone is missing everytime. The code I used is:
OleDbConnection excel_connection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + file_name + ";Extended Properties=Excel 8.0");
excel_connection.Open();
DataSet excel_data = new DataSet();
OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT * FROM [XX$]", excel_connection);
myCommand.Fill(excel_data);
excel_connection.Close();
int index = 0;
string excel_columns;
foreach (DataRow excel_row in excel_data.Tables[0].Rows)
{
excel_columns = String.Join(",", cells);
richTextBox1.AppendText(excel_columns);
}
Why is this happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我曾经像你一样阅读 Excel 文档,但我一直遇到列格式问题,所以我决定切换到 NPOI 。
这是一个很好的产品并且效果很好。实施非常非常容易。
这是一些代码:
I used to read Excel document like you do but I kept having problems with column formats so I decided to switch to NPOI.
It is a good product and works pretty well. The implementation is very very easy.
Here is some code: