导出excel没有在mozilla中获取文件扩展名.xls [英] exported excel not getting file extension .xls in mozilla

查看:55
本文介绍了导出excel没有在mozilla中获取文件扩展名.xls的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,

我正在使用VS 2008,C#.net,asp.net。

我将数据导出到excel 2003.

导出的excel在IE和Chrome中的类型为.xls。

但是在mozilla中不是.xls类型。打开该文件时,它会询问您要打开哪个程序?

是什么原因?



程序如下所示。



Hi Friends,
I am using VS 2008,C#.net,asp.net.
I am exporting the data to excel 2003.
The exported excel is of the type .xls in IE and Chrome.
But it is not .xls type in mozilla.When open that file, it is asking which program you want to open?
What is the reason?

the program is mentioned below.

private void ExportDataSetToExcel()
      {
          try
          {
              DataSet Ds = new DataSet();
              DataTable DT = new DataTable();

              string param = hidType.Get("Type").ToString();
              string[] codes = param.Split('.');
              if (codes.Length == 1)
                  FillGrid(Convert.ToString(param));
              else
                  FillDrillDownGrid(codes[1], codes[0]);
              if (hidType.Get("Type").ToString() == "2")
              {
                  DT.Columns.Add("<b>Sub Group Code</b>");
                  DT.Columns.Add("<b>Account Sub Group</b>");
              }
              else if (hidType.Get("Type").ToString() == "3")
              {
                  DT.Columns.Add("<b>Group Code</b>");
                  DT.Columns.Add("<b>Account Group</b>");
              }
              else
              {
                  DT.Columns.Add("<b>Acc.Head Code</b>");
                  DT.Columns.Add("<b>Account Head</b>");
              }

                  DT.Columns.Add("<b>Debit</b>");
                  DT.Columns.Add("<b>Credit</b>");


              for (int j = 0; j < grdTrialBal.VisibleRowCount; j++)
              {
                  DataRow DR;
                  DR = DT.NewRow();
                  if (hidType.Get("Type").ToString() == "2")
                  {
                      DR["<b>Sub Group Code</b>"] = grdTrialBal.GetRowValues(j, "ahdUserCode");
                      DR["<b>Account Sub Group</b>"] = grdTrialBal.GetRowValues(j, "ahdname");
                  }
                  else if (hidType.Get("Type").ToString() == "3")
                  {
                      DR["<b>Group Code</b>"] = grdTrialBal.GetRowValues(j, "ahdUserCode");
                      DR["<b>Account Group</b>"] = grdTrialBal.GetRowValues(j, "ahdname");
                  }
                  else
                  {
                      DR["<b>Acc.Head Code</b>"] = grdTrialBal.GetRowValues(j, "ahdUserCode");
                      DR["<b>Account Head</b>"] = grdTrialBal.GetRowValues(j, "ahdname");
                  }
                  if (Convert.ToDecimal(grdTrialBal.GetRowValues(j, "trnAhdDrAmt")) != 0)
                  {
                   DR["<b>Debit</b>"] = Convert.ToDecimal(grdTrialBal.GetRowValues(j, "trnAhdDrAmt"));
                  }
                  if (Convert.ToDecimal(grdTrialBal.GetRowValues(j, "trnAhdCrAmt")) != 0)
                  {
                   DR["<b>Credit</b>"] = Convert.ToDecimal(grdTrialBal.GetRowValues(j, "trnAhdCrAmt"));
                  }



                  CrAmount = CrAmount + Convert.ToDecimal(grdTrialBal.GetRowValues(j, "trnAhdCrAmt"));
                  DrAmount = DrAmount + Convert.ToDecimal(grdTrialBal.GetRowValues(j, "trnAhdDrAmt"));

                  DT.Rows.Add(DR);
              }
              DataRow Dr1;
              Dr1 = DT.NewRow();

              if (hidType.Get("Type").ToString() == "2")
              {
                  Dr1["<b>Sub Group Code</b>"] = "";
                  Dr1["<b>Account Sub Group</b>"] = "<b>Total</b>";
              }
              else if (hidType.Get("Type").ToString() == "3")
              {
                  Dr1["<b>Group Code</b>"] = "";
                  Dr1["<b>Account Group</b>"] = "<b>Total</b>";
              }
              else
              {
                  Dr1["<b>Acc.Head Code</b>"] = "";
                  Dr1["<b>Account Head</b>"] = "<b>Total</b>";
              }

              Dr1["<b>Debit</b>"] = "<b>" + DrAmount.ToString("#0.#0") + "</b>";
              Dr1["<b>Credit</b>"] = "<b>" + CrAmount.ToString("#0.#0") + "</b>";

              DT.Rows.Add(Dr1);

              DataGrid dg = new DataGrid();

              dg.DataSource = DT;
              dg.DataBind();

              String strFileName = "Trial Balance Account Group Wise.xls";
              if (hidType.Get("Type").ToString() == "2")
              {
                  strFileName = "Trial Balance Account Sub Group Wise.xls";
              }
              else if (hidType.Get("Type").ToString() == "3")
              {
                  strFileName = "Trial Balance Account Group Wise.xls";
              }
              else
              {
                  strFileName = "Trial Balance Account Head Wise.xls";
              }
              Response.ClearContent();
              Response.AddHeader("content-disposition", "attachment; filename=" + strFileName);
              Response.ContentType = "application/excel";
              System.IO.StringWriter sw = new System.IO.StringWriter();
              HtmlTextWriter htw = new HtmlTextWriter(sw);

              CommonFunctions cf = new CommonFunctions();
              String[] aTo = mskToDate1.Text.Split(new[] { '/', '-' });
              String dTo;
              dTo = aTo[0] + "/" + cf.getMonthName(Convert.ToInt32(aTo[1])) + "/" + aTo[2];

              if (hidType.Get("Type").ToString() == "2")
              {
                  htw.WriteLine("<b><u><font size='5'>" + "Trial Balance - Account Sub Group Wise - As on :" + dTo + " </font></u></b>");
              }
              else if (hidType.Get("Type").ToString() == "3")
              {
                  htw.WriteLine("<b><u><font size='5'>" + "Trial Balance - Account Group Wise - As on :" + dTo + " </font></u></b>");
              }
              else
              {
                  htw.WriteLine("<b><u><font size='5'>" + "Trial Balance - Account Head Wise - As on : " + dTo + " </font></u></b>");
              }

              dg.RenderControl(htw);
              Response.Write(sw.ToString());
              Response.End();

              dg = null;
              dg.Dispose();
          }
          catch (Exception ex)
          {

          }
      }

推荐答案

使用



use

Response.AddHeader("Content-Disposition", "attachment; filename=\"" + strFileName+ "\"");


这可能对你有帮助....



This might be helpfull for you....

protected void GenerateExcel(DataTable dta)
   {
           using (XLWorkbook wb = new XLWorkbook())
           {

               wb.Worksheets.Add(dta, "Sheet1");
               Response.Clear();
               Response.Buffer = true;
               Response.Charset = "";
               Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
               Response.AddHeader("content-disposition", "attachment;filename=EmploymentTracker.xls");
               using (MemoryStream MyMemoryStream = new MemoryStream())
               {
                   wb.SaveAs(MyMemoryStream);
                   MyMemoryStream.WriteTo(Response.OutputStream);
                   Response.Flush();
                   Response.End();
               }
           }
       
   }









如果有帮助,请将此标记为答案......:)



Please mark this as answer if this helps... :)


这篇关于导出excel没有在mozilla中获取文件扩展名.xls的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