Link to home
Start Free TrialLog in
Avatar of mackeyrj
mackeyrj

asked on

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.
Avatar of patrickab
patrickab
Flag of United Kingdom of Great Britain and Northern Ireland image

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
Avatar of mackeyrj
mackeyrj

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of markpalinux
markpalinux
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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