예제 #1
0
        /**
         * Used when writing out records.  This portion of the method handles the
         * biff code and the length of the record and appends on the data retrieved
         * from the subclasses
         *
         * @return the full record data to be written out to the compound file
         */
        public virtual byte[] getBytes()
        {
            byte[] data = getData();

            int dataLength = data.Length;

            // Don't the call the automatic continuation code for now
            //    Assert.verify(dataLength <= maxRecordLength - 4);
            // If the bytes length is greater than the max record length
            // then split out the data set into continue records
            if (data.Length > maxRecordLength - 4)
            {
                dataLength = maxRecordLength - 4;
                data       = handleContinueRecords(data);
            }

            byte[] bytes = new byte[data.Length + 4];

            System.Array.Copy(data, 0, bytes, 4, data.Length);

            IntegerHelper.getTwoBytes(getCode(), bytes, 0);
            IntegerHelper.getTwoBytes(dataLength, bytes, 2);

            return(bytes);
        }
예제 #2
0
        /**
         * Retrieves the data for output to binary file
         *
         * @return the data to be written
         */
        public override byte[] getData()
        {
            if (!modified)
            {
                return(data);
            }

            byte[] d = new byte[14 + ranges.Length * 8];

            // Copy in the original information
            System.Array.Copy(data, 0, d, 0, 4);

            // Create the new range
            IntegerHelper.getTwoBytes(enclosingRange.firstRow, d, 4);
            IntegerHelper.getTwoBytes(enclosingRange.lastRow, d, 6);
            IntegerHelper.getTwoBytes(enclosingRange.firstColumn, d, 8);
            IntegerHelper.getTwoBytes(enclosingRange.lastColumn, d, 10);

            IntegerHelper.getTwoBytes(numRanges, d, 12);

            int pos = 14;

            for (int i = 0; i < ranges.Length; i++)
            {
                IntegerHelper.getTwoBytes(ranges[i].firstRow, d, pos);
                IntegerHelper.getTwoBytes(ranges[i].lastRow, d, pos + 2);
                IntegerHelper.getTwoBytes(ranges[i].firstColumn, d, pos + 4);
                IntegerHelper.getTwoBytes(ranges[i].lastColumn, d, pos + 6);
                pos += 8;
            }

            return(d);
        }
예제 #3
0
        /**
         * Gets the data
         */
        public virtual byte[] getData()
        {
            byte[] data = new byte[18];

            int options = 0;

            if (promptBoxVisible)
            {
                options |= PROMPT_BOX_VISIBLE_MASK;
            }

            if (promptBoxAtCell)
            {
                options |= PROMPT_BOX_AT_CELL_MASK;
            }

            if (validityDataCached)
            {
                options |= VALIDITY_DATA_CACHED_MASK;
            }

            IntegerHelper.getTwoBytes(options, data, 0);
            IntegerHelper.getFourBytes(objectId, data, 10);
            IntegerHelper.getFourBytes(numDVRecords, data, 14);

            return(data);
        }
예제 #4
0
        /**
         * Accessor for the binary data - used when copying
         *
         * @return the binary data
         */
        public override byte[] getData()
        {
            // Palette was read in, but has not been changed
            if (read && !dirty)
            {
                return(getRecord().getData());
            }

            byte[] data = new byte[numColours * 4 + 2];
            int    pos  = 0;

            // Set the number of records
            IntegerHelper.getTwoBytes(numColours, data, pos);

            // Set the rgb content
            for (int i = 0; i < numColours; i++)
            {
                pos           = i * 4 + 2;
                data[pos]     = (byte)rgbColours[i].getRed();
                data[pos + 1] = (byte)rgbColours[i].getGreen();
                data[pos + 2] = (byte)rgbColours[i].getBlue();
            }

            return(data);
        }
