Exemplo n.º 1
0
Arquivo: Ptg.cs Projeto: zhgl7688/-
        /**
         * Writes the ptgs to the data buffer, starting at the specified offset.
         *
         * <br/>
         * The 2 byte encode Length field is <b>not</b> written by this method.
         * @return number of bytes written
         */
        public static int SerializePtgs(Ptg[] ptgs, byte[] array, int offset)
        {
            int size = ptgs.Length;

            LittleEndianByteArrayOutputStream out1 = new LittleEndianByteArrayOutputStream(array, offset);

            ArrayList arrayPtgs = null;

            for (int k = 0; k < size; k++)
            {
                Ptg ptg = ptgs[k];

                ptg.Write(out1);
                if (ptg is ArrayPtg)
                {
                    if (arrayPtgs == null)
                    {
                        arrayPtgs = new ArrayList(5);
                    }
                    arrayPtgs.Add(ptg);
                }
            }
            if (arrayPtgs != null)
            {
                for (int i = 0; i < arrayPtgs.Count; i++)
                {
                    ArrayPtg p = (ArrayPtg)arrayPtgs[i];
                    p.WriteTokenValueBytes(out1);
                }
            }
            return(out1.WriteIndex - offset);;
        }
Exemplo n.º 2
0
            /**
             * Read in the actual token (array) values. This occurs
             * AFTER the last Ptg in the expression.
             * See page 304-305 of Excel97-2007BinaryFileFormat(xls)Specification.pdf
             */
            public ArrayPtg FinishReading(ILittleEndianInput in1)
            {
                int   nColumns = in1.ReadUByte();
                short nRows    = in1.ReadShort();

                //The token_1_columns and token_2_rows do not follow the documentation.
                //The number of physical rows and columns is actually +1 of these values.
                //Which is not explicitly documented.
                nColumns++;
                nRows++;

                int totalCount = nRows * nColumns;

                Object[] arrayValues = ConstantValueParser.Parse(in1, totalCount);

                ArrayPtg result = new ArrayPtg(_reserved0, _reserved1, _reserved2, nColumns, nRows, arrayValues);

                result.PtgClass = this.PtgClass;
                return(result);
            }