[英]Extract data from cell
The following code works fine , it extracts data from all cells in a sheet 以下代码可以正常工作,它从工作表中的所有单元格提取数据
using (OleDbConnection con1 = new OleDbConnection(connectionString))
{
var dt = new DataTable();
string query = string.Format("SELECT * FROM [{0}]", sheetName);
con1.Open();
OleDbDataAdapter adapter = new OleDbDataAdapter(query, con1);
adapter.Fill(dt);
try
{
using (SqlConnection con = new SqlConnection(consString))
{
con.Open();
for (int i = 1; i < dt.Rows.Count; i++)
{
for (int j = 1; j < dt.Columns.Count; j ++)
{
MessageBox.Show(dt.Rows[i][j].ToString());
}
}
}
The code above extract data in the green rectangle but I need to extract data in the red rectangle in the following picture . 上面的代码在绿色矩形中提取数据,但是在下图中,我需要在红色矩形中提取数据。
How could I extract data in the rectangle not in the green rectangle ? 如何提取矩形而不是绿色矩形中的数据?
You can change the displayed digits by changing region and setting in the control panel, this way full values will be displayed which can be fetched by OLEDB connection. 您可以通过更改区域和在控制面板中进行设置来更改显示的数字,这样将显示可通过OLEDB连接获取的完整值。 EDIT: After reading your commment abount not changing excel cell column format I will suggest trying EPPLUS.
编辑:阅读您的评论后,不更改excel单元格列格式,我建议尝试EPPLUS。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.