By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,165 Members | 1,502 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,165 IT Pros & Developers. It's quick & easy.

ASP.NET with Excel and Database

P: n/a
All,

What I want to do is parse some data using vb.net/asp.net from a
database to a file in excel format. Now I know I can parse it into a
..csv file, but is there a way to parse it to a .xls file (some .net
libary or documented format).

Thanks,
Bob
Nov 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi Bob,

I would expect that any component that can build .xls files from the
ground up is likely to be a commercial product..

Have you considered using Automation to get Excel itself to read your .csv
file and write the .xsl file?

Regards,
Fergus
Nov 20 '05 #2

P: n/a
Hello,

"Bob W" <wr***@msn.com> schrieb:
What I want to do is parse some data using vb.net/asp.net
from a database to a file in excel format. Now I know I
can parse it into a .csv file, but is there a way to parse it to
a .xls file (some .net libary or documented format).


This is a VB.NET language group. Notice that you will have a better chance
to get an answer if you post the question to the ADO.NET newsgroup:

news://msnews.microsoft.com/microsof...amework.adonet

Web interface:

http://msdn.microsoft.com/newsgroups...amework.adonet

--
Herfried K. Wagner
MVP VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #3

P: n/a
"Fergus Cooney" <fi******@tesco.net> wrote in message news:<O5**************@TK2MSFTNGP11.phx.gbl>...
Hi Bob,

I would expect that any component that can build .xls files from the
ground up is likely to be a commercial product..

Have you considered using Automation to get Excel itself to read your .csv
file and write the .xsl file?

Regards,
Fergus


I guess I could create a .csv file and then port it out to an excel
sheet. I added the Microsoft Excel Object libary reference to my
asp.net application. Is there any example code from coverting a csv
file to an excel sheet?

Thanks,
Bob
Nov 20 '05 #4

P: n/a
Howdy Bob,

|| Is there any example code from coverting a csv
|| file to an excel sheet?

I reckon there is. :-)

<code>
Imports System.Runtime.InteropServices

Public Const xlNormal As Integer = -4143

Public Sub LetsChangeThatFile
Dim oExcel As Excel.Application
Dim oWorkSheet As Worksheet

Try
oExcel = New Excel.Application
oExcel.Visible = True 'Optional but good for debugging.

oExcel.Workbooks.Open ("C:\Tmp\Foo.csv")
oWorksheet = DirectCast (oExcel.ActiveSheet, Excel.Worksheet)

oWorksheet.SaveAs ("C:\Tmp\Foo.xls", xlNormal)
oExcel.Quit

Catch
Dim Up As New Exception ("Bad file - Uuurghh")
Throw Up

Finally
If oWorksheet Is Nothing = False Then
Marshal.ReleaseComObject (oWorksheet)

oExcel.Quit 'oExcel will be valid here.
End If
If oExcel Is Nothing = False Then
Marshal.ReleaseComObject (oExcel)
End If
End Try

End Sub
</code>

As you san see it's only about three lines of useful code - but with a lot
of packaging. You'll get an Excel dialogue about overwriting if the target
file already exists.

Regards,
Fergus
Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.