问题是,在Excel中换行符使用Char(10),而在Access中使用Char(13) & Char(10)。因此,当您从Excel导入到Access时,Excel中的换行符在Access中都在同一行上。
我有一个按钮点击自动导入,以便一些数据可以在输入之前进行消毒。我想将此添加到敏感化中,但我遇到了问题:
' Remove blank cells that aren't blank (i.e., pasting values of formulas with no value)
xl.ActiveSheet.UsedRange.Select
xl.Selection.Value = xl.Selection.Value
' Replace line breaks and carriage returns with something Access recognizes
xl.Selection.Value = Replace(xl.Selection.Value, Chr(10), Chr(13) + Chr(10))
' OR this....
xl.ActiveSheet.Selection.Replace _
What:=Chr(10), Replacement:=Chr(13) + Chr(10), _
SearchOrder:=xlByColumns, MatchCase:=False第一种方法生成:
Run-time error '13': Type mismatch第二种方法生成:
Run-time error '438': Object doesn't support this property or method在这里我哪里错了,什么是更好的方法?
发布于 2019-05-16 03:14:38
不要紧,在发帖几分钟后就明白了:
xl.Selection.Replace What:="" & Chr(10) & "", Replacement:="" & Chr(13) & Chr(10) & "", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False发布于 2019-05-16 03:17:23
要保留Excel数据,您也可以在导入MS Access后运行以下查询:
update
YourTable t
set
t.YourField = Replace(t.YourField, Chr(10), Chr(13) & Chr(10))
where
t.YourField like "*" & Chr(10) & "*" and
t.YourField not like "*" & Chr(13) & Chr(10) & "*"https://stackoverflow.com/questions/56156155
复制相似问题