Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Transforming an Excel spreadsheet in asp.net

Status
Not open for further replies.

dpdoug

Programmer
Nov 27, 2002
455
0
0
US
How do I programatically trasform an excel spreadsheet to a csv file?

It's easy enough to do in excel, but I want to do it from an asp.net application.

Or what would be even better yet would be to open up a spreadsheet, and insert it straight into a SQL table.

Any code examples?
 
Did you ever figure out how to do this?

Steve
"In the Jungle of the Senses
 
I believe you can refernce the Excel object and use the same code as you would in an excel macro. But I think you have to use a late bound function and you don't have the advantage of the intellisense to show you the methods and properties. Also the spreadsheet has to be serverside, so you have to upload it to your server.

Another thing, excel has to be installed on the server for it to work.

But I found a better way to do what I had originally wanted to do which was saving the data in the spreadsheet to a sql database. I found it was easier to just open the spreadsheet with an access driver and extended properties for excel and loop through the rows inserting the fields I needed.

So I didn't need to convert the spreadsheet to a CSV file first -- I just use the spreadsheet the way it comes.
 
The easiest way I have found of doing it is to simply open the excel file (using the Excel object) and then use "save as" and select the CSV format. e.g.

Code:
objExcel.ActiveWorkbook.SaveAs("MyFile.csv", Excel.XlFileFormat.xlCSV)

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top