コード例 #1
0
        /**
         * An exception has occurred, so produce some appropriate dummy
         * cell contents.  This may be overridden by subclasses
         * if they require specific handling
         *
         * @return the bodged data
         */
        public virtual byte[] handleFormulaException()
        {
            byte[] expressiondata = null;
            byte[] celldata = base.getData();

            // Generate an appropriate dummy formula
            WritableWorkbookImpl w = getSheet().getWorkbook();
            parser = new FormulaParser(getContents(), w, w, w.getSettings());

            // Get the bytes for the dummy formula
            try
                {
                parser.parse();
                }
            catch (FormulaException e2)
                {
                //logger.warn(e2.Message);
                parser = new FormulaParser("\"ERROR\"", w, w, w.getSettings());
                try
                    {
                    parser.parse();
                    }
                catch (FormulaException e3)
                    {
                    Assert.verify(false);
                    }
                }
            byte[] formulaBytes = parser.getBytes();
            expressiondata = new byte[formulaBytes.Length + 16];
            IntegerHelper.getTwoBytes(formulaBytes.Length, expressiondata, 14);
            System.Array.Copy(formulaBytes, 0, expressiondata, 16,
                             formulaBytes.Length);

            // Set the recalculate on load bit
            expressiondata[8] |= 0x02;

            byte[] data = new byte[celldata.Length +
                                   expressiondata.Length];
            System.Array.Copy(celldata, 0, data, 0, celldata.Length);
            System.Array.Copy(expressiondata, 0, data,
                             celldata.Length, expressiondata.Length);
            return data;
        }
コード例 #2
0
        /**
         * Error formula specific exception handling.  Can't really create
         * a formula (as it will look for a cell of that name, so just
         * create a STRING record containing the contents
         *
         * @return the bodged data
         */
        public override byte[] handleFormulaException()
        {
            byte[] expressiondata = null;
            byte[] celldata = base.getCellData();

            // Generate an appropriate dummy formula
            WritableWorkbookImpl w = getSheet().getWorkbook();
            FormulaParser parser = new FormulaParser(getValue().ToString(), w, w, w.getSettings());

            // Get the bytes for the dummy formula
            try
                {
                parser.parse();
                }
            catch (FormulaException e2)
                {
                //logger.warn(e2.Message);
                }
            byte[] formulaBytes = parser.getBytes();
            expressiondata = new byte[formulaBytes.Length + 16];
            IntegerHelper.getTwoBytes(formulaBytes.Length, expressiondata, 14);
            System.Array.Copy(formulaBytes, 0, expressiondata, 16,
                             formulaBytes.Length);

            // Set the recalculate on load bit
            expressiondata[8] |= 0x02;

            byte[] data = new byte[celldata.Length +
                                   expressiondata.Length];
            System.Array.Copy(celldata, 0, data, 0, celldata.Length);
            System.Array.Copy(expressiondata, 0, data,
                             celldata.Length, expressiondata.Length);

            // Store the value in the formula
            DoubleHelper.getIEEEBytes(getValue(), data, 6);

            return data;
        }
コード例 #3
0
        /**
         * Gets the raw bytes for the formula.  This will include the
         * parsed tokens array.  Used when copying spreadsheets
         *
         * @return the raw record data
         * @exception FormulaException
         */
        public override byte[] getFormulaData()
        {
            if (!getSheet().getWorkbookBof().isBiff8())
                {
                throw new FormulaException(FormulaException.BIFF8_SUPPORTED);
                }

            // Get the tokens, taking into account the mapping from shared
            // formula specific values into normal values
            FormulaParser fp = new FormulaParser
              (getTokens(),this,
               getExternalSheet(),getNameTable(),
               getSheet().getWorkbook().getSettings());
            fp.parse();
            byte[] rpnTokens = fp.getBytes();

            byte[] data = new byte[rpnTokens.Length + 22];

            // Set the standard info for this cell
            IntegerHelper.getTwoBytes(getRow(),data,0);
            IntegerHelper.getTwoBytes(getColumn(),data,2);
            IntegerHelper.getTwoBytes(getXFIndex(),data,4);

            // Set the two most significant bytes of the value to be 0xff in
            // order to identify this as a string
            data[6] = 0;
            data[12] = (byte)0xff;
            data[13] = (byte)0xff;

            // Now copy in the parsed tokens
            System.Array.Copy(rpnTokens,0,data,22,rpnTokens.Length);
            IntegerHelper.getTwoBytes(rpnTokens.Length,data,20);

            // Lop off the standard information
            byte[] d = new byte[data.Length - 6];
            System.Array.Copy(data,6,d,0,data.Length - 6);

            return d;
        }
コード例 #4
0
        /**
         * Error formula specific exception handling.  Can't really create
         * a formula (as it will look for a cell of that name, so just
         * create a STRING record containing the contents
         *
         * @return the bodged data
         */
        public override byte[] handleFormulaException()
        {
            byte[] expressiondata = null;
            byte[] celldata = base.getCellData();

            int errorCode = getErrorCode();
            string formulaString = null;

            if (errorCode == FormulaErrorCode.DIV0.getCode())
                formulaString = "1/0";
            else if (errorCode == FormulaErrorCode.VALUE.getCode())
                formulaString = "\"\"/0";
            else if (errorCode == FormulaErrorCode.REF.getCode())
                formulaString = "\"#REF!\"";
            else
                formulaString = "\"ERROR\"";

            // Generate an appropriate dummy formula
            WritableWorkbookImpl w = getSheet().getWorkbook();
            FormulaParser parser = new FormulaParser(formulaString, w, w,
                                                     w.getSettings());

            // Get the bytes for the dummy formula
            try
                {
                parser.parse();
                }
            catch (FormulaException e2)
                {
                //logger.warn(e2.Message);
                }

            byte[] formulaBytes = parser.getBytes();
            expressiondata = new byte[formulaBytes.Length + 16];
            IntegerHelper.getTwoBytes(formulaBytes.Length, expressiondata, 14);
            System.Array.Copy(formulaBytes, 0, expressiondata, 16,formulaBytes.Length);

            // Set the recalculate on load bit
            expressiondata[8] |= 0x02;

            byte[] data = new byte[celldata.Length + expressiondata.Length];
            System.Array.Copy(celldata, 0, data, 0, celldata.Length);
            System.Array.Copy(expressiondata, 0, data,celldata.Length, expressiondata.Length);

            // Set the type bits to indicate an error
            data[6] = 2;
            data[12] = (byte)0xff;
            data[13] = (byte)0xff;

            // Set the error code
            data[8] = (byte)errorCode;

            return data;
        }