当前位置: 首页>>代码示例>>C#>>正文


C# Util.CellReference类代码示例

本文整理汇总了C#中NPOI.SS.Util.CellReference的典型用法代码示例。如果您正苦于以下问题:C# CellReference类的具体用法?C# CellReference怎么用?C# CellReference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CellReference类属于NPOI.SS.Util命名空间,在下文中一共展示了CellReference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestEvaluateColumnGreaterThan255

        public void TestEvaluateColumnGreaterThan255()
        {
            XSSFWorkbook wb = (XSSFWorkbook)_testDataProvider.OpenSampleWorkbook("50096.xlsx");
            IFormulaEvaluator Evaluator = wb.GetCreationHelper().CreateFormulaEvaluator();

            /**
             *  The first row simply Contains the numbers 1 - 300.
             *  The second row simply refers to the cell value above in the first row by a simple formula.
             */
            for (int i = 245; i < 265; i++)
            {
                ICell cell_noformula = wb.GetSheetAt(0).GetRow(0).GetCell(i);
                ICell cell_formula = wb.GetSheetAt(0).GetRow(1).GetCell(i);

                CellReference ref_noformula = new CellReference(cell_noformula.RowIndex, cell_noformula.ColumnIndex);
                CellReference ref_formula = new CellReference(cell_noformula.RowIndex, cell_noformula.ColumnIndex);
                String fmla = cell_formula.CellFormula;
                // assure that the formula refers to the cell above.
                // the check below is 'deep' and involves conversion of the shared formula:
                // in the sample file a shared formula in GN1 is spanned in the range GN2:IY2,
                Assert.AreEqual(ref_noformula.FormatAsString(), fmla);

                CellValue cv_noformula = Evaluator.Evaluate(cell_noformula);
                CellValue cv_formula = Evaluator.Evaluate(cell_formula);
                Assert.AreEqual(cv_noformula.NumberValue, cv_formula.NumberValue, "Wrong Evaluation result in " + ref_formula.FormatAsString());
            }
        }
开发者ID:89sos98,项目名称:npoi,代码行数:27,代码来源:TestXSSFFormulaEvaluation.cs

示例2: TestReadCalcSheet

 public void TestReadCalcSheet()
 {
     try
     {
         HSSFWorkbook wb = HSSFTestDataSamples.OpenSampleWorkbook("XRefCalc.xls");
         Assert.AreEqual("Sheet1!$A$2", wb.GetName("QUANT").RefersToFormula);
         Assert.AreEqual("Sheet1!$B$2", wb.GetName("PART").RefersToFormula);
         Assert.AreEqual("x123", wb.GetSheet("Sheet1").GetRow(1).GetCell(1).StringCellValue);
         Assert.AreEqual("Sheet1!$C$2", wb.GetName("UNITCOST").RefersToFormula);
         CellReference cellRef = new CellReference(wb.GetName("UNITCOST").RefersToFormula);
         ICell cell = wb.GetSheet(cellRef.SheetName).GetRow(cellRef.Row).GetCell((int)cellRef.Col);
         Assert.AreEqual("VLOOKUP(PART,COSTS,2,FALSE)", cell.CellFormula);
         Assert.AreEqual("Sheet1!$D$2", wb.GetName("COST").RefersToFormula);
         cellRef = new CellReference(wb.GetName("COST").RefersToFormula);
         cell = wb.GetSheet(cellRef.SheetName).GetRow(cellRef.Row).GetCell((int)cellRef.Col);
         Assert.AreEqual("UNITCOST*Quant", cell.CellFormula);
         Assert.AreEqual("Sheet1!$E$2", wb.GetName("TOTALCOST").RefersToFormula);
         cellRef = new CellReference(wb.GetName("TOTALCOST").RefersToFormula);
         cell = wb.GetSheet(cellRef.SheetName).GetRow(cellRef.Row).GetCell((int)cellRef.Col);
         Assert.AreEqual("Cost*Markup_Cost", cell.CellFormula);
     }
     catch (Exception e)
     {
         Assert.Fail(e.Message);
     }
 }
开发者ID:89sos98,项目名称:npoi,代码行数:26,代码来源:TestExternalNameReference.cs

