how to export workbook NPOI to excel file with password

 on Saturday, October 5, 2019  

code example how to write excel with NPOI library used password
        public void Print(string fileName)
        { 
            // print disini 
            XSSFWorkbook xssfworkbook = CreateReport();
            if (xssfworkbook != null)
            {
                string password = "123As";
                MemoryStream mStream = new MemoryStream(); 
                xssfworkbook.Write(mStream);
                //to ensure memory stream can be expandable 
                Stream stream = new MemoryStream(); 
                stream.Write(mStream.ToArray(), 0, mStream.ToArray().Length); 
                using (MemoryStream memOutput = new MemoryStream()) 
                { 
                    Context.Response.BinaryWrite(Utilities.SetPassword(stream, password)); 
                    Context.Response.ContentType = "application/pdf"; 
                    Context.Response.AddHeader("content-disposition", string.Format("attachment;filename={0}.xlsx", fileName)); 
                    Context.Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache); 
                    Context.Response.End(); 
                }
            }
        }
how to export workbook NPOI to excel file with password 4.5 5 .NET-1235 Saturday, October 5, 2019 NPOI with password code example how to write excel with NPOI library used password public void Print(string fileName) { // print ...


No comments:

Post a Comment

Copyright © .Net-1235. All Rights Reserved.