title: EPPLUS export to excel protected View Issue ; Updated with previous Working Code
body: <p>I am able to export GridView to Excel successfully using Epplus. I have an issue that the excel is opening in <strong>protected view</strong> mode and  I have to explicitly click on <strong>enable editing</strong> button to edit. I want that the excel should generate directly in <strong>enable editing</strong> mode.
  I was able to do it without Epplus but I dont know how to do it with epplus.
  Here is the screenshot : 
  <a href="https://i.stack.imgur.com/kcb0s.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kcb0s.png" alt="enter image description here"></a></p>
  
  <p>Here is my Code : </p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  using System.Collections;
  using System.IO;
  using OfficeOpenXml;
  using OfficeOpenXml.Table;
  using System.Data;  
  
  public partial class _Default : System.Web.UI.Page
  {
      protected void Button1_Click(object sender, EventArgs e)
      {
          Response.Clear();
          Response.Charset = "";
          Response.ContentEncoding = System.Text.Encoding.UTF8;
          Response.Cache.SetCacheability(HttpCacheability.NoCache);
          Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
          Response.AddHeader("content-disposition", "attachment;filename=GridData.xlsx");
          // Here we create a DataTable with four columns.
          DataTable table = new DataTable();
          table.Columns.Add("Dosage", typeof(int));
          table.Columns.Add("Drug", typeof(string));
          table.Columns.Add("Patient", typeof(string));
          table.Columns.Add("Date", typeof(DateTime));
  
          table.Rows.Add(25, "Indocin", "David", DateTime.Now);
          table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now);
          table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now);
          table.Rows.Add(21, "Combivent", "Janet", DateTime.Now);
          table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now);
  
         using(ExcelPackage pck = new ExcelPackage())
         {
           ExcelWorksheet wsDt = pck.Workbook.Worksheets.Add("Sheet1");
           wsDt.Cells["A1"].LoadFromDataTable(table, true, TableStyles.None);
           wsDt.Cells[wsDt.Dimension.Address].AutoFitColumns();
  
           wsDt.Protection.IsProtected = false;
           Response.BinaryWrite(pck.GetAsByteArray());
         }
  
         Response.Flush();
         Response.End();
      }
  }
  </code></pre>
  
  <p><strong>Update</strong> Here is the Code that opens the excel file directly in "Enable Editing mode" : </p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  using System.Collections;
  using System.IO;
  using OfficeOpenXml;
  using OfficeOpenXml.Table;
  using System.Data;  
  
  public partial class _Default : System.Web.UI.Page
  {
      protected void Button1_Click(object sender, EventArgs e)
      {
          Response.Clear();
          Response.Charset = "";
          Response.ContentEncoding = System.Text.Encoding.UTF8;
          Response.Cache.SetCacheability(HttpCacheability.NoCache);
          Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
          Response.AddHeader("content-disposition", "attachment;filename=GridData.xls");
          // Here we create a DataTable with four columns.
          DataTable table = new DataTable();
          table.Columns.Add("Dosage", typeof(int));
          table.Columns.Add("Drug", typeof(string));
          table.Columns.Add("Patient", typeof(string));
          table.Columns.Add("Date", typeof(DateTime));
  
          table.Rows.Add(25, "Indocin", "David", DateTime.Now);
          table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now);
          table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now);
          table.Rows.Add(21, "Combivent", "Janet", DateTime.Now);
          table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now);
  
         //using(ExcelPackage pck = new ExcelPackage())
         //{
         //  ExcelWorksheet wsDt = pck.Workbook.Worksheets.Add("Sheet1");
         //  wsDt.Cells["A1"].LoadFromDataTable(table, true, TableStyles.None);
         //  wsDt.Cells[wsDt.Dimension.Address].AutoFitColumns();
  
         //  wsDt.Protection.IsProtected = false;
         //  Response.BinaryWrite(pck.GetAsByteArray());
         //}
  
          StringWriter sw = new StringWriter();
          HtmlTextWriter htw = new HtmlTextWriter(sw);
  
          GridView gv = new GridView();
          gv.DataSource = table;
          gv.DataBind();
  
          gv.RenderControl(htw);
         Response.Write(sw.ToString());
         Response.Flush();
         Response.End();
      }
  }
  </code></pre>