示例3: FormatAsString

        /**
     * @return the text format of this range using specified sheet name.
     */
        public String FormatAsString(String sheetName, bool useAbsoluteAddress)
        {
            StringBuilder sb = new StringBuilder();
            if (sheetName != null)
            {
                sb.Append(SheetNameFormatter.Format(sheetName));
                sb.Append("!");
            }
            CellReference cellRefFrom = new CellReference(FirstRow, FirstColumn,
                    useAbsoluteAddress, useAbsoluteAddress);
            CellReference cellRefTo = new CellReference(LastRow, LastColumn,
                    useAbsoluteAddress, useAbsoluteAddress);
            sb.Append(cellRefFrom.FormatAsString());

            //for a single-cell reference return A1 instead of A1:A1
            //for full-column ranges or full-row ranges return A:A instead of A,
            //and 1:1 instead of 1
            if (!cellRefFrom.Equals(cellRefTo)
                || IsFullColumnRange || IsFullRowRange)
            {
                sb.Append(':');
                sb.Append(cellRefTo.FormatAsString());
            }
            return sb.ToString();
        }
开发者ID:WPG,项目名称:npoi,代码行数:28,代码来源:CellRangeAddress.cs

示例4: TestEvaluate

 public void TestEvaluate()
 {
     HSSFWorkbook wb = HSSFTestDataSamples.OpenSampleWorkbook("XRefCalc.xls");
     HSSFWorkbook wb2 = HSSFTestDataSamples.OpenSampleWorkbook("XRefCalcData.xls");
     CellReference cellRef = new CellReference(wb.GetName("QUANT").RefersToFormula);
     ICell cell = wb.GetSheet(cellRef.SheetName).GetRow(cellRef.Row).GetCell((int)cellRef.Col);
     cell.SetCellValue(NEW_QUANT);
     cell = wb2.GetSheet("CostSheet").GetRow(1).GetCell(1);
     cell.SetCellValue(NEW_PART_COST);
     HSSFFormulaEvaluator Evaluator = new HSSFFormulaEvaluator(wb);
     HSSFFormulaEvaluator EvaluatorCost = new HSSFFormulaEvaluator(wb2);
     String[] bookNames = { "XRefCalc.xls", "XRefCalcData.xls" };
     HSSFFormulaEvaluator[] Evaluators = { Evaluator, EvaluatorCost, };
     HSSFFormulaEvaluator.SetupEnvironment(bookNames, Evaluators);
     cellRef = new CellReference(wb.GetName("UNITCOST").RefersToFormula);
     ICell uccell = wb.GetSheet(cellRef.SheetName).GetRow(cellRef.Row).GetCell((int)cellRef.Col);
     cellRef = new CellReference(wb.GetName("COST").RefersToFormula);
     ICell ccell = wb.GetSheet(cellRef.SheetName).GetRow(cellRef.Row).GetCell((int)cellRef.Col);
     cellRef = new CellReference(wb.GetName("TOTALCOST").RefersToFormula);
     ICell tccell = wb.GetSheet(cellRef.SheetName).GetRow(cellRef.Row).GetCell((int)cellRef.Col);
     Evaluator.EvaluateFormulaCell(uccell);
     Evaluator.EvaluateFormulaCell(ccell);
     Evaluator.EvaluateFormulaCell(tccell);
     Assert.AreEqual(NEW_PART_COST, uccell.NumericCellValue);
     Assert.AreEqual(NEW_PART_COST * NEW_QUANT, ccell.NumericCellValue);
     Assert.AreEqual(NEW_PART_COST * NEW_QUANT * MARKUP_COST_2, tccell.NumericCellValue);
 }
开发者ID:ctddjyds,项目名称:npoi,代码行数:27,代码来源:TestExternalNameReference.cs

示例5: Process

        private static void Process(IRow row, HSSFFormulaEvaluator eval)
        {
            IEnumerator it = row.GetEnumerator();
            while (it.MoveNext())
            {
                ICell cell = (ICell)it.Current;
                if (cell.CellType != NPOI.SS.UserModel.CellType.FORMULA)
                {
                    continue;
                }
                FormulaRecordAggregate record = (FormulaRecordAggregate)((HSSFCell)cell).CellValueRecord;
                FormulaRecord r = record.FormulaRecord;
                Ptg[] ptgs = r.ParsedExpression;

                String cellRef = new CellReference(row.RowNum, cell.ColumnIndex, false, false).FormatAsString();
#if !HIDE_UNREACHABLE_CODE
                if (false && cellRef.Equals("BP24"))
                { 
                    Console.Write(cellRef);
                    Console.WriteLine(" - has " + ptgs.Length + " ptgs:");
                    for (int i = 0; i < ptgs.Length; i++)
                    {
                        String c = ptgs[i].GetType().ToString();
                        Console.WriteLine("\t" + c.Substring(c.LastIndexOf('.') + 1));
                    }
                    Console.WriteLine("-> " + cell.CellFormula);
                }
#endif

                NPOI.SS.UserModel.CellValue evalResult = eval.Evaluate(cell);
                Assert.IsNotNull(evalResult);
            }
        }
