Beispiel #1
0
        private Bytes INDEX(int baseLength)
        {
            Bytes index = new Bytes();

            //Not used
            index.Append(new byte[] { 0x00, 0x00, 0x00, 0x00 });

            //Index to first used row (0-based)
            index.Append(BitConverter.GetBytes(_rows.MinRow - 1));

            //Index to first row of unused tail of sheet(last row + 1, 0-based)
            index.Append(BitConverter.GetBytes(_rows.MaxRow));

            //Absolute stream position of the DEFCOLWIDTH record
            //TODO: Implement Worksheet.INDEX Absolute stream position of the DEFCOLWIDTH record (not necessary)
            index.Append(BitConverter.GetBytes((uint)0));

            for (int i = 1; i < _dbCellOffsets.Length; i++)
                index.Append(BitConverter.GetBytes((uint)(baseLength + _dbCellOffsets[i])));

            return Record.GetBytes(RID.INDEX, index);
        }
Beispiel #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 Exception(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 Exception(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);
        }