I’m writing pl/sql procedure that exports data from Oracle to Excel. I need data formatting so I can’t use CSV. I’ve already tried with XML but it generates too large files
I've had similar issues and eventually made a spreadsheet with some VBA code that queried and populated the spreadsheet for me. My task was to export a series of tables, each one on a different sheet, but any flag could be used to switch to a new sheet. Anyhow, let me know if you would like to see the code. Here is a chunk that might help you out. Just change the TableSQL string to whatever your select should be. Each record returned will be inserted as a row in the sheet. Then, based on whatever flag you decide, you can create and move to the next sheet. Please let me know if you need more information (as this particular example isn't EXACTLY what you are doing)
Private Sub getMyRows(inSchema As String, InTable As String)
Dim RS As Object
Dim TableSQL As String
Dim DataType As String
Dim DataLength As String
Dim DataPrecision As String
Dim DataScale As String
Dim ColCount As Integer
Dim WS As Worksheet
' create a sheet with the current table as name
Worksheets.Add().Name = InTable
Set RS = CreateObject("ADODB.recordset")
TableSQL = "Select * from " & inSchema & "." & InTable
' grab the data
RS.Open TableSQL, conn, adOpenStatic
For ColCount = 0 To RS.Fields.Count - 1
' set column headings to match table
ActiveSheet.Cells(1, ColCount + 1).Value = RS.Fields(ColCount).Name
Next
' copy table data to sheet
With Worksheets(InTable).Range("A2")
.CopyFromRecordset RS
End With
RS.Close
End Sub