[英]Reading integers from Excel using oledb
I am using oledb to read data from an excel file and store it in a dataset. 我正在使用oledb从excel文件中读取数据并将其存储在数据集中。 My excel file contents are like as follows:
我的excel文件内容如下:
0 0 somestring somestring
500 200 somestring somestring
When i checked the contents of my data set, the values of Columns 1 & 2 are not stored as integers but rather as DateTime values. 当我检查数据集的内容时,第1列和第2列的值不会存储为整数,而是存储为DateTime值。
How will I make it be stored as integer values instead of DateTime? 如何将其存储为整数值而不是DateTime?
您是否尝试将IMEX = 1添加到OLEDB连接字符串?
Are you sure its a number? 你确定它的号码吗? Following could be a few options:
以下可能是一些选择:
that is, 那是,
Excel.Worksheet sheet = this.Application.ActiveSheet as Excel.Worksheet;
Excel.Range range = sheet.get_Range("A1", "A5") as Excel.Range;
//delete previous validation rules
range.Validation.Delete();
You could use a 3rd party component like SpreadsheetGear for .NET which lets you get the underlying values of cells (with IWorkbook.Worksheets["MySheet"].Cells[rowIndex, colIndex].Value) regardless of the cell format, or you can get the formatted result with IRange.Text. 您可以使用第三方组件,如SpreadsheetGear for .NET ,它可以让您获取单元格的基础值(使用IWorkbook.Worksheets [“MySheet”]。单元格[rowIndex,colIndex] .Value),无论单元格格式如何,或者您可以使用IRange.Text获取格式化结果。
You can see live ASP.NET samples here and download the free trial here . 你可以看到现场ASP.NET样品这里并下载免费试用这里 。
Disclaimer: I won SpreadsheetGear LLC 免责声明:我赢得了SpreadsheetGear LLC
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.