TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
mary jean ligas
NA
420
195.6k
Export to excell file
Jun 10 2014 1:13 AM
i want to create a function that would export an excell file according to a dynamically created table in web page..as in same format..please help me
please see my snippet:
GridView1.AllowPaging =
true
;
StringWriter
tw =
new
StringWriter
();
System.Web.UI.
HtmlTextWriter
hw =
new
System.Web.UI.
HtmlTextWriter
(tw);
HtmlForm
frm =
new
HtmlForm
();
string
strTmpTime = (System.
DateTime
.Today).ToString();
if
(strTmpTime.IndexOf(
"/"
) != -1)
{
strTmpTime = strTmpTime.Replace(
"/"
,
"-"
).ToString().Trim();
}
if
(strTmpTime.IndexOf(
":"
) != -1)
{
strTmpTime = strTmpTime.Replace(
":"
,
"-"
).ToString().Trim();
}
Response.ContentType =
"application/ms-excel"
;
Response.AddHeader(
"content-disposition"
,
"attachment;filename=sheet.xls"
);
Response.Charset =
"UTF-8"
;
EnableViewState =
false
;
Controls.Add(frm);
frm.Controls.Add(GridView1);
frm.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
this code gives an error upon opening the excel file:
"The file you are trying to open, [filename], is in a different format than specified by the file extension" error opening Excel files
Reply
Answers (
4
)
Save web form data to disk file
Time Stampt Function(trial version)Windows form application