示例#1
0
            public override void OnStartEvaluate(EvaluationCell cell, ICacheEntry entry)
            {
                _formulaCellsByCacheEntry.Remove(entry);
                _formulaCellsByCacheEntry.Add(entry, cell);
                Cell hc = _book.GetSheetAt(0).GetRow(cell.RowIndex).GetCell(cell.ColumnIndex);

                log("start", cell.RowIndex, cell.ColumnIndex, FormulaExtractor.GetPtgs(hc));
            }
示例#2
0
            public override void OnStartEvaluate(IEvaluationCell cell, ICacheEntry entry)
            {
                if (!_formulaCellsByCacheEntry.ContainsKey(entry))
                {
                    _formulaCellsByCacheEntry.Add(entry, cell);
                }
                else
                {
                    _formulaCellsByCacheEntry[entry] = cell;
                }
                ICell hc = _book.GetSheetAt(0).GetRow(cell.RowIndex).GetCell(cell.ColumnIndex);

                Log("start", cell.RowIndex, cell.ColumnIndex, FormulaExtractor.GetPtgs(hc));
            }
示例#3
0
        private void ConfirmCell(ICell formulaCell, String formula, HSSFWorkbook wb)
        {
            Ptg[] excelPtgs    = FormulaExtractor.GetPtgs(formulaCell);
            Ptg[] poiPtgs      = HSSFFormulaParser.Parse(formula, wb);
            int   nExcelTokens = excelPtgs.Length;
            int   nPoiTokens   = poiPtgs.Length;

            if (nExcelTokens != nPoiTokens)
            {
                if (nExcelTokens == nPoiTokens + 1 && excelPtgs[0].GetType() == typeof(AttrPtg))
                {
                    // compensate for missing tAttrVolatile, which belongs in any formula
                    // involving OFFSET() et al. POI currently does not insert where required
                    Ptg[] temp = new Ptg[nExcelTokens];
                    temp[0] = excelPtgs[0];
                    Array.Copy(poiPtgs, 0, temp, 1, nPoiTokens);
                    poiPtgs = temp;
                }
                else
                {
                    throw new Exception("Expected " + nExcelTokens + " tokens but got "
                                        + nPoiTokens);
                }
            }
            bool          hasMismatch = false;
            StringBuilder sb          = new StringBuilder();

            for (int i = 0; i < nExcelTokens; i++)
            {
                Ptg poiPtg   = poiPtgs[i];
                Ptg excelPtg = excelPtgs[i];
                if (excelPtg.GetType() != poiPtg.GetType())
                {
                    hasMismatch = true;
                    sb.Append("  mismatch token type[" + i + "] " + GetShortClassName(excelPtg) + " "
                              + excelPtg.RVAType + " - " + GetShortClassName(poiPtg) + " "
                              + poiPtg.RVAType);
                    sb.Append(Environment.NewLine);
                    continue;
                }
                if (poiPtg.IsBaseToken)
                {
                    continue;
                }
                sb.Append("  token[" + i + "] " + excelPtg.ToString() + " "
                          + excelPtg.RVAType);

                if (excelPtg.PtgClass != poiPtg.PtgClass)
                {
                    hasMismatch = true;
                    sb.Append(" - was " + poiPtg.RVAType);
                }
                sb.Append(Environment.NewLine);
            }
            //if (false)
            //{ // Set 'true' to see trace of RVA values
            //    Console.WriteLine(formula);
            //    Console.WriteLine(sb.ToString());
            //}
            if (hasMismatch)
            {
                throw new AssertionException(sb.ToString());
            }
        }