Fails to open Excel

Z

ZW

Hi there,

I use following code to convert a datagrid data to Excel.
However, if I use IE to access the page, it opens an empty
excel page. If I access it by Netscape, it can open it
with excel (or save it). Does any one have experience to
fix the problem?

//
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/vnd.ms-excel";
//Response.ContentType = "application/x-msexcel"; // Same
result
Response.Charset = string.Empty ;
this.EnableViewState = false;
object content = Session["datagrid"];
if (content != null)
{
Response.Write(content.ToString());
Response.End();
}


TIA

ZW
 
D

Dan Bass

This method works if there are no controls (buttons, dropdowns etc) in the
data grid:

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();

}
 
Z

ZW

Hi Don,

Thanks for the reply.

However, it doesn't work.

Although I didn't mention, I already use
datagrid.RenderControl(HtmlTextWriter) put data to
StringWriter in DataGrid page and save the data in
Session, then in the excel report page retrieve the data
and write to Response. As I mentioned, the weird thing is
it works fine in Netscape, but not work for IE.

ZW
-----Original Message-----
remove the line ClearControls from my method.

Hi there,

I use following code to convert a datagrid data to Excel.
However, if I use IE to access the page, it opens an empty
excel page. If I access it by Netscape, it can open it
with excel (or save it). Does any one have experience to
fix the problem?

//
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/vnd.ms-excel";
//Response.ContentType = "application/x-msexcel"; // Same
result
Response.Charset = string.Empty ;
this.EnableViewState = false;
object content = Session["datagrid"];
if (content != null)
{
Response.Write(content.ToString());
Response.End();
}


TIA

ZW


.
 
D

Dan Bass

What version of IE, and what version of Office do you have installed?

ZW said:
Hi Don,

Thanks for the reply.

However, it doesn't work.

Although I didn't mention, I already use
datagrid.RenderControl(HtmlTextWriter) put data to
StringWriter in DataGrid page and save the data in
Session, then in the excel report page retrieve the data
and write to Response. As I mentioned, the weird thing is
it works fine in Netscape, but not work for IE.

ZW
-----Original Message-----
remove the line ClearControls from my method.

Hi there,

I use following code to convert a datagrid data to Excel.
However, if I use IE to access the page, it opens an empty
excel page. If I access it by Netscape, it can open it
with excel (or save it). Does any one have experience to
fix the problem?

//
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/vnd.ms-excel";
//Response.ContentType = "application/x-msexcel"; // Same
result
Response.Charset = string.Empty ;
this.EnableViewState = false;
object content = Session["datagrid"];
if (content != null)
{
Response.Write(content.ToString());
Response.End();
}


TIA

ZW


.
 
Z

ZW

IE 6 (sp1) and Office 2000.

BTW I tried IE in one computer with Office 97, it seems OK.
-----Original Message-----
What version of IE, and what version of Office do you have installed?

Hi Don,

Thanks for the reply.

However, it doesn't work.

Although I didn't mention, I already use
datagrid.RenderControl(HtmlTextWriter) put data to
StringWriter in DataGrid page and save the data in
Session, then in the excel report page retrieve the data
and write to Response. As I mentioned, the weird thing is
it works fine in Netscape, but not work for IE.

ZW
-----Original Message-----
remove the line ClearControls from my method.

Hi there,

I use following code to convert a datagrid data to Excel.
However, if I use IE to access the page, it opens an empty
excel page. If I access it by Netscape, it can open it
with excel (or save it). Does any one have experience to
fix the problem?

//
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/vnd.ms-excel";
//Response.ContentType = "application/x-msexcel"; // Same
result
Response.Charset = string.Empty ;
this.EnableViewState = false;
object content = Session["datagrid"];
if (content != null)
{
Response.Write(content.ToString());
Response.End();
}


TIA

ZW


.


.
 
D

Dan Bass

and I know it works with IE 5.01 + with Office 97, and also with IE 6.0+
with Office 2003...

Hmm. Do you have any controls in your grid? (buttons, drop downs etc?)

Have you seen this?

http://www.c-sharpcorner.com/Code/2003/Sept/ExportASPNetDataGridToExcel.asp


ZW said:
IE 6 (sp1) and Office 2000.

