[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How do I convert a CSV file to XLSX file

Posted on 2008-11-13
4
Medium Priority
?
4,342 Views
Last Modified: 2013-11-26
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.
0
Comment
Question by:mackeyrj
  • 2
4 Comments
 
LVL 45

Expert Comment

by:patrickab
ID: 22952280
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
 

Author Comment

by:mackeyrj
ID: 22953448
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
 
LVL 15

Accepted Solution

by:
markpalinux earned 1000 total points
ID: 23010152
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
 

Author Comment

by:mackeyrj
ID: 23027970
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

865 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question