Exemplo n.º 1
0
        /**
         * Gets the formula present in the validation
         *
         * @return the validation formula as a string
         * @exception FormulaException
         */
        public string getValidationFormula()
        {
            if (type == LIST)
            {
                return(formula1.getFormula());
            }

            string s1 = formula1.getFormula();
            string s2 = formula2 != null?formula2.getFormula() : null;

            return(condition.getConditionString(s1, s2) + "; x " + type.getDescription());
        }
Exemplo n.º 2
0
 /**
  * This formula was copied from a formula already present in the writable
  * workbook.  Requires special handling to sort out the cell references
  *
  * @param ws the workbook settings
  * @param es the external sheet
  * @param nt the name table
  */
 private void initializeCopiedFormula(WorkbookSettings ws,
                                      ExternalSheet es, WorkbookMethods nt)
 {
     try
     {
         parser = new FormulaParser(formulaBytes, this, es, nt, ws);
         parser.parse();
         parser.adjustRelativeCellReferences
             (getColumn() - copiedFrom.getColumn(),
             getRow() - copiedFrom.getRow());
         formulaString = parser.getFormula();
         formulaBytes  = parser.getBytes();
     }
     catch (FormulaException e)
     {
         try
         {
             // try again, with an error formula
             formulaToParse = "ERROR(1)";
             parser         = new FormulaParser(formulaToParse, es, nt, ws);
             parser.parse();
             formulaString = parser.getFormula();
             formulaBytes  = parser.getBytes();
         }
         catch (FormulaException e2)
         {
             // fail silently
             //logger.error(string.Empty, e2);
         }
     }
 }
Exemplo n.º 3
0
        /**
         * Gets the formula as an excel string
         *
         * @return the formula as an excel string
         * @exception FormulaException
         */
        public string getFormula()
        {
            if (formulaString == null)
            {
                FormulaParser fp = new FormulaParser
                                       (tokens, this, externalSheet, nameTable,
                                       getSheet().getWorkbook().getSettings());
                fp.parse();
                formulaString = fp.getFormula();
            }

            return(formulaString);
        }
Exemplo n.º 4
0
        /**
         * Gets the formula as an excel string
         *
         * @return the formula as an excel string
         * @exception FormulaException
         */
        public string getFormula()
        {
            if (formulaString == null)
            {
                byte[] tokens = new byte[data.Length - 22];
                System.Array.Copy(data, 22, tokens, 0, tokens.Length);
                FormulaParser fp = new FormulaParser
                                       (tokens, this, externalSheet, nameTable,
                                       getSheet().getWorkbook().getSettings());
                fp.parse();
                formulaString = fp.getFormula();
            }

            return(formulaString);
        }
Exemplo n.º 5
0
        /**
         * Gets the formula as an excel string
         *
         * @return the formula as an excel string
         * @exception FormulaException
         */
        public string getFormula()
        {
            // Note that the standard information was lopped off by the NumberFormula
            // record when creating this formula
            if (formulaString == null)
            {
                byte[] tokens = new byte[data.Length - 16];
                System.Array.Copy(data, 16, tokens, 0, tokens.Length);
                FormulaParser fp = new FormulaParser
                                       (tokens, this, externalSheet, nameTable,
                                       getSheet().getWorkbook().getSettings());
                fp.parse();
                formulaString = fp.getFormula();
            }

            return(formulaString);
        }
Exemplo n.º 6
0
        /**
         * Initializes the string and the formula bytes.  In order to get
         * access to the workbook settings, the object is not initialized until
         * it is added to the sheet
         *
         * @param ws the workbook settings
         * @param es the external sheet
         * @param nt the name table
         */
        private void initialize(WorkbookSettings ws, ExternalSheet es,
                                WorkbookMethods nt)
        {
            if (copiedFrom != null)
            {
                initializeCopiedFormula(ws, es, nt);
                return;
            }

            parser = new FormulaParser(formulaToParse, es, nt, ws);

            try
            {
                parser.parse();
                formulaString = parser.getFormula();
                formulaBytes  = parser.getBytes();
            }
            catch (FormulaException e)
            {
                //logger.warn(e.Message + " when parsing formula " + formulaToParse + " in cell " +
                //   getSheet().getName() + "!" +
                //     CellReferenceHelper.getCellReference(getColumn(), getRow()));

                try
                {
                    // try again, with an error formula
                    formulaToParse = "ERROR(1)";
                    parser         = new FormulaParser(formulaToParse, es, nt, ws);
                    parser.parse();
                    formulaString = parser.getFormula();
                    formulaBytes  = parser.getBytes();
                }
                catch (FormulaException e2)
                {
                    // fail silently
                    //logger.error(string.Empty, e2);
                }
            }
        }