使用NPOI的密码保护的Excel [英] Password protected excel using NPOI

查看:1192
本文介绍了使用NPOI的密码保护的Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.net c#应用程序,其中我单击按钮即可下载一个excel文件. 我使用的代码是

i have a .net c# application in which im downloading one excel file on button click. the code im using is

using NPOI.HSSF.UserModel;
using NPOI.HSSF.Util;
using NPOI.SS.UserModel;

然后输入一些代码.

HSSFWorkbook book = new HSSFWorkbook();
var sheet = book.CreateSheet("StatusReport");

一些用于格式化excel的代码,然后一些用于下载excel的代码.

some code for formatting the excel,then some code for downloading the excel.

 HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Charset = "utf-16";
            HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("windows-1250");
            HttpContext.Current.Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "MpiDischargeReport.xls"));
            HttpContext.Current.Response.ContentType = "application/ms-excel";
            book.Write(HttpContext.Current.Response.OutputStream);
            HttpContext.Current.ApplicationInstance.CompleteRequest();

这将帮助我下载excel,但是我需要将该excel设置为受密码保护的excel. 请帮忙.

this will help me to download the excel,but i need to make that excel as a password protected one. please help.

推荐答案

在1.2.5中不起作用,在2.0中可能起作用 尝试

This is not working in 1.2.5 may work in 2.0 Try

var sheet = book.CreateSheet("StatusReport");
            sheet.ProtectSheet("Password");

这篇关于使用NPOI的密码保护的Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