How do I convert a CSV file to XLSX file

I have a form that clients use to upload a CSV file.
After the file is uploaded I want to convert that file to an Excel 2007 spreadsheet and save it on the server.
I am using visual studio 2008 and office 2007.
mackeyrjAsked:
Who is Participating?
 
markpalinuxConnect With a Mentor Commented:
I was looking for the same answer. I am looking to use vbscript.

Here is the cut and pasted for some web pages solution I came up with.

Works for me with vbscript. Hope this helps.

Mark
strCSVFile = "C:\me\code\vbscript-excel-csv-saveas\file1.csv"
strXLSX = "C:\me\code\vbscript-excel-csv-saveas\file1.xlsx"
 
 ' Create the Excel application.
    Set objExcel = CreateObject("Excel.Application")
 
    ' Uncomment this line to make Excel visible.
    'objExcel.Visible = True
 
    ' Load the CSV file.
    objExcel.Workbooks.Open (strCSVFile)
        
 
 ' Save as an Excel spreadsheet.
 
    objExcel.ActiveWorkbook.SaveAs strXLSX, 51
    'to get the file type look at EE Q_22879330
 
 
    ' Comment the rest of the lines to keep
    ' Excel running so you can see it.
 
    ' Close the workbook without saving.
    objExcel.ActiveWorkbook.Close False
 
    ' Close Excel.
    objExcel.Quit
    Set objExcel = Nothing

Open in new window

0
 
patrickabCommented:
mackeyrj,
I suggest two alternatives:
1. Import the CSV into Excel and save it as an xlsx file
or
2. Use ConvertXLS from Softinterface.com which has a specific option to do what you want.
Patrick
0
 
mackeyrjAuthor Commented:
I want the action to be handled programmatically inside the web application.
The client uploads the CSV and it just automatically is saved in the xlsx.
0
 
mackeyrjAuthor Commented:
I had to make a few minor changes for this to work in VB 2008.

In the snippet notice the DIM AS  STRINGS and OBJECT that I added.


DIM strCSVFile AS STRING= "C:\me\code\vbscript-excel-csv-saveas\file1.csv"
DIM strXLSX AS STRING = "C:\me\code\vbscript-excel-csv-saveas\file1.xlsx"
 
 ' Create the Excel application.
    DIM objExcel AS OBJECT = CreateObject("Excel.Application")
 
    ' Uncomment this line to make Excel visible.
     objExcel.Visible = True
 
    ' Load the CSV file.
    objExcel.Workbooks.Open (strCSVFile)
        
 
 ' Save as an Excel spreadsheet.
 
    objExcel.ActiveWorkbook.SaveAs strXLSX, 51
    'to get the file type look at EE Q_22879330
 
 
    ' Comment the rest of the lines to keep
    ' Excel running so you can see it.
 
    ' Close the workbook without saving.
    objExcel.ActiveWorkbook.Close False
 
    ' Close Excel.
    objExcel.Quit
    Set objExcel = Nothing

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.