示例#1
0
 private void ReadModules()
 {
     foreach (var modul in Modules)
     {
         var    stream = Document.Storage.SubStorage["VBA"].DataStreams[modul.streamName];
         var    byCode = CompoundDocument.DecompressPart(stream, (int)modul.ModuleOffset);
         string code   = Encoding.GetEncoding(CodePage).GetString(byCode);
         int    pos    = 0;
         while (pos + 9 < code.Length && code.Substring(pos, 9) == "Attribute")
         {
             int      linePos = code.IndexOf("\r\n", pos);
             string[] lineSplit;
             if (linePos > 0)
             {
                 lineSplit = code.Substring(pos + 9, linePos - pos - 9).Split('=');
             }
             else
             {
                 lineSplit = code.Substring(pos + 9).Split(new char[] { '=' }, 1);
             }
             if (lineSplit.Length > 1)
             {
                 lineSplit[1] = lineSplit[1].Trim();
                 var attr =
                     new ExcelVbaModuleAttribute()
                 {
                     Name     = lineSplit[0].Trim(),
                     DataType = lineSplit[1].StartsWith("\"") ? eAttributeDataType.String : eAttributeDataType.NonString,
                     Value    = lineSplit[1].StartsWith("\"") ? lineSplit[1].Substring(1, lineSplit[1].Length - 2) : lineSplit[1]
                 };
                 modul.Attributes._list.Add(attr);
             }
             pos = linePos + 2;
         }
         modul.Code = code.Substring(pos);
     }
 }
 private void ReadModules()
 {
     foreach (var modul in Modules)
     {
         var stream = Document.Storage.SubStorage["VBA"].DataStreams[modul.streamName];
         var byCode = CompoundDocument.DecompressPart(stream, (int)modul.ModuleOffset);
         string code = Encoding.GetEncoding(CodePage).GetString(byCode);
         int pos=0;
         while(pos+9<code.Length && code.Substring(pos,9)=="Attribute")
         {
             int linePos=code.IndexOf("\r\n",pos);
             string[] lineSplit;
             if(linePos>0)
             {
                 lineSplit = code.Substring(pos + 9, linePos - pos - 9).Split('=');
             }
             else
             {
                 lineSplit=code.Substring(pos+9).Split(new char[]{'='},1);
             }
             if (lineSplit.Length > 1)
             {
                 lineSplit[1] = lineSplit[1].Trim();
                 var attr = 
                     new ExcelVbaModuleAttribute()
                 {
                     Name = lineSplit[0].Trim(),
                     DataType = lineSplit[1].StartsWith("\"") ? eAttributeDataType.String : eAttributeDataType.NonString,
                     Value = lineSplit[1].StartsWith("\"") ? lineSplit[1].Substring(1, lineSplit[1].Length - 2) : lineSplit[1]
                 };
                 modul.Attributes._list.Add(attr);
             }
             pos = linePos + 2;
         }
         modul.Code=code.Substring(pos);
     }
 }