Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在ASP.Net中将GridView导出到具有密码保护(安全)的Excel 我已经完成了从gridview导出excel,但希望在导出时也在excel中添加密码…帮助我可能的副本 protected void Btn_Xls_Click(object _.net - Fatal编程技术网

如何在ASP.Net中将GridView导出到具有密码保护(安全)的Excel 我已经完成了从gridview导出excel,但希望在导出时也在excel中添加密码…帮助我可能的副本 protected void Btn_Xls_Click(object

如何在ASP.Net中将GridView导出到具有密码保护(安全)的Excel 我已经完成了从gridview导出excel,但希望在导出时也在excel中添加密码…帮助我可能的副本 protected void Btn_Xls_Click(object ,.net,.net,如何在ASP.Net中将GridView导出到具有密码保护(安全)的Excel 我已经完成了从gridview导出excel,但希望在导出时也在excel中添加密码…帮助我可能的副本 protected void Btn_Xls_Click(object sender, ImageClickEventArgs e) { string attachment = "attachment; filename=MonthlyAttendanceReport.xls"; string sh

如何在ASP.Net中将GridView导出到具有密码保护(安全)的Excel
我已经完成了从gridview导出excel,但希望在导出时也在excel中添加密码…帮助我可能的副本
protected void Btn_Xls_Click(object sender, ImageClickEventArgs e)
{
    string attachment = "attachment; filename=MonthlyAttendanceReport.xls";
    string sheetProtectPassword = "123";
    Response.ClearContent();
    Response.AddHeader("content-disposition", attachment);
    Response.ContentType = "application/ms-excel";

    StringWriter sw = new StringWriter();
    HtmlTextWriter htw = new HtmlTextWriter(sw);
    // Create a form to contain the grid
    HtmlForm frm = new HtmlForm();
    rptOrder.Parent.Controls.Add(frm);
    frm.Attributes["runat"] = "server";
    frm.Controls.Add(rptOrder);
    frm.RenderControl(htw);


    Response.Write(sw.ToString());
    Response.End();


   //Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
   // Microsoft.Office.Interop.Excel.Sheets objSheets;
   // Microsoft.Office.Interop.Excel._Worksheet objSheet;
   // string sheetProtectPassword = "123";
   // string workbookPath = "Path where excel file is stored";
   // Microsoft.Office.Interop.Excel.Workbook m_objBook = excelApp.Workbooks.Open(workbookPath, 0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);
   // objSheets = m_objBook.Worksheets;
   // objSheet = (Excel._Worksheet)objSheets.get_Item(1); 
   // objSheet.Protect(sheetProtectPassword, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true);

}