vimalendu kuamar

vimalendu kuamar

  • NA
  • 46
  • 8.2k

Export excel with password

Apr 7 2016 2:17 AM

I need to  to export  excel with  password  from  Grid view . I am using following Code  for same

public ActionResult DataExportExcel(GridView GridView1, string FileName, int FontSize)
        {
            GridView1.Font.Size = FontSize;
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);
             GridView dataGridView1 = new GridView();
          
          
            
            Response.Clear();
          Response.Buffer = true;
       Response.AddHeader("content-disposition""attachment;filename=" + FileName.Trim() + ".xls");
            Response.Charset = "";
           Response.ContentType = "application/vnd.ms-excel";
            
           
            int RowCount= GridView1.Rows.Count;
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
               // GridView1.Rows[i].Attributes.Add("class", "textmode");
                GridView1.Rows[i].Height = 33;
                GridView1.Rows[i].Cells[5].Wrap = false;
                GridView1.Rows[i].Cells[5].Style.Add("mso-number-format", TestFormat(GridView1.Rows[i].Cells[5].Text.Length));
               
            }
            GridView1.Rows[RowCount-1].Cells[3].Font.Bold = true;
            GridView1.Rows[RowCount - 1].Cells[4].Font.Bold = true;
            GridView1.RenderControl(hw);
            GridView1.HeaderStyle.Height = 33;
            GridView1.FooterStyle.Height = 33;
 
            dataGridView1 = GridView1;          
 
 
 
            Response.Output.Write(Convert.ToString(sw));
            Response.Flush();
            Response.End();

return View();
       }


So pls Help me 
  
 


 


Answers (3)