Ejemplo n.º 1
0
        /**
         * Constructs this string formula
         *
         * @param t the record
         * @param excelFile the excel file
         * @param fr the formatting record
         * @param es the external sheet
         * @param nt the workbook
         * @param si the sheet
         * @param ws the workbook settings
         */
        public SharedStringFormulaRecord(Record t,
                                         File excelFile,
                                         FormattingRecords fr,
                                         ExternalSheet es,
                                         WorkbookMethods nt,
                                         SheetImpl si,
                                         WorkbookSettings ws)
            : base(t, fr, es, nt, si, excelFile.getPos())
        {
            int pos = excelFile.getPos();

            // Save the position in the excel file
            int filepos = excelFile.getPos();

            // Look for the string record in one of the records after the
            // formula.  Put a cap on it to prevent ednas
            Record nextRecord = excelFile.next();
            int    count      = 0;

            while (nextRecord.getType() != Type.STRING && count < 4)
            {
                nextRecord = excelFile.next();
                count++;
            }
            Assert.verify(count < 4, " @ " + pos);

            byte[] stringData = nextRecord.getData();

            // Read in any continuation records
            nextRecord = excelFile.peek();
            while (nextRecord.getType() == Type.CONTINUE)
            {
                nextRecord = excelFile.next();                 // move the pointer within the data
                byte[] d = new byte[stringData.Length + nextRecord.getLength() - 1];
                System.Array.Copy(stringData, 0, d, 0, stringData.Length);
                System.Array.Copy(nextRecord.getData(), 1, d,
                                  stringData.Length, nextRecord.getLength() - 1);
                stringData = d;
                nextRecord = excelFile.peek();
            }

            int chars = IntegerHelper.getInt(stringData[0], stringData[1]);

            bool unicode  = false;
            int  startpos = 3;

            if (stringData.Length == chars + 2)
            {
                // string might only consist of a one byte length indicator, instead
                // of the more normal 2
                startpos = 2;
                unicode  = false;
            }
            else if (stringData[2] == 0x1)
            {
                // unicode string, two byte length indicator
                startpos = 3;
                unicode  = true;
            }
            else
            {
                // ascii string, two byte length indicator
                startpos = 3;
                unicode  = false;
            }

            if (!unicode)
            {
                value = StringHelper.getString(stringData, chars, startpos, ws);
            }
            else
            {
                value = StringHelper.getUnicodeString(stringData, chars, startpos);
            }

            // Restore the position in the excel file, to enable the SHRFMLA
            // record to be picked up
            excelFile.setPos(filepos);
        }