访问excel数据而无需在应用程序中打开它

时间:2019-04-18 10:45:19

标签: excel

我正在寻找一种处理存储在网络位置上的excel文件的快速方法。我需要检查excel文件中的某些值,但是我打开工作簿的标准方法,查找所需内容以及关闭这些巨大的excel文件的方法已经花了很长时间。

是否有其他方法无需打开即可访问excel内容?

我已经阅读了有关EPplus的信息,但是还有其他内容吗?

1 个答案:

答案 0 :(得分:0)

在VBA中使用ExecuteExcel4Macro命令,您可以访问excel文件中的数据,而无需打开文件本身。缺点是您必须知道要寻找的特定范围,但这听起来可能适合您。

例如:

Private Function GetCellFromClosedFile(ByVal wbPath As String, wbName As String, wsName As String, _
                                       rowref As Long, colref As Long) As Variant
'Fetches the value of a single cell in a closed workbook
Dim val As String
    GetCellFromClosedFile = "" 'Clears old value
    If Right(wbPath, 1) <> "" Then wbPath = wbPath & "" 'Clears path string
    If Dir(wbPath & "" & wbName) = "" Then Exit Function 'If no new path exit
    'Returns single cell - can only return a single cell - use ADO to get a range
    val = "'" & wbPath & "[" & wbName & "]" & wsName & "'!" & _
          Range(Cells(rowref, colref), Cells(rowref, colref)).Address(True, True, xlR1C1)
    On Error Resume Next
    GetCellFromClosedFile = ExecuteExcel4Macro(val)
End Function