コード例 #1
0
        private ValueEval Evaluate(String formula, CellReference target, CellRangeAddressBase region, FormulaType formulaType)
        {
            String sheetName = target == null ? null : target.SheetName;

            if (sheetName == null)
            {
                throw new ArgumentException("Sheet name is required");
            }

            int sheetIndex = Workbook.GetSheetIndex(sheetName);

            Ptg[] ptgs = FormulaParser.Parse(formula, (IFormulaParsingWorkbook)Workbook, formulaType, sheetIndex, target.Row);

            AdjustRegionRelativeReference(ptgs, target, region);

            OperationEvaluationContext ec = new OperationEvaluationContext(this, Workbook, sheetIndex, target.Row, target.Col, new EvaluationTracker(_cache), formulaType.GetAttributes().Get <SingleValueAttribute>().IsSingleValue);

            return(EvaluateNameFormula(ptgs, ec));
        }
コード例 #2
0
        protected bool AdjustRegionRelativeReference(Ptg[] ptgs, CellReference target, CellRangeAddressBase region)
        {
            if (!region.IsInRange(target))
            {
                throw new ArgumentException(target + " is not within " + region);
            }

            //return adjustRegionRelativeReference(ptgs, target.getRow() - region.getFirstRow(), target.getCol() - region.getFirstColumn());

            int deltaRow    = target.Row;
            int deltaColumn = target.Col;

            bool shifted = false;

            foreach (Ptg ptg in ptgs)
            {
                // base class for cell reference "things"
                if (ptg is RefPtgBase)
                {
                    RefPtgBase reference = (RefPtgBase)ptg;
                    // re-calculate cell references
                    SpreadsheetVersion version = _workbook.GetSpreadsheetVersion();
                    if (reference.IsRowRelative)
                    {
                        int rowIndex = reference.Row + deltaRow;
                        if (rowIndex > version.MaxRows)
                        {
                            throw new IndexOutOfRangeException(version.Name + " files can only have " + version.MaxRows + " rows, but row " + rowIndex + " was requested.");
                        }
                        reference.Row = rowIndex;
                        shifted       = true;
                    }
                    if (reference.IsColRelative)
                    {
                        int colIndex = reference.Column + deltaColumn;
                        if (colIndex > version.MaxColumns)
                        {
                            throw new IndexOutOfRangeException(version.Name + " files can only have " + version.MaxColumns + " columns, but column " + colIndex + " was requested.");
                        }
                        reference.Column = colIndex;
                        shifted          = true;
                    }
                }
            }
            return(shifted);
        }
コード例 #3
0
 public ValueEval Evaluate(String formula, CellReference target, CellRangeAddressBase region)
 {
     return(Evaluate(formula, target, region, FormulaType.Cell));
 }
コード例 #4
0
ファイル: HSSFChart.cs プロジェクト: missxiaohuang/Weekly
            public void SetCategoryLabelsCellRange(CellRangeAddressBase range)
            {
                int count = SetVerticalCellRange(dataCategoryLabels, range);

                series.NumCategories = (short)count;
            }
コード例 #5
0
ファイル: HSSFChart.cs プロジェクト: missxiaohuang/Weekly
            public void SetValuesCellRange(CellRangeAddressBase range)
            {
                int count = SetVerticalCellRange(dataValues, range);

                series.NumValues = (short)count;
            }
コード例 #6
0
ファイル: HSSFChart.cs プロジェクト: missxiaohuang/Weekly
            private int SetVerticalCellRange(LinkedDataRecord linkedDataRecord,
                                                 CellRangeAddressBase range)
            {
                if (linkedDataRecord == null)
                {
                    throw new ArgumentNullException("linkedDataRecord should not be null"); ;
                }

                List<Ptg> ptgList = new List<Ptg>();

                int rowCount = (range.LastRow - range.FirstRow) + 1;
                int colCount = (range.LastColumn - range.FirstColumn) + 1;

                foreach (Ptg ptg in linkedDataRecord.FormulaOfLink)
                {
                    if (ptg is AreaPtgBase)
                    {
                        AreaPtgBase areaPtg = (AreaPtgBase)ptg;

                        areaPtg.FirstRow = range.FirstRow;
                        areaPtg.LastRow = range.LastRow;

                        areaPtg.FirstColumn = range.FirstColumn;
                        areaPtg.LastColumn = range.LastColumn;
                        ptgList.Add(areaPtg);
                    }
                }

                linkedDataRecord.FormulaOfLink = (ptgList.ToArray());

                return rowCount * colCount;
            }