473,569 Members | 2,729 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Fails to open Excel

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.ClearC ontent();
Response.ClearH eaders();
Response.Conten tType = "applicatio n/vnd.ms-excel";
//Response.Conten tType = "applicatio n/x-msexcel"; // Same
result
Response.Charse t = string.Empty ;
this.EnableView State = false;
object content = Session["datagrid"];
if (content != null)
{
Response.Write( content.ToStrin g());
Response.End();
}
TIA

ZW
Nov 19 '05 #1
8 1610
remove the line ClearControls from my method.

"ZW" <an*******@disc ussions.microso ft.com> wrote in message
news:04******** *************** *****@phx.gbl.. .
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.ClearC ontent();
Response.ClearH eaders();
Response.Conten tType = "applicatio n/vnd.ms-excel";
//Response.Conten tType = "applicatio n/x-msexcel"; // Same
result
Response.Charse t = string.Empty ;
this.EnableView State = false;
object content = Session["datagrid"];
if (content != null)
{
Response.Write( content.ToStrin g());
Response.End();
}
TIA

ZW

Nov 19 '05 #2
This method works if there are no controls (buttons, dropdowns etc) in the
data grid:

public static void ExportToXls(Dat aGrid dgExport, HttpResponse
response)
{

response.Clear( );
response.Buffer = true;
response.Charse t = "";
response.Conten tType = "applicatio n/vnd.ms-excel";

System.IO.Strin gWriter stringWrite = new
System.IO.Strin gWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter( stringWrite);

ClearControls(d gExport);
dgExport.GridLi nes = GridLines.None;
dgExport.Header Style.Font.Bold = true;
dgExport.Altern atingItemStyle. BackColor =
System.Drawing. Color.WhiteSmok e;
dgExport.Header Style.ForeColor =
System.Drawing. Color.DarkBlue;
dgExport.Header Style.BackColor =
System.Drawing. Color.LightGray ;
dgExport.Render Control(htmlWri te);

response.Write( stringWrite.ToS tring());
response.End();

}

"ZW" <an*******@disc ussions.microso ft.com> wrote in message
news:04******** *************** *****@phx.gbl.. .
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.ClearC ontent();
Response.ClearH eaders();
Response.Conten tType = "applicatio n/vnd.ms-excel";
//Response.Conten tType = "applicatio n/x-msexcel"; // Same
result
Response.Charse t = string.Empty ;
this.EnableView State = false;
object content = Session["datagrid"];
if (content != null)
{
Response.Write( content.ToStrin g());
Response.End();
}
TIA

ZW

Nov 19 '05 #3
ZW
Hi Don,

Thanks for the reply.

However, it doesn't work.

Although I didn't mention, I already use
datagrid.Render Control(HtmlTex tWriter) 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.

"ZW" <an*******@disc ussions.microso ft.com> wrote in messagenews:04******* *************** ******@phx.gbl. ..
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.ClearC ontent();
Response.ClearH eaders();
Response.Conten tType = "applicatio n/vnd.ms-excel";
//Response.Conten tType = "applicatio n/x-msexcel"; // Same result
Response.Charse t = string.Empty ;
this.EnableView State = false;
object content = Session["datagrid"];
if (content != null)
{
Response.Write( content.ToStrin g());
Response.End();
}
TIA

ZW

.

Nov 19 '05 #4
What version of IE, and what version of Office do you have installed?

"ZW" <an*******@disc ussions.microso ft.com> wrote in message
news:13******** *************** *****@phx.gbl.. .
Hi Don,

Thanks for the reply.

However, it doesn't work.

Although I didn't mention, I already use
datagrid.Render Control(HtmlTex tWriter) 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.

"ZW" <an*******@disc ussions.microso ft.com> wrote in

