我有下面的代碼將存儲在鏈接的Oracle表中的blob字段中的數據下載到文件中。 Blob數據存儲excel文件(.xlsx),但當我嘗試在Excel中打開下載的文件時,出現錯誤,指出文件已損壞,格式不正確。下面的代碼 -使用Access VBA打開從Oracle數據庫中的blob字段下載的excel文件時發現錯誤
Option Explicit
Const BlockSize = 32768
Public Function DownloadBlob()
Dim db As Database
Dim rst As Recordset
Dim NumBlocks As Integer, DestFile As Integer, i As Integer
Dim FileLength As Long, LeftOver As Long
Dim FileData, FilePath As String
Dim RetVal As Variant
Set db = CurrentDb
Set rst = db.OpenRecordset("Select Blob_Field FROM Table1;")
NumBlocks = FileLength/BlockSize
LeftOver = FileLength Mod BlockSize
DestFile = FreeFile()
FilePath = "C:\Desktop\test.xlsx"
Open FilePath For Output As DestFile
Close DestFile
Open FilePath For Binary As DestFile
FileData = rst.Fields(0).GetChunk(0, LeftOver)
Put DestFile, , FileData
For i = 1 To NumBlocks
FileData = rst.Fields(0).GetChunk((i - 1) * BlockSize + LeftOver, BlockSize)
Put DestFile, , FileData
Next i
Close DestFile
End Function
你在文件頂部有'Const BlockSize = 32768',對嗎?通過GUI提取文件時沒有問題? –
您在Access中,DB限制爲2GB。爲什麼要浪費寶貴的存儲空間來存放文件服務器上完美的存儲空間? –
對不起,如果我之前沒有更清楚,正如我在標題中所述,該表是Oracle數據庫中的鏈接表,因此2GB限制不適用,並且我只有RO訪問該數據庫的權限,並且必須下載這些excel文件。 –