Click here to Skip to main content
15,908,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends,

I am using VS 2008,asp.net,C#.net.
I have a web application which uses export to excel features.
The exported excel sheet file.xls is not opening in few systems when double click on file.
We need to browse and select the software each time in which it has to open.
How to solve this?
I am using the following code to export to excel 2003.
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename=file.xls");
Response.ContentType = "application/excel";



Thanks in advance
george n t
Posted
Updated 30-Jan-14 20:28pm
v2
Comments
Richard MacCutchan 31-Jan-14 3:52am    
What happens on the systems where it does not open? Are you sure they have Excel installed?
george@84 31-Jan-14 5:02am    
Hi Richard. Excel is installed in the system.
Richard MacCutchan 31-Jan-14 5:03am    
Fine, but you really need to explain in detail what is happening if you want some help. We cannot guess what problems you are seeing.
george@84 31-Jan-14 5:36am    
I have downloaded the exported excel file. exported excel sheet is of the type file but it is not the required .xls extension. when double click on the file,it is asking "how do you want to open this file?" .if we select excel ,it is showing a question "The file you are opening is in different format than specified by the file extension.Verify that the file is corrupted and is from a trusted source before opening the file.Do you want to open the file now? " when click on yes, the data in the excel sheet are displaying.


My program is written below

private void ExportDataSetToExcel()
{
try
{
DataTable DT = new DataTable();
FillGrid(hidType.Get("Type").ToString());

if (hidType.Get("Type").ToString() == "2")
{
DT.Columns.Add("Account Sub Group");
}
else if (hidType.Get("Type").ToString() == "3")
{
DT.Columns.Add("Account Group");
}
DT.Columns.Add("Account Head");
DT.Columns.Add("Debit");
DT.Columns.Add("Credit");

for (int j = 0; j < grdTrialBal.VisibleRowCount; j++)
{
DataRow DR;
DR = DT.NewRow();
if (hidType.Get("Type").ToString() == "2")
{
if ((grdTrialBal.GetRowValues(j, "DispOrder").ToString()) == "0")
{
DR["Account Sub Group"] = grdTrialBal.GetRowValues(j, "Sub Group");
}
else
{
DR["Account Sub Group"] = "" +grdTrialBal.GetRowValues(j, "Sub Group")+ "";
}

}
else if (hidType.Get("Type").ToString() == "3")
{
if ((grdTrialBal.GetRowValues(j, "DispOrder").ToString()) == "0")
{
DR["Account Group"] = grdTrialBal.GetRowValues(j, "Sub Group");
}
else
{
DR["Account Group"] = "" + grdTrialBal.GetRowValues(j, "Sub Group") + "";
}
}

if ((grdTrialBal.GetRowValues(j, "DispOrder").ToString()) == "0")
{
DR["Account Head"] = grdTrialBal.GetRowValues(j, "Acc Head");
}
else
{
DR["Account Head"] = "" + grdTrialBal.GetRowValues(j, "Acc Head")+ "";
}

if (grdTrialBal.GetRowValues(j, "trnAhdDrAmt") != System.DBNull.Value)
{
if ((grdTrialBal.GetRowValues(j, "trnAhdDrAmt").ToString()) != "")
{
Decimal DrAmt =Convert.ToDecimal(grdTrialBal.GetRowValues(j, "trnAhdDrAmt"));
if (DrAmt != 0)
{
if ((grdTrialBal.GetRowValues(j, "DispOrder").ToString()) == "0")
{
DR["Debit"] = DrAmt;
}
else
{
DR["Debit"] = "" + DrAmt + "";
}
}
else
{
DR["Debit"] = "";
Richard MacCutchan 31-Jan-14 6:23am    
I don't see anything in the above that creates an Excel file. Also, you say that the file does not have a .xls extension, which is why it will not open automatically.

1 solution

It sounds like the users who can't open it are using a newer version of Excel which uses .xlsx format instead of .xls. It's still compatible. You can still open it but it will give you the warning about its format.

If it doesn't open automatically just add a file association for it. Choose Open With and then select Excel and check the box that says Always use this program.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900