0

Excelファイルを作成して開く「ダウンロード」ボタンがあります。Firefox では問題なく動作しますが、IE ではボタンをクリックしても何も起こりません。誰かが理由、またはそれを修正する方法を知っていますか? コードは次のとおりです。

<div align="center" id="excelDiv" runat="server">
    <a id="excelDownloadLink" runat="server">
    <input type="button" id="btnSubmitDownload" value="Download" />
    </a>
    <br /><br />
    <span id="validationResults" style="color:Red"></span><br />
</div>

コードビハインド:

 protected void Page_Load(object sender, EventArgs e)
    {
        excelDownloadLink.ServerClick += new System.EventHandler(ExcelDownload);

        DataCounts.DataSource = db.GetRequestCountByState();
        DataCounts.DataBind();
    }

    public override void VerifyRenderingInServerForm(Control control)
    {
        /* Confirms that an HtmlForm control is rendered for the specified ASP.NET
           server control at run time. */
    }

    public void ExcelDownload(object sender, EventArgs e)
    {
        DateTime startDateVal = DateTime.Parse(startDate.Value.ToString());
        DateTime endDateVal = DateTime.Parse(endDate.Value.ToString());

        if (searchType.Value == "Requests by Status")
        {

            DataSet statusExtract = db.GetStatusExport(startDateVal, endDateVal);
            DataTable statusExtractTable = statusExtract.Tables[0];

            DumpExcel(statusExtractTable, "Requests by Status");
        }
        else if (searchType.Value == "Database Extract")
        {
            DataSet dataExtract = db.GetDataExport(startDateVal, endDateVal);
            DataTable dataExtractTable = dataExtract.Tables[0];

            DumpExcel(dataExtractTable, "Database Extract");
        }
    }

    private void DumpExcel(DataTable tbl, string type)
    {
        using (ExcelPackage pck = new ExcelPackage())
        {
            //Create the worksheet
            ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Database Extract");

            //Load the datatable into the sheet, starting from cell A1. Print the column names on row 1
            ws.Cells["A2"].LoadFromDataTable(tbl, false);
            Response.Clear();

            switch (type)
            { 
                case "Database Extract":
                    //Header Titles
                    ws.Cells["A1"].Value = "RequestNumber";
                    ws.Cells["B1"].Value = "State";
                    ws.Cells["C1"].Value = "Status";
                    ws.Cells["D1"].Value = "Queue";
                    ws.Cells["E1"].Value = "OEM";
                    ws.Cells["F1"].Value = "Raytheon Material Number";
                    ws.Cells["G1"].Value = "Mfg Part Number";
                    ws.Cells["H1"].Value = "Material Charge Number";
                    ws.Cells["I1"].Value = "Program";
                    ws.Cells["J1"].Value = "Purchase Order";
                    ws.Cells["K1"].Value = "Purchase Requisition";
                    ws.Cells["L1"].Value = "Business Unit";
                    ws.Cells["M1"].Value = "Site";
                    ws.Cells["N1"].Value = "Buyer";
                    ws.Cells["O1"].Value = "Requisitioner";
                    ws.Cells["P1"].Value = "Component Engineer";
                    ws.Cells["Q1"].Value = "Responsible Engineer";
                    ws.Cells["R1"].Value = "Quality Engineer";
                    ws.Cells["S1"].Value = "Item Type";
                    ws.Cells["T1"].Value = "Material Location";
                    ws.Cells["U1"].Value = "Justification";
                    ws.Cells["V1"].Value = "Internal Testing Required";
                    ws.Cells["W1"].Value = "External Testing Required";
                    ws.Cells["X1"].Value = "Create Date";
                    ws.Cells["Y1"].Value = "Create Comments";
                    ws.Cells["Z1"].Value = "Closed Date";
                    ws.Column(26).Style.Numberformat.Format = @"m/d/yy h:mm:ss AM/PM";
                    ws.Cells["AA1"].Value = "Cancelled Date";
                    ws.Column(27).Style.Numberformat.Format = @"m/d/yy h:mm:ss AM/PM";
                    ws.Cells["AB1"].Value = "qty";
                    ws.Cells["AC1"].Value = "Minimum Buy Qty";
                    ws.Cells["AD1"].Value = "Broker Name";
                    ws.Cells["AE1"].Value = "Second Tier Supplier";
                    ws.Cells["AF1"].Value = "Requisitioner Date";
                    ws.Column(32).Style.Numberformat.Format = @"m/d/yy h:mm:ss AM/PM";
                    ws.Cells["AG1"].Value = "Requisitioner Comments";
                    ws.Cells["AH1"].Value = "CE Date";
                    ws.Column(34).Style.Numberformat.Format = @"m/d/yy h:mm:ss AM/PM";
                    ws.Cells["AI1"].Value = "CE Comments";
                    ws.Cells["AJ1"].Value = "REA Date";
                    ws.Column(36).Style.Numberformat.Format = @"m/d/yy h:mm:ss AM/PM";
                    ws.Cells["AK1"].Value = "REA Comments";
                    ws.Cells["AL1"].Value = "PQE Date";
                    ws.Column(38).Style.Numberformat.Format = @"m/d/yy h:mm:ss AM/PM";
                    ws.Cells["AM1"].Value = "PQE Comments";
                    ws.Cells["AN1"].Value = "PQE Customer Approval";
                    ws.Cells["AO1"].Value = "PQE NFD Purchase Request Approval";
                    ws.Cells["AP1"].Value = "PQE Additional Internal Testing";
                    ws.Cells["AQ1"].Value = "PQE Additional External Testing";
                    ws.Cells["AR1"].Value = "REA NFD Purchase Request";
                    ws.Cells["AS1"].Value = "REA Additional Internal Testing";
                    ws.Cells["AT1"].Value = "REA Additional External Testing";
                    ws.Cells["AU1"].Value = "MA Date";
                    ws.Column(47).Style.Numberformat.Format = @"m/d/yy h:mm:ss AM/PM";
                    ws.Cells["AV1"].Value = "MA Approval";
                    ws.Cells["AW1"].Value = "MA Comments";

                    ws.Column(1).AutoFit();
                    ws.Column(2).AutoFit();
                    ws.Column(3).AutoFit();
                    ws.Column(4).AutoFit();
                    ws.Column(5).AutoFit();
                    ws.Column(6).AutoFit();
                    ws.Column(7).AutoFit();
                    ws.Column(8).AutoFit();
                    ws.Column(9).AutoFit();
                    ws.Column(10).AutoFit();
                    ws.Column(11).AutoFit();
                    ws.Column(12).AutoFit();
                    ws.Column(13).AutoFit();
                    ws.Column(14).AutoFit();
                    ws.Column(15).AutoFit();
                    ws.Column(16).AutoFit();
                    ws.Column(17).AutoFit();
                    ws.Column(18).AutoFit();
                    ws.Column(19).AutoFit();
                    ws.Column(20).AutoFit();
                    ws.Column(21).AutoFit();
                    ws.Column(22).AutoFit();
                    ws.Column(23).AutoFit();
                    ws.Column(24).AutoFit();
                    ws.Column(25).AutoFit();
                    ws.Column(26).AutoFit();
                    ws.Column(27).AutoFit();
                    ws.Column(28).AutoFit();
                    ws.Column(29).AutoFit();
                    ws.Column(30).AutoFit();
                    ws.Column(31).AutoFit();
                    ws.Column(32).AutoFit();
                    ws.Column(33).AutoFit();
                    ws.Column(34).AutoFit();
                    ws.Column(35).AutoFit();
                    ws.Column(36).AutoFit();
                    ws.Column(37).AutoFit();
                    ws.Column(38).AutoFit();
                    ws.Column(39).AutoFit();
                    ws.Column(40).AutoFit();
                    ws.Column(41).AutoFit();
                    ws.Column(42).AutoFit();
                    ws.Column(43).AutoFit();
                    ws.Column(44).AutoFit();
                    ws.Column(45).AutoFit();
                    ws.Column(46).AutoFit();
                    ws.Column(47).AutoFit();
                    ws.Column(48).AutoFit();
                    ws.Column(49).AutoFit();
                    break;

                case "Requests by Status":
                    ws.Cells["A1"].Value = "RequestNumber";
                    ws.Cells["B1"].Value = "Status";
                    ws.Cells["C1"].Value = "Queue";
                    ws.Cells["D1"].Value = "OEM";
                    ws.Cells["E1"].Value = "Raytheon Material Number";
                    ws.Cells["F1"].Value = "Mfg Part Number";
                    ws.Cells["G1"].Value = "Material Charge Number";
                    ws.Cells["H1"].Value = "Program";

                    ws.Column(1).AutoFit();
                    ws.Column(2).AutoFit();
                    ws.Column(3).AutoFit();
                    ws.Column(4).AutoFit();
                    ws.Column(5).AutoFit();
                    ws.Column(6).AutoFit();
                    ws.Column(7).AutoFit();
                    ws.Column(8).AutoFit();


                    break;
            }      

            //Format the header for all columns
            using (ExcelRange rng = ws.Cells["A1:AW1"])
            {
                rng.Style.Font.Bold = true;
                //Set Pattern for the background to Solid
                rng.Style.Fill.PatternType = ExcelFillStyle.Solid;
                //Set color to dark blue
                rng.Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.FromArgb(79, 129, 189));
                rng.Style.Font.Color.SetColor(System.Drawing.Color.White);
            }

            using (ExcelRange cols = ws.Cells["C1:C2000"])
            {

            }



            //Write it back to the client
            Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
            Response.AddHeader("content-disposition", "attachment;  filename=NFDDatabaseExtract.xlsx");
            Response.BinaryWrite(pck.GetAsByteArray());

            Response.End();
        }
    }
4

1 に答える 1

0

理解した。代わりにサーバー コントロール (asp:Button) を作成し、サーバー コントロールの OnClick イベントを使用して、ExcelDownload をポイントしました。以前、IE とは異なる方法で IE の名前付けコントロールに問題があったことは知っていますが、それが問題だったのかもしれません。確かではありませんが、とにかく、それを修正しました。

于 2012-06-01T19:08:59.947 に答える