开发者ID:hanwangkun,项目名称:npoi,代码行数:33,代码来源:TestBug42464.cs

示例6: buildWorkbook

        private void buildWorkbook(IWorkbook wb)
        {
            ISheet sh = wb.CreateSheet();
            IRow row1 = sh.CreateRow(0);
            IRow row2 = sh.CreateRow(1);
            row3 = sh.CreateRow(2);

            row1.CreateCell(0, CellType.Numeric);
            row1.CreateCell(1, CellType.Numeric);

            row2.CreateCell(0, CellType.Numeric);
            row2.CreateCell(1, CellType.Numeric);

            row3.CreateCell(0);
            row3.CreateCell(1);

            CellReference a1 = new CellReference("A1");
            CellReference a2 = new CellReference("A2");
            CellReference b1 = new CellReference("B1");
            CellReference b2 = new CellReference("B2");

            sh.GetRow(a1.Row).GetCell(a1.Col).SetCellValue(35);
            sh.GetRow(a2.Row).GetCell(a2.Col).SetCellValue(0);
            sh.GetRow(b1.Row).GetCell(b1.Col).CellFormula = (/*setter*/"A1/A2");
            sh.GetRow(b2.Row).GetCell(b2.Col).CellFormula = (/*setter*/"NA()");

            Evaluator = wb.GetCreationHelper().CreateFormulaEvaluator();
        }
开发者ID:Reinakumiko,项目名称:npoi,代码行数:28,代码来源:TestLogicalFunction.cs

示例7: RefPtgBase

 protected RefPtgBase(CellReference c)
 {
     Row = (c.Row);
     Column = (c.Col);
     IsColRelative = (!c.IsColAbsolute);
     IsRowRelative = (!c.IsRowAbsolute);
 }
开发者ID:xoposhiy,项目名称:npoi,代码行数:7,代码来源:RefPtgBase.cs

示例8: Ref3DPtg

 public Ref3DPtg(String cellref, int externIdx)
 {
     CellReference c = new CellReference(cellref);
     Row=c.Row;
     Column=c.Col;
     IsColRelative=!c.IsColAbsolute;
     IsRowRelative=!c.IsRowAbsolute;
     ExternSheetIndex=externIdx;
 }
开发者ID:babywzazy,项目名称:Server,代码行数:9,代码来源:Ref3DPtg.cs

示例9: FormatAsString

 public String FormatAsString()
 {
     StringBuilder sb = new StringBuilder();
     CellReference cellRefFrom = new CellReference(FirstRow, FirstColumn);
     CellReference cellRefTo = new CellReference(LastRow, LastColumn);
     sb.Append(cellRefFrom.FormatAsString());
     sb.Append(':');
     sb.Append(cellRefTo.FormatAsString());
     return sb.ToString();
 }
开发者ID:uwitec,项目名称:web-mvc-logistics,代码行数:10,代码来源:CellRangeAddress.cs