BTW I tried IE in one computer with Office 97, it seems OK.
-----Original Message-----
What version of IE, and what version of Office do you have installed?

Hi Don,

Thanks for the reply.

However, it doesn't work.

Although I didn't mention, I already use
datagrid.RenderControl(HtmlTextWriter) put data to
StringWriter in DataGrid page and save the data in
Session, then in the excel report page retrieve the data
and write to Response. As I mentioned, the weird thing is
it works fine in Netscape, but not work for IE.

ZW
-----Original Message-----
remove the line ClearControls from my method.

message
Hi there,

I use following code to convert a datagrid data to
Excel.
However, if I use IE to access the page, it opens an
empty
excel page. If I access it by Netscape, it can open it
with excel (or save it). Does any one have experience to
fix the problem?

//
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/vnd.ms-excel";
//Response.ContentType = "application/x-msexcel"; //
Same
result
Response.Charset = string.Empty ;
this.EnableViewState = false;
object content = Session["datagrid"];
if (content != null)
{
Response.Write(content.ToString());
Response.End();
}


TIA

ZW


.


.
 
D

Dan Bass

I think it's a bug in Office 2000 (pre SR-1)

creating excel from datagrif ->
http://support.microsoft.com/default.aspx?scid=kb;en-us;317719
bug affecting you -> http://support.microsoft.com/kb/264143/EN-US/

why it works with netscape though i don't know.

ZW said:
IE 6 (sp1) and Office 2000.

BTW I tried IE in one computer with Office 97, it seems OK.
-----Original Message-----
What version of IE, and what version of Office do you have installed?

Hi Don,

Thanks for the reply.

However, it doesn't work.

Although I didn't mention, I already use
datagrid.RenderControl(HtmlTextWriter) put data to
StringWriter in DataGrid page and save the data in
Session, then in the excel report page retrieve the data
and write to Response. As I mentioned, the weird thing is
it works fine in Netscape, but not work for IE.

ZW
-----Original Message-----
remove the line ClearControls from my method.

message
Hi there,

I use following code to convert a datagrid data to
Excel.
However, if I use IE to access the page, it opens an
empty
excel page. If I access it by Netscape, it can open it
with excel (or save it). Does any one have experience to
fix the problem?

//
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/vnd.ms-excel";
//Response.ContentType = "application/x-msexcel"; //
Same
result
Response.Charset = string.Empty ;
this.EnableViewState = false;
object content = Session["datagrid"];
if (content != null)
{
Response.Write(content.ToString());
Response.End();
}


TIA

ZW


.


.
 
Z

ZW

I think it might be problem of Office 2000. I also tried
to load Word file to web page, I got the same problem with
IE 6 + Office 2000.

Thanks,

ZW
-----Original Message-----
and I know it works with IE 5.01 + with Office 97, and also with IE 6.0+
with Office 2003...

Hmm. Do you have any controls in your grid? (buttons, drop downs etc?)

Have you seen this?

http://www.c- sharpcorner.com/Code/2003/Sept/ExportASPNetDataGridToExcel.
asp


IE 6 (sp1) and Office 2000.

BTW I tried IE in one computer with Office 97, it seems OK.
-----Original Message-----
What version of IE, and what version of Office do you have installed?

Hi Don,

Thanks for the reply.

However, it doesn't work.

Although I didn't mention, I already use
datagrid.RenderControl(HtmlTextWriter) put data to
StringWriter in DataGrid page and save the data in
Session, then in the excel report page retrieve the data
and write to Response. As I mentioned, the weird thing is
it works fine in Netscape, but not work for IE.

ZW
-----Original Message-----
remove the line ClearControls from my method.

message
Hi there,

I use following code to convert a datagrid data to
Excel.
However, if I use IE to access the page, it opens an
empty
excel page. If I access it by Netscape, it can open it
with excel (or save it). Does any one have
experience
to
fix the problem?

//
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/vnd.ms-excel";
//Response.ContentType = "application/x- msexcel"; //
Same
result
Response.Charset = string.Empty ;
this.EnableViewState = false;
object content = Session["datagrid"];
if (content != null)
{
Response.Write(content.ToString());
Response.End();
}


TIA

ZW


.



.


.
 

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

Top