Connecting Tech Pros Worldwide Forums | Help | Site Map

ASP.NET with Excel and Database

Bob W
Guest
 
Posts: n/a
#1: Nov 20 '05
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

Fergus Cooney
Guest
 
Posts: n/a
#2: Nov 20 '05

re: ASP.NET with Excel and Database


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


Herfried K. Wagner [MVP]
Guest
 
Posts: n/a
#3: Nov 20 '05

re: ASP.NET with Excel and Database


Hello,

"Bob W" <wr3pa@msn.com> schrieb:[color=blue]
> 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).[/color]

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


Bob W
Guest
 
Posts: n/a
#4: Nov 20 '05

re: ASP.NET with Excel and Database


"Fergus Cooney" <filter-1@tesco.net> wrote in message news:<O5JSnTMgDHA.3208@TK2MSFTNGP11.phx.gbl>...[color=blue]
> 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[/color]

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
Fergus Cooney
Guest
 
Posts: n/a
#5: Nov 20 '05

re: ASP.NET with Excel and Database


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


Closed Thread