message
news:04****** *************** *******@phx.gbl ...
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.ClearC ontent();
Response.ClearH eaders();
Response.Conten tType = "applicatio n/vnd.ms-excel";
//Response.Conten tType = "applicatio n/x-msexcel"; // Same result
Response.Charse t = string.Empty ;
this.EnableView State = false;
object content = Session["datagrid"];
if (content != null)
{
Response.Write( content.ToStrin g());
Response.End();
}
TIA

ZW

.

Nov 19 '05 #5
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?
"ZW" <an*******@disc ussions.microso ft.com> wrote in messagenews:13******* *************** ******@phx.gbl. ..
Hi Don,

Thanks for the reply.

However, it doesn't work.

Although I didn't mention, I already use
datagrid.Render Control(HtmlTex tWriter) 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.

"ZW" <an*******@disc ussions.microso ft.com> wrote in

message
news:04***** *************** ********@phx.gb l...
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.ClearC ontent();
Response.ClearH eaders();
Response.Conten tType = "applicatio n/vnd.ms-excel";
//Response.Conten tType = "applicatio n/x-msexcel"; //

Same
result
Response.Charse t = string.Empty ;
this.EnableView State = false;
object content = Session["datagrid"];
if (content != null)
{
Response.Write( content.ToStrin g());
Response.End();
}
TIA

ZW
.

.

Nov 19 '05 #6
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/20...ridToExcel.asp
"ZW" <an*******@disc ussions.microso ft.com> wrote in message
news:16******** *************** *****@phx.gbl.. .
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?

"ZW" <an*******@disc ussions.microso ft.com> wrote in

message
news:13****** *************** *******@phx.gbl ...
Hi Don,

Thanks for the reply.

However, it doesn't work.

Although I didn't mention, I already use
datagrid.Render Control(HtmlTex tWriter) 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.

"ZW" <an*******@disc ussions.microso ft.com> wrote in
message
news:04**** *************** *********@phx.g bl...
> 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.ClearC ontent();
> Response.ClearH eaders();
> Response.Conten tType = "applicatio n/vnd.ms-excel";
> //Response.Conten tType = "applicatio n/x-msexcel"; //
Same
> result
> Response.Charse t = string.Empty ;
> this.EnableView State = false;
> object content = Session["datagrid"];
> if (content != null)
> {
> Response.Write( content.ToStrin g());
> Response.End();
> }
>
>
> TIA
>
> ZW
.

.

Nov 19 '05 #7
I think it's a bug in Office 2000 (pre SR-1)

creating excel from datagrif ->
http://support.microsoft.com/default...b;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" <an*******@disc ussions.microso ft.com> wrote in message
news:16******** *************** *****@phx.gbl.. .
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?

"ZW" <an*******@disc ussions.microso ft.com> wrote in

message
news:13****** *************** *******@phx.gbl ...
Hi Don,

Thanks for the reply.

However, it doesn't work.

Although I didn't mention, I already use
datagrid.Render Control(HtmlTex tWriter) 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.

"ZW" <an*******@disc ussions.microso ft.com> wrote in
message
news:04**** *************** *********@phx.g bl...
> 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.ClearC ontent();
> Response.ClearH eaders();
> Response.Conten tType = "applicatio n/vnd.ms-excel";
> //Response.Conten tType = "applicatio n/x-msexcel"; //
Same
> result
> Response.Charse t = string.Empty ;
> this.EnableView State = false;
> object content = Session["datagrid"];
> if (content != null)
> {
> Response.Write( content.ToStrin g());
> Response.End();
> }
>
>
> TIA
>
> ZW
.

.

Nov 19 '05 #8
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/ExportASPNetDat aGridToExcel.
asp

"ZW" <an*******@disc ussions.microso ft.com> wrote in messagenews:16******* *************** ******@phx.gbl. ..
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?

"ZW" <an*******@disc ussions.microso ft.com> wrote in

message
news:13***** *************** ********@phx.gb l...
Hi Don,

Thanks for the reply.

However, it doesn't work.

