Excel report using asp.net

T

Terry

I am building an ASP.net application which will generate a formatted Excel
report.
Is there a way I can using the Excel on the client pc?
Do I have to do a full install of Excel on the server or just add the needed
dll's to my ASP.net project.

Terry
 
D

Dan Bass

The server doesn't need Excel...

Here's a method that sends a excel application type stream, converting a
datagrid object into a excel like table...

public static void ExportToXls(DataGrid dgExport, HttpResponse
response)
{

response.Clear();
response.Buffer = true;
response.Charset = "";
response.ContentType = "application/vnd.ms-excel";

System.IO.StringWriter stringWrite = new
System.IO.StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

ClearControls(dgExport);
dgExport.GridLines = GridLines.None;
dgExport.HeaderStyle.Font.Bold = true;
dgExport.AlternatingItemStyle.BackColor =
System.Drawing.Color.WhiteSmoke;
dgExport.HeaderStyle.ForeColor =
System.Drawing.Color.DarkBlue;
dgExport.HeaderStyle.BackColor =
System.Drawing.Color.LightGray;
dgExport.RenderControl(htmlWrite);

response.Write(stringWrite.ToString());
response.End();

}
 
B

bill

I got this client-side script from Steve Orr's site
(http://steveorr.net/Articles/ExcelExport.aspx). You should read his
discussion also.

<scriptlanguage="vbscript">
Sub exportbutton_onclick
Dim sHTML, oExcel, oBook
sHTML = document.all.item("DataGrid1").outerhtml
Set oExcel = CreateObject("Excel.Application")
Set oBook = oExcel.Workbooks.Add
oBook.HTMLProject.HTMLProjectItems("Sheet1").Text = sHTML
oBook.HTMLProject.RefreshDocument
oExcel.Visible = true
oExcel.UserControl = true
End Sub </script>
 
D

Dan Bass

You should not use the Excel Application object, it's not created for this
purpose. Instead, if you want to go this route you sould use the Office Web
Components downloadable from Microsoft's web site.

Access this object in this way leaves Excel instances open in memory after
the uses shut them down and causes other problems as well...
 
S

Steve C. Orr [MVP, MCSD]

Here's another technique you can use. With the free export panel, just put
everything into the panel and have it generate the spreadsheet automatically
for you. It can also export to other applications just as easily, such as
Word and WordPerfect.
http://SteveOrr.net/articles/exportpanel.aspx
 
G

Guest

Hi Bill,

What do you do when you get the "Access denied" error ? Because I don't want
to change the settings on my webserver (say that i ant to use it on another
webserver, then i have to configure that too, and that's something i don't
want to)

Thx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,169
Latest member
ArturoOlne
Top