예제 #1
0
파일: XSSFCell.cs 프로젝트: founshi/npoi
        private void SetFormula(String formula, FormulaType formulaType)
        {
            IWorkbook wb = _row.Sheet.Workbook;

            if (formula == null)
            {
                ((XSSFWorkbook)wb).OnDeleteFormula(this);
                if (_cell.IsSetF())
                {
                    _cell.unsetF();
                }
                return;
            }

            IFormulaParsingWorkbook fpb = XSSFEvaluationWorkbook.Create(wb);

            //validate through the FormulaParser
            FormulaParser.Parse(formula, fpb, formulaType, wb.GetSheetIndex(this.Sheet), -1);

            CT_CellFormula f = new CT_CellFormula();

            f.Value = formula;
            _cell.f = (f);
            if (_cell.IsSetV())
            {
                _cell.unsetV();
            }
        }
예제 #2
0
 private void updateRowFormulas(XSSFRow row, FormulaShifter Shifter)
 {
     foreach (XSSFCell xssfCell in row)
     {
         CT_Cell ctCell = xssfCell.GetCTCell();
         if (ctCell.IsSetF())
         {
             CT_CellFormula f        = ctCell.f;
             string         formula1 = f.Value;
             if (formula1.Length > 0)
             {
                 string str = XSSFRowShifter.ShiftFormula(row, formula1, Shifter);
                 if (str != null)
                 {
                     f.Value = str;
                 }
             }
             if (f.isSetRef())
             {
                 string formula2 = f.@ref;
                 string str      = XSSFRowShifter.ShiftFormula(row, formula2, Shifter);
                 if (str != null)
                 {
                     f.@ref = str;
                 }
             }
         }
     }
 }
예제 #3
0
        private void updateRowFormulas(XSSFRow row, FormulaShifter Shifter)
        {
            foreach (ICell c in row)
            {
                XSSFCell cell = (XSSFCell)c;

                CT_Cell ctCell = cell.GetCTCell();
                if (ctCell.IsSetF())
                {
                    CT_CellFormula f       = ctCell.f;
                    String         formula = f.Value;
                    if (formula.Length > 0)
                    {
                        String ShiftedFormula = ShiftFormula(row, formula, Shifter);
                        if (ShiftedFormula != null)
                        {
                            f.Value = (ShiftedFormula);
                        }
                    }

                    if (f.isSetRef())
                    { //Range of cells which the formula applies to.
                        String ref1       = f.@ref;
                        String ShiftedRef = ShiftFormula(row, ref1, Shifter);
                        if (ShiftedRef != null)
                        {
                            f.@ref = ShiftedRef;
                        }
                    }
                }
            }
        }
예제 #4
0
        public void RemoveFormula()
        {
            if (CellType == CellType.Blank)
            {
                return;
            }

            if (IsPartOfArrayFormulaGroup)
            {
                TryToDeleteArrayFormula(null);
                return;
            }
            ((XSSFWorkbook)_row.Sheet.Workbook).OnDeleteFormula(this);
            if (_cell.IsSetF())
            {
                ((XSSFSheet)_row.Sheet).OnDeleteFormula(this, null);
                _cell.unsetF();
            }
        }
예제 #5
0
        /// <summary>
        /// Update the formulas in specified row using the formula shifting policy specified by shifter
        /// </summary>
        /// <param name="row">the row to update the formulas on</param>
        /// <param name="Shifter">the formula shifting policy</param>
        public override void UpdateRowFormulas(IRow row, FormulaShifter Shifter)
        {
            XSSFSheet sheet = (XSSFSheet)row.Sheet;

            foreach (ICell c in row)
            {
                XSSFCell cell = (XSSFCell)c;

                CT_Cell ctCell = cell.GetCTCell();
                if (ctCell.IsSetF())
                {
                    CT_CellFormula f       = ctCell.f;
                    String         formula = f.Value;
                    if (formula.Length > 0)
                    {
                        String ShiftedFormula = ShiftFormula(row, formula, Shifter);
                        if (ShiftedFormula != null)
                        {
                            f.Value = (ShiftedFormula);
                            if (f.t == ST_CellFormulaType.shared)
                            {
                                int            si = (int)f.si;
                                CT_CellFormula sf = sheet.GetSharedFormula(si);
                                sf.Value = (ShiftedFormula);
                            }
                        }
                    }

                    if (f.isSetRef())
                    { //Range of cells which the formula applies to.
                        String ref1       = f.@ref;
                        String ShiftedRef = ShiftFormula(row, ref1, Shifter);
                        if (ShiftedRef != null)
                        {
                            f.@ref = ShiftedRef;
                        }
                    }
                }
            }
        }
예제 #6
0
        private static void ConfirmArrayFormulaCell(ICell c, String cellRef, String formulaText, String arrayRangeRef)
        {
            if (c == null)
            {
                throw new AssertionException("Cell should not be null.");
            }
            CT_Cell ctCell = ((XSSFCell)c).GetCTCell();

            Assert.AreEqual(cellRef, ctCell.r);
            if (formulaText == null)
            {
                Assert.IsFalse(ctCell.IsSetF());
                Assert.IsNull(ctCell.f);
            }
            else
            {
                CT_CellFormula f = ctCell.f;
                Assert.AreEqual(arrayRangeRef, f.@ref);
                Assert.AreEqual(formulaText, f.Value);
                Assert.AreEqual(ST_CellFormulaType.array, f.t);
            }
        }