本文介绍了Excel To ADO RecordSet的数字单元格具有空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Excel文件中导入一些数据以供使用,但是我遇到了数字单元格值的问题。我有一些列将具有值,其中一些都是数字,而其他值可能是数字和非数字值的混合(没有特殊字符,只有A-Z字母)。要将数据拉入记录集,我需要执行以下操作

I'm trying to import some data to work with from an Excel file but I'm running into problems with numeric cell values. I have some columns that will have values where some are all numeric while other values might be a mix of numeric and non numeric values (no special characters, just A-Z letters). To pull the data into a recordset, I'm doing the following

 Set oconn = New ADODB.connection
 oconn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & excelFile & ";" & "Extended Properties=""Excel 8.0;HDR=YES;"""

  sTableName = "[sheet1$]"
  sTableName = "select * from " & sTableName

  Set oRs = New ADODB.Recordset
  oRs.Open sTableName, oconn, adOpenStatic, adLockOptimistic

当我读取记录集的值时,数值在混合格式的列中显示为空白。有什么方法可以使记录集将所有值都读取为文本,还是可以通过另一种方式读取Excel文件来避免此问题?

When I'm reading the recordset's values though, numeric values are showing up as blank in the columns where the data is in a mixed format. Is there any way to get the recordset to just read all values as text or an alternative way to reading the Excel file to avoid this issue?

推荐答案

我有一个类似的问题,但是反过来,数字显示的很好,但是alpha却没有。将

I had a similar problem but in reverse, where the numbers showed up fine but the alphas did not. After adding

添加后; IMEX = 1

扩展属性,它工作正常。

to the Extended Properties, it worked fine.

IMEX = 1 表示始终将混合数据列读取为文本。

IMEX=1 means always read mixed data columns as text.

这篇关于Excel To ADO RecordSet的数字单元格具有空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 18:48
查看更多