Exemplo n.º 1
0
        private Bytes RK(bool trueFalse)
        {
            Bytes rk = new Bytes();

            //Index to row
            rk.Append(BitConverter.GetBytes((ushort)(Row - 1)));

            //Index to column
            rk.Append(BitConverter.GetBytes((ushort)(Column - 1)));

            //Index to XF record
            rk.Append(BitConverter.GetBytes((ushort)_xfIdx));

            //RK Value
            if (Type == CellTypes.Integer)
            {
                rk.Append(RKIntegerValue(Value, trueFalse));
            }
            else if (Type == CellTypes.Float)
            {
                rk.Append(RKDecimalValue(Value, trueFalse));
            }

            return(Record.GetBytes(RID.RK, rk));
        }
Exemplo n.º 2
0
        private Bytes MERGEDCELLS()
        {
            Bytes mergedcells = new Bytes();

            int  areaIndex       = 0;
            int  mergeAreaCount  = _mergeAreas.Count;
            long areasPerRecord  = 1027;
            int  recordsRequired = (int)Math.Ceiling(_mergeAreas.Count / (double)areasPerRecord);

            for (int recordIndex = 0; recordIndex < recordsRequired; recordIndex++)
            {
                ushort blockAreaIndex = 0;
                Bytes  rangeAddresses = new Bytes();
                while (areaIndex < mergeAreaCount && blockAreaIndex < areasPerRecord)
                {
                    rangeAddresses.Append(CellRangeAddress(_mergeAreas[areaIndex]));

                    blockAreaIndex++;
                    areaIndex++;
                }
                rangeAddresses.Prepend(BitConverter.GetBytes(blockAreaIndex));
                mergedcells.Append(Record.GetBytes(RID.MERGEDCELLS, rangeAddresses));
            }

            return(mergedcells);
        }
Exemplo n.º 3
0
        //NOTE: Don't want to pass recordBytes by ref or when we set it to a new Bytes
        //instance, it will wipe out what was appended to bytes
        private Bytes Continue(Bytes sst, Bytes bytes, out int remainingRecordBytes, ref bool isFirstContinue)
        {
            sst.Append(Record.GetBytes(isFirstContinue ? RID.SST : RID.CONTINUE, bytes));

            remainingRecordBytes = BIFF8.MaxDataBytesPerRecord;
            isFirstContinue      = false;
            return(new Bytes());
        }
Exemplo n.º 4
0
        private Bytes GetFormatRecord(ushort id, string format)
        {
            Bytes bytes = new Bytes();

            bytes.Append(BitConverter.GetBytes(id));
            bytes.Append(XlsDocument.GetUnicodeString(format, 16));

            return(Record.GetBytes(RID.FORMAT, bytes));
        }
Exemplo n.º 5
0
        private Bytes LABELSST()
        {
            Bytes labelsst = new Bytes();

            labelsst.Append(LABELBase());

            //Index of string value in Shared String Table
            labelsst.Append(BitConverter.GetBytes((uint)_value));

            return(Record.GetBytes(RID.LABELSST, labelsst));
        }
Exemplo n.º 6
0
        private Bytes LABEL()
        {
            Bytes label = new Bytes();

            label.Append(LABELBase());

            //Unicode string, 16-bit string length
            label.Append(XlsDocument.GetUnicodeString((string)Value ?? string.Empty, 16));

            return(Record.GetBytes(RID.LABEL, label));
        }
Exemplo n.º 7
0
        private Bytes BLANK()
        {
            Bytes blank = new Bytes();

            //Index to row
            blank.Append(BitConverter.GetBytes((ushort)(Row - 1)));

            //Index to column
            blank.Append(BitConverter.GetBytes((ushort)(Column - 1)));

            //Index to XF record
            blank.Append(BitConverter.GetBytes((ushort)_xfIdx));

            return(Record.GetBytes(RID.BLANK, blank));
        }
Exemplo n.º 8
0
        private Bytes WINDOW2()
        {
            Bytes window2 = new Bytes();

            //TODO: Implement options - excelfileformat.pdf pp.210-211
            if (_doc.Workbook.Worksheets.GetIndex(Name) == 0) //NOTE: This was == 1, but the base of the worksheets collection must have changed
            {
                window2.Append(new byte[] { 0xB6, 0x06 });
            }
            else
            {
                window2.Append(new byte[] { 0xB6, 0x04 });
            }
            window2.Append(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 });

            return(Record.GetBytes(RID.WINDOW2, window2));
        }
Exemplo n.º 9
0
        private static Bytes ROW(Row row)
        {
            Bytes bytes = new Bytes();

            //Index of this row
            bytes.Append(BitConverter.GetBytes((ushort)(row.RowIndex - 1)));

            //Index to column of the first cell which is described by a cell record
            bytes.Append(BitConverter.GetBytes((ushort)(row.MinCellCol - 1)));

            //Index to column of the last cell which is described by a cell record, + 1
            bytes.Append(BitConverter.GetBytes(row.MaxCellCol));

            //Height of row in twips, custom row height indicator
            //TODO: Implement Row height and custom height indicators (excelfileformat.pdf p.190)
            //bytes.Append(new byte[] {0x08, 0x01});
            if (row.RowHeight > 32767)
            {
                throw new ApplicationException("Row height can not greater than 32767.");
            }
            else
            {
                bytes.Append(BitConverter.GetBytes(row.RowHeight));
            }

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

            //Not used anymore in BIFF8 (DBCELL instead)
            bytes.Append(new byte[] { 0x00, 0x00 });

            //Option flags and default row formatting
            //TODO: Implement Row option flags and default row formatting (excelfileformat.pdf p.190)
            //bytes.Append(new byte[] {0x00, 0x01, 0x0F, 0x00});
            //Bit Value
            //7   1
            //6   1      Row height and default font height do not match
            //5   0
            //4   0
            //2-0 0
            bytes.Append(new byte[] { 0xC0, 0x01, 0x0F, 0x00 });


            return(Record.GetBytes(RID.ROW, bytes));
        }
Exemplo n.º 10
0
        private static Bytes DBCELL(ushort[] cOff)
        {
            Bytes dbcell = new Bytes();

            for (int i = 0; i < cOff.Length; i++)
            {
                if (i == 0)
                {
                    dbcell.Append(BitConverter.GetBytes((uint)cOff[i]));
                }
                else
                {
                    dbcell.Append(BitConverter.GetBytes(cOff[i]));
                }
            }

            return(Record.GetBytes(RID.DBCELL, dbcell));
        }
Exemplo n.º 11
0
        private Bytes NUMBER()
        {
            double value = Convert.ToDouble(Value);

            Bytes number = new Bytes();

            //Index to row
            number.Append(BitConverter.GetBytes((ushort)(Row - 1)));

            //Index to column
            number.Append(BitConverter.GetBytes((ushort)(Column - 1)));

            //Index to XF record
            number.Append(BitConverter.GetBytes((ushort)_xfIdx));

            //NUMBER Value
            number.Append(NUMBERVal(value));

            return(Record.GetBytes(RID.NUMBER, number));
        }
Exemplo n.º 12
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));
        }