2016-11-09 2 views
0

選択した日付に基づいてExcelレポートを生成する必要があります。すべてのものはうまく動作しますが、私のExcelシートは生成されませんが、Webフォームでエクスポートしようとすると正常に動作します。Excelシートがエクスポートされていません

:私はここ..そのは動作していない

をマスターページとコンテンツページを使用している場合でも、CSコード私のコード

のaspx

<center> 
<table> 
    <tr> 
     <td> 
      <asp:Label ID="Label1" runat="server" Text="Start Date:" style="color:white"></asp:Label> 
     </td> 
     <td> 
      <asp:TextBox ID="datepicker" runat="server"></asp:TextBox> 
     </td> 
     <td> 
      <img src="../Images/calendar.gif" id ="datepic"/> 
      <cc1:calendarextender ID="ceFromDate" runat="server" TargetControlID="datepicker" 
                 Format="dd-MMM-yyyy" Enabled="True" PopupButtonID="datepic" CssClass="black"> 
                </cc1:calendarextender> 
     </td> 
    </tr> 
    <br /> 
    <br /> 
    <tr> 
     <td> 
      <asp:Label ID="Label2" runat="server" Text="End Date:" style="color:white"></asp:Label> 
     </td> 
     <td> 
      <asp:TextBox ID="datepicker1" runat="server"></asp:TextBox> 
     </td> 
     <td> 
      <img src="../Images/calendar.gif" id="datepic1" /> 
      <cc1:calendarextender ID="Calendarextender1" runat="server" TargetControlID="datepicker1" 
                 Format="dd-MMM-yyyy" Enabled="True" PopupButtonID="datepic1" CssClass="black"> 
                </cc1:calendarextender> 
     </td> 
    </tr> 
    <tr> 
     <td> 
      <asp:Button ID="Button1" runat="server" Text="Get Report" OnClick="Button1_Click" /> 
     </td> 
    </tr> 
</table> 
    <asp:GridView ID="GridView1" runat="server" ></asp:GridView> 
    </center> 

です

protected void Button1_Click(object sender, EventArgs e) { using (OracleConnection con = new OracleConnection(constr)) { //for getting id con.Open(); OracleCommand cmd = new OracleCommand("select adcomplain_no as \"AD COMPLAIN NO\",to_char(COMPLAINT_DATE,'DD/MM/YY') as \"COMPLAINT DATE\",nature_of_complaint as \"NATURE OF COMPLAINT\",(select categoryname from crs_categorynew where crsid=complaint_categoryID)as \"CATEGORY NAME\",(SELECT subcategoryname FROM CRS_SUDCATEGORYNEW WHERE CRSSUBID=complaint_subcategory) as \"SUB CATEGORY NAME\",seat_location AS \"SEAT LOCATION\",seatno AS \"SEAT NO\",extensionno AS \"EXTENSION NO\",to_char(entry_date,'DD/MM/YY')as \"ENTRY DATE\" ,(select staffno||'-'||NAME as name from employee where staffno=entry_by) as \"ENTRY BY\" ,(CASE STATUSFLAG WHEN 'U' THEN 'Un Allotted' WHEN 'AN' THEN 'Allotted' WHEN 'B' THEN 'Being Completed' WHEN 'C' THEN 'Completed' WHEN 'UA' THEN 'Un Attented' ELSE '' END)as \"STATUS\",(select staffno||'-'||NAME as name from employee where staffno=alloted_person) as \"ALLOTED PERSON\",to_char(target_date,'DD/MM/YY') as \"TARGET DATE\",(select staffno||'-'||NAME as name from employee where staffno=alloted_by) as \"ALLOTED BY\",to_char(alloted_date,'DD/MM/YY') as \" ALLOTED DATE\",complain_reason as SOLUTION,to_char(complain_statusdate, 'DD/MM/YY')as \"COMPLAIN STATUS DATE\",(select staffno||'-'||NAME as name from employee where staffno=complain_statusby)AS \"COMPLAIN STATUS BY\" from crs_complaint where complaint_date between (TO_DATE('" + datepicker.Text + "', 'dd/mm/yyyy')) and (TO_DATE('" + datepicker1.Text + "', 'dd/mm/yyyy'))", con); OracleDataAdapter oda = new OracleDataAdapter(cmd); DataTable dt = new DataTable(); oda.Fill(dt); if (dt.Rows.Count > 0) { GridView1.DataSource = dt; GridView1.DataBind(); } Response.Clear(); Response.Buffer = true; Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.xls"); Response.Charset = ""; Response.ContentType = "application/vnd.ms-excel"; StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); for (int i = 0; i < GridView1.Rows.Count; i++) { //Apply text style to each Row GridView1.Rows[i].Attributes.Add("class", "textmode"); } GridView1.RenderControl(hw); string headerTable = @"<h1>Service Request List from '" + datepicker.Text + "' to '" + datepicker1.Text + "'</h1>"; //style to format numbers to string string style = @"<style> .textmode { mso-number-format:\@; } </style>"; //Range rg = (Excel.Range)worksheetobject.Cells[1, 1]; //rg.EntireColumn.NumberFormat = "MM/DD/YYYY"; Response.Write(headerTable); Response.Output.Write(sw.ToString()); Response.Flush(); Response.End(); con.Close(); } } public override void VerifyRenderingInServerForm(Control control) { /* Confirms that an HtmlForm control is rendered for the specified ASP.NET server control at run time. */ } 
+0

working'ない '定義します。エラー、空のシート、間違ったデータがありますか?詳細な情報がなければ、あなたの質問は十分ではありません。 – VDWWD

答えて

0

cretaeのUpdatePanel内のボタンのトリガーを、これはあなたの問題を解決することがあります。..

</ContentTemplate> 
     <Triggers> 
      <asp:PostBackTrigger ControlID="Button1" /> 
     </Triggers> 
    </asp:UpdatePanel> 
+0

私は作業していなくても試してみました.... – hyugaazia

+0

両方の機能をサプレートすることができます。..... 2つのボタンを使用し、最初のボタンをクリックしてgridviewをクリックし、2番目のボタンをクリックしてExcelにエクスポートします。 .iマスターページと更新パネルで同じものを使用しています –

+0

ありがとうございました。 – hyugaazia

関連する問題