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
You can get Tom Kyte's OWA-SYLK utility, which supports a subset of .xls format features.
The ExcelDocumentType is a great solution. It allows you to generate fully functional multi-sheet Excel documents with PL/SQL. You can find it here:
http://radio.weblogs.com/0137094/2006/10/26.html
http://radio.weblogs.com/0137094/2009/01/02.html
(Jason Bennett's Developer Corner)
I found this solution on the web (not invented by me), using SQL plus:
set feed off markup html on spool on
spool c:\table1.xls
select * from table1;
spool off
set markup html off spool off
We use to OOXML methods. We were first writing our own method to do it in PL/SQL but a coworker found this product called Excellant. It it is you pass in a xml spec with column mappings and styles/formulas (almost any excel formula works), the query and it gives you a clob back. So you can then run gzip on the clob if you want to make it smaller. The product is pretty cheep my manager bought it with a pcard.
The web site is www.peak42solutions.com. We couldn't use ODBC since the network folks don't allow access directly to the database. And we are now emailing invoicing in excel to customers.
Thanks,
Bill