VBA 中的 ADO 以读取 XLS(Web 存档)文件

问题描述 投票:0回答:0

我正在 Excel (Office 365) 中编写 VBA,以通过 ActiveX 数据对象 (ADO) 6.1 库从外部源检索数据

代码从 XLS(X) 和 CSV 文件中检索数据数据的速度非常快,但我现在遇到了看似 XLS(即这是文件扩展名),但实际上是 Excel 应用程序的“Web 存档”文件可以处理(尽管有一条错误消息表明文件内容与扩展名不匹配),但是 ADO 抱怨“外部表不是预期的格式”

这是在Notepad++打开时的文件头

MIME-Version: 1.0
X-Document-Type: Workbook
Content-Type: multipart/related; boundary="----=_NextPart_01C3AACE.2206ED10"

This document is a Web archive file.  If you are seeing this message, this means your browser or editor doesn't support Web archive files.  For more information on the Web archive format, go to http://officeupdate.microsoft.com/office/webarchive.htm.

------=_NextPart_01C3AACE.2206ED10
Content-Location: http://localhost/excel.htm
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset="utf-8"

<html xmlns:o=3D"urn:schemas-microsoft-com:office:office"
xmlns:x=3D"urn:schemas-microsoft-com:office:excel"
xmlns:v=3D"urn:schemas-microsoft-com:vml"
xmlns=3D"http://www.w3.org/TR/REC-html40">

如果我通过 Windows 资源管理器将扩展名更改为 XLSX,Excel 会告诉我文件根本无法打开

据我所知,这根本不是一个真正的 Excel 文件,它是一个在第 3 方系统中创建的文件,Excel 只有在被告知它是 XLS 文件时才能解释它

有没有什么方法可以在不使用“Workbooks.Open”依赖 Excel 应用程序来理解内容的情况下在 VBA 中解释这个文件?

似乎可以将其作为 XML 读取并以这种方式处理数据,但我什至不知道从哪里开始

excel vba ado
© www.soinside.com 2019 - 2024. All rights reserved.