Password Protected Excel Download using EPPLUS

前端 未结 4 669

I am exporting data in Excel form using EPPLUS Excel Library. I want that when excel downloaded it will ask for password. I have tried following code.

相关标签:
4条回答
  • 2021-01-02 21:47

    If you are saving the excel package into a MemoryStream (for sending as an email attachment) you have to do this:

    excelPackage.SaveAs(memoryStream, "pa$$w0rd");
    
    0 讨论(0)
  • 2021-01-02 21:50

    It's not documented, but you can do as following:

    package.Encryption.Password = "your password here";
    

    Then serve your package with Save() or GetAsByteArray() of your choice

    0 讨论(0)
  • 2021-01-02 21:50

    package.GetAsByteArray("sometest"); ---> this will protect your excel sheet with password sometest :)

    0 讨论(0)
  • 2021-01-02 22:07

    Just need to use the .Save overload with a password as the option:

    package.Save("password");
    

    Response To Comments

    To apply a password if saving via a byte array it is very similar:

    Byte[] bin = pck.GetAsByteArray("password");
    System.IO.File.WriteAllBytes(fullFilePath, bin);
    
    0 讨论(0)
提交回复
热议问题