Excel to CSV

Hi All,
I have an excel spreadsheet with multiple tabs . I want to read the data in this spreadsheet using external tables in oracle 9i which is working fine. My problem is I need to save each tab as a csv which is not acceptable. The requirement is to convert the spreadsheet tabs into csv files programatically.
Can anyone help me with this please.  

regards
SV
svanukuriAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Patrick MatthewsCommented:
Hi SV,

Option Explicit

' Function intended for use in VBA projects that shows a mini-browser allowing user to
' pick a folder.  If no folder is selected, function returns zero-length string

' Code based on procedures found at:
' http://www.exceltip.com/show_tip/Files,_Workbook,_and_Worksheets_in_VBA/
' List_files_in_a_folder_with_Microsoft_Scripting_Runtime_using_VBA_in_Microsoft_Excel/446.html

Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias _
    "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias _
    "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long

Public Type BROWSEINFO
 
    hOwner As Long
    pidlRoot As Long
    pszDisplayName As String
    lpszTitle As String
    ulFlags As Long
    lpfn As Long
    lParam As Long
    iImage As Long

End Type

Private Function GetDirectory(Optional Msg) As String
   
' Msg arguments allows for customized message in browser tool

    Dim bInfo As BROWSEINFO
    Dim path As String
    Dim r As Long
    Dim x As Long
    Dim pos As Integer

' Root folder = Desktop
    bInfo.pidlRoot = 0&

' Title in the dialog
    If IsMissing(Msg) Then bInfo.lpszTitle = "Select a folder." Else bInfo.lpszTitle = Msg

' Type of directory to return
    bInfo.ulFlags = &H1

' Display the dialog
    x = SHBrowseForFolder(bInfo)

' Parse the result
    path = Space$(512)
    r = SHGetPathFromIDList(ByVal x, ByVal path)
    If r Then
        pos = InStr(path, Chr$(0))
        GetDirectory = Left(path, pos - 1)
    Else
        GetDirectory = ""
    End If

End Function

Sub MakeCSV()

    Dim DestFolder As String
    Dim ws As Worksheet
    Dim Counter As Long
   
    DestFolder = GetDirectory("Save folder to save CSV files to")
    If DestFolder = "" Then Exit Sub
   
    Application.DisplayAlerts = False
   
    For Each ws In ThisWorkbook.Worksheets
        ws.Copy
        With ActiveWorkbook
            .SaveAs DestFolder & "\" & ActiveSheet.Name & ".csv", xlCSV
            .Close
        End With
    Next
   
    Application.DisplayAlerts = True
   
    MsgBox "Done; saved " & ThisWorkbook.Worksheets.Count & " files in " & DestFolder
   
End Sub


Regards,

Patrick

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
svanukuriAuthor Commented:
Thanks Patrick ,
I am looking for a solution in Java or oracle.

regards
sv
Patrick MatthewsCommented:
SV,

My apologies.  If none are forthcoming, I do hope you will consider that VBA solution.

Regards,

Patrick
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Patrick MatthewsCommented:
sv,

You might consider asking "pointer" questions in Oracle and/or Java:

http://www.experts-exchange.com/help.jsp#hi262

Regards,

Patrick
kaaviyamCommented:
One suggestion.

Export the data to 'Text' format. This stores data in fixed width columns. If you can view the first few rows of data, determine the width of each column.
In the java program read each row, each column trim the spaces add comma after each column and CR&LF after each row. Write the row to a text file.

This is feasible if the task is to be done on few tables and/or repeatedly.

If you need to do this on any table/ any time w/o user interaction, you need to find a way to seperate each column, and the job is done.

Note: You may not face problems with numbers & dates and single word text columns. To some extent you can rely on text with proper single spacing. (an issue arises when there is just a single space left after a column and/or the following column happens to be text also.
nmcdermaidCommented:
>> I am looking for a solution in Java or oracle

Then you'll need to find some kind of library on these platforms that can read an Excel file.

Excel is a proprietary data format therefore you're probably going to have to find something on the MS site

Once you can open an Excel file it's trivial to create the CSV.


For your Java solution is it permissible to use a windows ODBC driver? Windows MDAC comes with the Excel ODBC driver. You could use this to connect to the Excel file (assuming Java/Oracle can use ODBS) and export it as CSV
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.