469,621 Members | 1,685 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,621 developers. It's quick & easy.

Excel report using asp.net

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
Nov 19 '05 #1
5 2894
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();

}


"Terry" <te***@xxx.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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

Nov 19 '05 #2
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>

"Terry" <te***@xxx.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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

Nov 19 '05 #3
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...
"bill" <be****@datamti.com> wrote in message
news:eE****************@TK2MSFTNGP12.phx.gbl...
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>

"Terry" <te***@xxx.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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


Nov 19 '05 #4
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

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Terry" <te***@xxx.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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

Nov 19 '05 #5
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

"bill" wrote:
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>

"Terry" <te***@xxx.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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


Nov 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Spacy | last post: by
1 post views Thread by Steven Stewart | last post: by
1 post views Thread by Mustufa Baig | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.