|
-
December 3rd, 2006, 08:10 AM
#1
how to create an excel file???
Hello,
I have a asp.net web application which inside it I create a string with a table, which I want to be able to open an excel file with the data in that table.
my problem is that I am not able to open the excel in a new window(I do create the excel file. but it is being opend be the browser in the same page and not in a new page).
I use the following code:
Response.ContentType = "application/vnd.ms-excel";
Response.Write(ExcelString);
Response.End();
When ExcelString = “<TABLE borderColor=#808080 border=1>
<THEAD>
<TR>
<TH BGCOLOR='BLUE'>Date</TD>
<TH BGCOLOR='BLUE'># New Accounts</TD>
<TH BGCOLOR='BLUE'>Log In</TD>
<TH BGCOLOR='BLUE'>Deposit</TD>
<TH BGCOLOR='BLUE'>Withdraw</TD>
<TH BGCOLOR='BLUE'>Pending Withdrawal</TD>
<TH BGCOLOR='BLUE'>Bonus</TD>
<TH BGCOLOR='BLUE'>Sum Of Bonus</TD>
<TH BGCOLOR='BLUE'># Bets</TD>
<TH BGCOLOR='BLUE'># Match Bets</TD>
<TH BGCOLOR='BLUE'>Match Bets Sum</TD>
<TH BGCOLOR='BLUE'>UnMatch Bets Sum</TD>
<TH BGCOLOR='BLUE'>Profit\Loss</TD>
<TH BGCOLOR='BLUE'>Commission Profit</TD>
</TR>
<TR>
<TH BGCOLOR='BLUE'></TD>
<TH BGCOLOR='BLUE'></TD>
<TH BGCOLOR='BLUE'></TD>
<TH BGCOLOR='BLUE'></TD>
<TH BGCOLOR='BLUE'></TD>
<TH BGCOLOR='BLUE'></TD>
<TH BGCOLOR='BLUE'></TD>
<TH BGCOLOR='BLUE'></TD>
<TH BGCOLOR='BLUE'></TD>
<TH BGCOLOR='BLUE'></TD>
<TH BGCOLOR='BLUE'></TD>
<TH BGCOLOR='BLUE'></TD>
<TH BGCOLOR='BLUE'></TD>
<TH BGCOLOR='BLUE'></TD>
</TR>
</THEAD>
<TBODY>
<TR>
<TD>12/2006</TD>
<TD>0</TD>
<TD>0</TD>
<TD>0</TD>
<TD>0</TD>
<TD>0</TD>
<TD>0</TD>
<TD>0</TD>
<TD>0</TD>
<TD>0</TD>
<TD>0</TD>
<TD>0</TD>
<TD>0</TD>
<TD>0</TD>
</TR>
<TR>
<TD>TOTAL</TD>
<TD>0</TD>
<TD>0</TD>
<TD>0</TD>
<TD>0</TD>
<TD>0</TD>
<TD>0</TD>
<TD>0</TD>
<TD>0</TD>
<TD>0</TD>
<TD>0</TD>
<TD>0</TD>
<TD>0</TD>
<TD>0</TD>
</TR>
</TBODY>
</TABLE>"
-
December 3rd, 2006, 11:19 AM
#2
Re: how to create an excel file???
Maybe you can try to use datagrid and do it as follow
Code:
Protected Sub but_export_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim now As DateTime = DateTime.Now
Dim tmp As String = now.ToString("hh mm, MM dd, yyyy")
xlfile = "Report_" + tmp + ".xls"
Response.Clear()
'Set the content type to Excel.
Response.ContentType = "application/vnd.ms-excel"
Response.AppendHeader("Content-disposition", "attachment; filename=" + xlfile)
Response.Charset = ""
' Turn off the view state.
Me.EnableViewState = False
Dim tw As New System.IO.StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
' Get the HTML for the control.
MemberDataGrid.RenderControl(hw)
' Write the HTML back to the browser.
Response.Write(tw.ToString())
' End the response.
Response.End()
End Sub
hope it helps
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|