Open XML SDK 2.0

http://msdn.microsoft.com/en-us/library/bb448854

http://msdn.microsoft.com/en-us/library/gg278316%28v=office.14%29

http://msdn.microsoft.com/en-us/library/cc850837 ---how to 

 

Excel加密

将想要设定的密码传入Mothed 1得到加密密码,将加密密码传给workbookPassword,即实现加密。

SheetProtection wSheetProtection = new SheetProtection() { Password = workbookPassword,Sheet = true, Objects = true, Scenarios = true };

 

Mothed 1 :

 

    public String GetSheetPassword(String password)
    {
      Int32 pLength = password.Length;
      Int32 hash = 0;
      if (pLength == 0) return hash.ToString("X");

      for (Int32 i = pLength - 1; i >= 0; i--)
      {
        hash = hash >> 14 & 0x01 | hash << 1 & 0x7fff;
        hash ^= password[i];
      }
      hash = hash >> 14 & 0x01 | hash << 1 & 0x7fff;
      hash ^= 0x8000 | 'N' << 8 | 'K';
      hash ^= pLength;
      return hash.ToString("X");
    }

posted on 2012-08-28 16:20  傍晚雨  阅读(332)  评论(0编辑  收藏  举报