Although I didn't mention, I already use
datagrid.Render Control(HtmlTex tWriter) 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.
>
>"ZW" <an*******@disc ussions.microso ft.com> wrote in
message
>news:04*** *************** **********@phx. gbl...
>> 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.ClearC ontent();
>> Response.ClearH eaders();
>> Response.Conten tType = "applicatio n/vnd.ms-excel";
>> //Response.Conten tType = "applicatio n/x-

msexcel"; // Same
>> result
>> Response.Charse t = string.Empty ;
>> this.EnableView State = false;
>> object content = Session["datagrid"];
>> if (content != null)
>> {
>> Response.Write( content.ToStrin g());
>> Response.End();
>> }
>>
>>
>> TIA
>>
>> ZW
>
>
>.
>
.

.

Nov 19 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2177
by: Mick Hardy | last post by:
Hi, Has anyone seen this weird behaviour or have any suggestions or can anyone reproduce it? The history: I converted a large third party DB from 97 to XP and it uses the TransferSpreadsheet method. This method requires a somewhat complicated spreadsheet to be open in order to work. A simple
11
4037
by: Mr. Smith | last post by:
Hello all, My code can successfully open, write to, format and save several worksheets in a workbook then save it by a given name, close and quit excel. My problem is that if I try and do it again, Excel hangs. OR if I open Excel again (say from a desktop icon) before I close Access, Excel hangs. (this has happened for both 97 & 2000...
2
6602
by: info | last post by:
I am pasting in a recordset from access to an excel sheet via VBA successfully. Then my routine copies a range of cells and pastes them into another range, this works fine every other time it runs. Every other run of the code it fails at the line Selection.Copy with a Runtime error 91:. I then run it again and it works fine. This is...
0
1452
by: midlothian | last post by:
I have some long Excel routines that I would like to run from my database in a hidden, second instance of the same Access db. The macro I pass to the shell command to open the second instance contains code to 'Hide' the database (from Dev's site) and also the code which runs the Excel routine. It then quits the database when the code has...
0
1081
by: JB | last post by:
Hi All, We have an ASP .Net application that has export to Excel functionality. We are using contenttype="application/vnd.ms-excel". The functionality works fine on Windows XP on the customer's machine but fails for Windows 2000 SP4, IE 6.02 SP1 and Office 2000. It shows the "missing file..." dialog box with the name of the aspx file as the...
0
2329
by: Nicholas Dreyer | last post by:
Operating System: Microsoft Windows Version 5.1 (Build 2600.xpsp_sp2_gdr.050301-1519 : Service Pack 2) Visual Basic: MIcrosoft Visual Basic 6.3 Version 9972 VBA: Retail 6.4.9972 Forms3: 11.0.6550 (comes with Excel 2003) The copy paste code below fails to copy the PrefixCharacter from cell "a1" to cell "a2" when compiled into a dll and...
8
2911
by: Johnny | last post by:
Hi all: I have an ASP.NET form that reads an Excel file and populates a datagrid. If I load the form in IE on the server, and select a local file, the code works fine. However if I load the form in IE from a client (http://server/readexcel.aspx) and try to read a local Excel file, the file cannot be opened. I imagine it's some kind of a...
7
93650
by: NeverLift | last post by:
This is probably answered elsewhere, but I've searched the Web and VBA for Excel manual, find no answers. I have a VBA-coded macro in an Excel workbook that is to open another existing workbook -- a .xls file, not .csv -- copy data from it, paste that into the original workbook where the macro resides, then close the source workbook. If I...
22
68618
by: robertgregson | last post by:
Using C#, .NET3.5, Visual Studio 2008 and WCF on Windows VISTA SP1, I have written a service, service host (as a C# console application) and a client. The service uses Microsoft.Office.Interop.Excel.Application to access an Excel file on the local hard drive, opens it (using Application.Workbooks.Open), reads out some data and the provides said...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7922
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6281
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5509
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5218
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2111
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1209
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.