예제 #5
0
        /**
         * Used to get the data when writing out the format record
         *
         * @return the raw data
         */
        public override byte[] getData()
        {
            data = new byte[formatString.Length * 2 + 3 + 2];

            IntegerHelper.getTwoBytes(indexCode, data, 0);
            IntegerHelper.getTwoBytes(formatString.Length, data, 2);
            data[4] = (byte)0x1;             // unicode indicator
            StringHelper.getUnicodeBytes(formatString, data, 5);

            return(data);
        }
예제 #6
0
        /**
         * Gets the byte data for writing out
         *
         * @return the raw data
         */
        public override byte[] getData()
        {
            byte[] data = new byte[16 + name.Length * 2];

            // Excel expects font heights in 1/20ths of a point
            IntegerHelper.getTwoBytes(pointHeight * EXCEL_UNITS_PER_POINT, data, 0);

            // Set the font attributes to be zero for now
            if (italic)
            {
                data[2] |= 0x2;
            }

            if (struckout)
            {
                data[2] |= 0x08;
            }

            // Set the index to the colour palette
            IntegerHelper.getTwoBytes(colourIndex, data, 4);

            // Bold style
            IntegerHelper.getTwoBytes(boldWeight, data, 6);

            // Script style
            IntegerHelper.getTwoBytes(scriptStyle, data, 8);

            // Underline style
            data[10] = (byte)underlineStyle;

            // Set the font family to be 0
            data[11] = fontFamily;

            // Set the character set to be zero
            data[12] = characterSet;

            // Set the reserved bit to be zero
            data[13] = 0;

            // Set the length of the font name
            data[14] = (byte)name.Length;

            data[15] = (byte)1;

            // Copy in the string
            StringHelper.getUnicodeBytes(name, data, 16);

            return(data);
        }
예제 #7
0
            /**
             * Constructs an empty property set.  Used when writing the file
             *
             * @param name the property storage name
             */
            public PropertyStorage(string name)
            {
                data = new byte[PROPERTY_STORAGE_BLOCK_SIZE];

                Assert.verify(name.Length < 32);

                IntegerHelper.getTwoBytes((name.Length + 1) * 2,
                                          data,
                                          SIZE_OF_NAME_POS);
                // add one to the name length to allow for the null character at
                // the end
                for (int i = 0; i < name.Length; i++)
                {
                    data[i * 2] = (byte)name[i];
                }
            }
예제 #8
0
        /**
         * Gets the binary data for output to file
         *
         * @return the binary data
         */
        public override byte[] getData()
        {
            byte[] data = new byte[2];

            if (fitToPages)
            {
                wsoptions |= FIT_TO_PAGES;
            }

            if (rowOutlines)
            {
                wsoptions |= SHOW_ROW_OUTLINE_SYMBOLS;
            }

            if (columnOutlines)
            {
                wsoptions |= SHOW_COLUMN_OUTLINE_SYMBOLS;
            }

            IntegerHelper.getTwoBytes(wsoptions, data, 0);

            return(data);
        }
예제 #9
0
        /**
         * The number of bytes for this record exceeds the maximum record
         * length, so a continue is required
         * @param data the raw data
         * @return  the continued data
         */
        private byte[] handleContinueRecords(byte[] data)
        {
            // Deduce the number of continue records
            int continuedData      = data.Length - (maxRecordLength - 4);
            int numContinueRecords = continuedData / (maxRecordLength - 4) + 1;

            // Create the new byte array, allowing for the continue records
            // code and length
            byte[] newdata = new byte[data.Length + numContinueRecords * 4];

            // Copy the bona fide record data into the beginning of the super
            // record
            System.Array.Copy(data, 0, newdata, 0, maxRecordLength - 4);
            int oldarraypos = maxRecordLength - 4;
            int newarraypos = maxRecordLength - 4;

            // Now handle all the continue records
            for (int i = 0; i < numContinueRecords; i++)
            {
                // The number of bytes to add into the new array
                int length = System.Math.Min(data.Length - oldarraypos, maxRecordLength - 4);

                // Add in the continue record code
                IntegerHelper.getTwoBytes(Type.CONTINUE.value, newdata, newarraypos);
                IntegerHelper.getTwoBytes(length, newdata, newarraypos + 2);

                // Copy in as much of the new data as possible
                System.Array.Copy(data, oldarraypos, newdata, newarraypos + 4, length);

                // Update the position counters
                oldarraypos += length;
                newarraypos += length + 4;
            }

            return(newdata);
        }
