excel - 在 Excel 中将 Chr(10) 替换为 Chr(13) + Chr(10) 以导入 Access
问题描述
问题是在 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
我在哪里错了,什么是更好的方法?
解决方案
没关系,在发布后几分钟就弄清楚了:
xl.Selection.Replace What:="" & Chr(10) & "", Replacement:="" & Chr(13) & Chr(10) & "", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
推荐阅读
- sql - 这个 SQL 查询的最佳索引是什么?
- python - 列表Python中的比较总和
- java - ServletRequest getAsyncContext() 上的 IllegalStateException
- python - 如何将python字符串转换为数组
- arrays - 如何检查多维数组是否为空
- django - 如何使用 django-partial-date 和 SelectDateWidget 管理部分日期?
- r - 运行一段代码多次更改 R 中的某些参数(如 SAS 中的宏)
- regex - 用于连接正则表达式和变量的 PowerShell 脚本
- nestjs - 在 Nestjs 问题中读取对象值
- windows - 用于将代理部署到 Windows 操作系统的 Azure 自定义脚本扩展问题