示例10: AreaReference

        /**
         * Create an area ref from a string representation.  Sheet names containing special Chars should be
         * delimited and escaped as per normal syntax rules for formulas.<br/> 
         * The area reference must be contiguous (i.e. represent a single rectangle, not a Union of rectangles)
         */
        public AreaReference(String reference)
        {
            if (!IsContiguous(reference))
            {
                throw new ArgumentException(
                        "References passed to the AreaReference must be contiguous, " +
                        "use generateContiguous(ref) if you have non-contiguous references");
            }

            String[] parts = SeparateAreaRefs(reference);

            String part0 = parts[0];
            if (parts.Length == 1)
            {
                // TODO - probably shouldn't initialize area ref when text is really a cell ref
                // Need to fix some named range stuff to get rid of this
                _firstCell = new CellReference(part0);

                _lastCell = _firstCell;
                _isSingleCell = true;
                return;
            }
            if (parts.Length != 2)
            {
                throw new ArgumentException("Bad area ref '" + reference + "'");
            }
            String part1 = parts[1];
            if (IsPlainColumn(part0))
            {
                if (!IsPlainColumn(part1))
                {
                    throw new Exception("Bad area ref '" + reference + "'");
                }
                // Special handling for whole-column references
                // Represented internally as x$1 to x$65536
                //  which is the maximum range of rows

                bool firstIsAbs = CellReference.IsPartAbsolute(part0);
                bool lastIsAbs = CellReference.IsPartAbsolute(part1);

                int col0 = CellReference.ConvertColStringToIndex(part0);
                int col1 = CellReference.ConvertColStringToIndex(part1);

                _firstCell = new CellReference(0, col0, true, firstIsAbs);
                _lastCell = new CellReference(0xFFFF, col1, true, lastIsAbs);
                _isSingleCell = false;
                // TODO - whole row refs
            }
            else
            {
                _firstCell = new CellReference(part0);
                _lastCell = new CellReference(part1);
                _isSingleCell = part0.Equals(part1);
            }
        }
开发者ID:xiepeixing,项目名称:npoi,代码行数:60,代码来源:AreaReference.cs

示例11: ToString

 public override String ToString()
 {
     CellReference cr = new CellReference(Row, Column);
     StringBuilder sb = new StringBuilder();
     sb.Append(GetType().Name).Append("[");
     sb.Append(_evaluator.SheetName);
     sb.Append('!');
     sb.Append(cr.FormatAsString());
     sb.Append("]");
     return sb.ToString();
 }
开发者ID:hanwangkun,项目名称:npoi,代码行数:11,代码来源:LazyRefEval.cs

示例12: ToString

 public override String ToString()
 {
     CellReference cr = new CellReference(Row, Column, !IsRowRelative, !IsColRelative);
     StringBuilder sb = new StringBuilder();
     sb.Append(GetType().Name);
     sb.Append(" [");
     sb.Append("sheetIx=").Append(ExternSheetIndex);
     sb.Append(" ! ");
     sb.Append(cr.FormatAsString());
     sb.Append("]");
     return sb.ToString();
 }
开发者ID:xoposhiy,项目名称:npoi,代码行数:12,代码来源:Ref3DPtg.cs

示例13: TestSpecialSheetNames

        public void TestSpecialSheetNames()
        {
            CellReference cf;
            cf = new CellReference("'profit + loss'!A1");
            ConfirmCell(cf, "profit + loss", 0, 0, false, false, "'profit + loss'!A1");

            cf = new CellReference("'O''Brien''s Sales'!A1");
            ConfirmCell(cf, "O'Brien's Sales", 0, 0, false, false, "'O''Brien''s Sales'!A1");

            cf = new CellReference("'Amazing!'!A1");
            ConfirmCell(cf, "Amazing!", 0, 0, false, false, "'Amazing!'!A1");
        }
开发者ID:xoposhiy,项目名称:npoi,代码行数:12,代码来源:TestCellReference.cs

示例14: ToString

 public override String ToString()
 {
     CellReference crA = new CellReference(FirstRow, FirstColumn);
     CellReference crB = new CellReference(LastRow, LastColumn);
     StringBuilder sb = new StringBuilder();
     sb.Append(GetType().Name).Append("[");
     sb.Append(_evaluator.SheetName);
     sb.Append('!');
     sb.Append(crA.FormatAsString());
     sb.Append(':');
     sb.Append(crB.FormatAsString());
     sb.Append("]");
     return sb.ToString();
 }
开发者ID:babywzazy,项目名称:Server,代码行数:14,代码来源:LazyAreaEval.cs

示例15: Ref3DPxg

 public Ref3DPxg(int externalWorkbookNumber, SheetIdentifier sheetName, CellReference c)
     : base(c)
 {
     this.externalWorkbookNumber = externalWorkbookNumber;
     this.firstSheetName = sheetName.SheetId.Name;
     if (sheetName is SheetRangeIdentifier)
     {
         this.lastSheetName = ((SheetRangeIdentifier)sheetName).LastSheetIdentifier.Name;
     }
     else
     {
         this.lastSheetName = null;
     }
 }
开发者ID:Reinakumiko,项目名称:npoi,代码行数:14,代码来源:Ref3DPxg.cs


注:本文中的NPOI.SS.Util.CellReference类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。