예제 #10
0
        /**
         * Gets the data
         */
        public virtual byte[] getData()
        {
            // Compute the length of the data
            byte[] f1Bytes = formula1 != null?formula1.getBytes() : new byte[0];

            byte[] f2Bytes = formula2 != null?formula2.getBytes() : new byte[0];

            int dataLength = 4 +                          // the options
                             promptTitle.Length * 2 + 3 + // the prompt title
                             errorTitle.Length * 2 + 3 +  // the error title
                             promptText.Length * 2 + 3 +  // the prompt text
                             errorText.Length * 2 + 3 +   // the error text
                             f1Bytes.Length + 2 +         // first formula
                             f2Bytes.Length + 2 +         // second formula
                             +4 +                         // unused bytes
                             10;                          // cell range

            byte[] data = new byte[dataLength];

            // The position
            int pos = 0;

            // The options
            int options = 0;

            options |= type.getValue();
            options |= errorStyle.getValue() << 4;
            options |= condition.getValue() << 20;

            if (stringListGiven)
            {
                options |= STRING_LIST_GIVEN_MASK;
            }

            if (emptyCellsAllowed)
            {
                options |= EMPTY_CELLS_ALLOWED_MASK;
            }

            if (suppressArrow)
            {
                options |= SUPPRESS_ARROW_MASK;
            }

            if (showPrompt)
            {
                options |= SHOW_PROMPT_MASK;
            }

            if (showError)
            {
                options |= SHOW_ERROR_MASK;
            }

            // The text
            IntegerHelper.getFourBytes(options, data, pos);
            pos += 4;

            IntegerHelper.getTwoBytes(promptTitle.Length, data, pos);
            pos += 2;

            data[pos] = (byte)0x1;             // unicode indicator
            pos++;

            StringHelper.getUnicodeBytes(promptTitle, data, pos);
            pos += promptTitle.Length * 2;

            IntegerHelper.getTwoBytes(errorTitle.Length, data, pos);
            pos += 2;

            data[pos] = (byte)0x1;             // unicode indicator
            pos++;

            StringHelper.getUnicodeBytes(errorTitle, data, pos);
            pos += errorTitle.Length * 2;

            IntegerHelper.getTwoBytes(promptText.Length, data, pos);
            pos += 2;

            data[pos] = (byte)0x1;             // unicode indicator
            pos++;

            StringHelper.getUnicodeBytes(promptText, data, pos);
            pos += promptText.Length * 2;

            IntegerHelper.getTwoBytes(errorText.Length, data, pos);
            pos += 2;

            data[pos] = (byte)0x1;             // unicode indicator
            pos++;

            StringHelper.getUnicodeBytes(errorText, data, pos);
            pos += errorText.Length * 2;

            // Formula 1
            IntegerHelper.getTwoBytes(f1Bytes.Length, data, pos);
            pos += 4;

            System.Array.Copy(f1Bytes, 0, data, pos, f1Bytes.Length);
            pos += f1Bytes.Length;

            // Formula 2
            IntegerHelper.getTwoBytes(f2Bytes.Length, data, pos);
            pos += 4;

            System.Array.Copy(f2Bytes, 0, data, pos, f2Bytes.Length);
            pos += f2Bytes.Length;

            // The cell ranges
            IntegerHelper.getTwoBytes(1, data, pos);
            pos += 2;

            IntegerHelper.getTwoBytes(row1, data, pos);
            pos += 2;

            IntegerHelper.getTwoBytes(row2, data, pos);
            pos += 2;

            IntegerHelper.getTwoBytes(column1, data, pos);
            pos += 2;

            IntegerHelper.getTwoBytes(column2, data, pos);
            pos += 2;

            return(data);
        }