Ejemplo n.º 1
0
 // Token: 0x0600015A RID: 346 RVA: 0x0000790C File Offset: 0x0000690C
 internal Worksheet(XlsDocument doc, Record boundSheet, List <Record> sheetRecords) : this(doc)
 {
     byte[] byteArray = boundSheet.Data.ByteArray;
     byte   b         = byteArray[4];
     if (b == 0)
     {
         this._visibility = WorksheetVisibilities.Default;
     }
     else if (b == 1)
     {
         this._visibility = WorksheetVisibilities.Hidden;
     }
     else
     {
         if (b != 2)
         {
             throw new ApplicationException(string.Format("Unknown Visibility {0}", b));
         }
         this._visibility = WorksheetVisibilities.StrongHidden;
     }
     byte b2 = byteArray[5];
     if (b2 == 0)
     {
         this._sheettype = WorksheetTypes.Default;
     }
     else if (b2 == 2)
     {
         this._sheettype = WorksheetTypes.Chart;
     }
     else
     {
         if (b2 != 6)
         {
             throw new ApplicationException(string.Format("Unknown Sheet Type {0}", b2));
         }
         this._sheettype = WorksheetTypes.VBModule;
     }
     List <Record> list  = new List <Record>();
     List <Record> list2 = new List <Record>();
     for (int i = 0; i < sheetRecords.Count; i++)
     {
         Record record = sheetRecords[i];
         if (record.IsCellRecord())
         {
             if (record.RID == RID.FORMULA)
             {
                 Record record2 = null;
                 if (i + i < sheetRecords.Count)
                 {
                     record2 = sheetRecords[i + 1];
                     if (record2.RID != RID.STRING)
                     {
                         record2 = null;
                     }
                 }
                 record = new FormulaRecord(record, record2);
             }
             list2.Add(record);
         }
         else if (record.RID == RID.ROW)
         {
             list.Add(record);
         }
     }
     foreach (Record record3 in list)
     {
         Bytes  data   = record3.Data;
         ushort rowNum = data.Get(0, 2).GetBits().ToUInt16();
         this.Rows.AddRow(rowNum);
         if (!data.Get(6, 2).GetBits().Values[15])
         {
             data.Get(6, 2).GetBits().Get(0, 14).ToUInt16();
         }
         bool flag = data.Get(10, 1).ByteArray[0] == 1;
     }
     foreach (Record record4 in list2)
     {
         this.AddCells(record4);
     }
     this._name = UnicodeBytes.Read(boundSheet.Data.Get(6, boundSheet.Data.Length - 6), 8);
 }
Ejemplo n.º 2
0
        internal Worksheet(XlsDocument doc, Record boundSheet, List <Record> sheetRecords) : this(doc)
        {
            byte[] byteArray = boundSheet.Data.ByteArray;

            byte visibility = byteArray[4];
            if (visibility == 0x00)
            {
                _visibility = WorksheetVisibilities.Visible;
            }
            else if (visibility == 0x01)
            {
                _visibility = WorksheetVisibilities.Hidden;
            }
            else if (visibility == 0x02)
            {
                _visibility = WorksheetVisibilities.StrongHidden;
            }
            else
            {
                throw new ApplicationException(string.Format("Unknown Visibility {0}", visibility));
            }

            byte type = byteArray[5];
            if (type == 0x00)
            {
                _sheettype = WorksheetTypes.Worksheet;
            }
            else if (type == 0x02)
            {
                _sheettype = WorksheetTypes.Chart;
            }
            else if (type == 0x06)
            {
                _sheettype = WorksheetTypes.VBModule;
            }
            else
            {
                throw new ApplicationException(string.Format("Unknown Sheet Type {0}", type));
            }

            List <Record> rowRecords  = new List <Record>();
            List <Record> cellRecords = new List <Record>();

            for (int i = 0; i < sheetRecords.Count; i++)
            {
                Record record = sheetRecords[i];
                if (record.IsCellRecord())
                {
                    if (record.RID == RID.FORMULA)
                    {
                        Record formulaStringRecord = null;
                        if ((i + i) < sheetRecords.Count)
                        {
                            formulaStringRecord = sheetRecords[i + 1];
                            if (formulaStringRecord.RID != RID.STRING)
                            {
                                formulaStringRecord = null;
                            }
                        }
                        record = new FormulaRecord(record, formulaStringRecord);
                    }

                    cellRecords.Add(record);
                }
                else if (record.RID == RID.ROW)
                {
                    rowRecords.Add(record);
                }
            }

            //Add the Rows first so they exist for adding the Cells
            foreach (Record rowRecord in rowRecords)
            {
                Bytes  rowBytes        = rowRecord.Data;
                ushort rowIndex        = rowBytes.Get(0, 2).GetBits().ToUInt16();
                Row    row             = Rows.AddRow(rowIndex);
                bool   isDefaultHeight = rowBytes.Get(6, 2).GetBits().Values[15];
                ushort height          = 0;
                if (!isDefaultHeight)
                {
                    height = rowBytes.Get(6, 2).GetBits().Get(0, 14).ToUInt16();
                    //TODO: Set height on Row when reading (after Row Height implemented)
                }
                bool defaultsWritten = (rowBytes.Get(10, 1).ByteArray[0] == 0x01);
                if (defaultsWritten)
                {
                    //TODO: Read ROW record defaults
                }
            }

            foreach (Record record in cellRecords)
            {
                AddCells(record);
            }

            _name = UnicodeBytes.Read(boundSheet.Data.Get(6, boundSheet.Data.Length - 6), 8);
        }