现在的位置: 首页 > 综合 > 正文

Open XML SDK 2.0

2012年08月29日 ⁄ 综合 ⁄ 共 669字 ⁄ 字号 评论关闭

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");
    }

抱歉!评论已关闭.