ASP.NET with Excel and Database

  • Thread starter Thread starter Bob W
  • Start date Start date
B

Bob W

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
 
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
 
Hello,

Bob W said:
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/microsoft.public.dotnet.framework.adonet

Web interface:

http://msdn.microsoft.com/newsgroup...roup=microsoft.public.dotnet.framework.adonet
 
Fergus Cooney said:
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
 
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
 
Back
Top