如何使用Microsoft OLE DB提供程序读取cell.Value而不是Cell.text [英] How to read cell.Value instead of Cell.text using Microsoft OLE DB Provider

查看:45
本文介绍了如何使用Microsoft OLE DB提供程序读取cell.Value而不是Cell.text的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用  Microsoft.ACE.OLEDB.12.0读取Excel。

Am trying to read an excel using Microsoft.ACE.OLEDB.12.0.

有几个在某些情况下,值可以是字母数字的列,在某些情况下,这些值可以在excel中转​​换为科学记数法。

There are a few columns where the values can be alphanumeric in some case and in some cases a very long number which gets converted to scientific notation in excel.

我想获取单元格中显示的整数值框而不是舍入的数字。也不能要求最终用户始终在此列上应用数字格式。

I want to fetch the whole number as seen in the cell values box instead of the rounded off number.Also cannot ask the end user to always apply numeric format on this column.

有没有办法可以设置此提供程序的某些属性来读取单元格值而不是单元格文本?

Is there a way I can set some property of this provider to read the cell value instead of cell text?

谢谢

RAMYA

RAMYA M

推荐答案

嗨ramyam,

Hi ramyam,

根据您的描述,我创建一个简单的如下阅读excel中的科学记数法,工作正常,请你分享相关代码,截图,excel来重现问题。

Based on your description, I create a simple as below to read scientific notation in excel, which works fine, could you please share related code, screenshot, excel to reproduce the issue.

static void Main(string[] args)
        {
            string connstr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Data\Excel\Book1.xlsx; Extended Properties='Excel 12.0 Xml; HDR = YES';";
            DataTable dt = new DataTable();
            using (var conn = new OleDbConnection(connstr))
            {
                string sql = @"select * from [Sheet1


" ;;
OleDbCommand command = new OleDbCommand(sql,conn);
OleDbDataAdapter adapter = new OleDbDataAdapter(command);
adapter.Fill(dt);

}

foreach(dt.Rows中的DataRow dr)
{
Console.WriteLine(" {0} - {1}" ;,博士[0],博士[1]);
}

Console.ReadLine();
}
"; OleDbCommand command = new OleDbCommand(sql, conn); OleDbDataAdapter adapter = new OleDbDataAdapter(command); adapter.Fill(dt); } foreach (DataRow dr in dt.Rows) { Console.WriteLine("{0} -- {1}", dr[0], dr[1]); } Console.ReadLine(); }

祝你好运,

张龙


这篇关于如何使用Microsoft OLE DB提供程序读取cell.Value而不是Cell.text的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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