private CollaboratingWorkbooksEnvironment(String[] workbookNames, WorkbookEvaluator[] evaluators, int nItems)
 {
     Hashtable m = new Hashtable(nItems * 3 / 2);
     Hashtable uniqueEvals = new Hashtable(nItems * 3 / 2);
     for (int i = 0; i < nItems; i++)
     {
         String wbName = workbookNames[i];
         WorkbookEvaluator wbEval = evaluators[i];
         if (m.ContainsKey(wbName))
         {
             throw new ArgumentException("Duplicate workbook name '" + wbName + "'");
         }
         if (uniqueEvals.ContainsKey(wbEval))
         {
             String msg = "Attempted To register same workbook under names '"
                 + uniqueEvals[(wbEval) + "' and '" + wbName + "'"];
             throw new ArgumentException(msg);
         }
         uniqueEvals[wbEval]=wbName;
         m[wbName] = wbEval;
     }
     UnhookOldEnvironments(evaluators);
     //HookNewEnvironment(evaluators, this); - moved to Setup method above
     _unhooked = false;
     _evaluators = evaluators;
     _evaluatorsByName = m;
 }
Ejemplo n.º 2
0
 public SheetRefEvaluator(WorkbookEvaluator bookEvaluator, EvaluationTracker tracker, int sheetIndex)
 {
     if (sheetIndex < 0)
     {
         throw new ArgumentException("Invalid sheetIndex: " + sheetIndex + ".");
     }
     _bookEvaluator = bookEvaluator;
     _tracker = tracker;
     _sheetIndex = sheetIndex;
 }
 public OperationEvaluationContext(WorkbookEvaluator bookEvaluator, IEvaluationWorkbook workbook, int sheetIndex, int srcRowNum,
         int srcColNum, EvaluationTracker tracker)
 {
     _bookEvaluator = bookEvaluator;
     _workbook = workbook;
     _sheetIndex = sheetIndex;
     _rowIndex = srcRowNum;
     _columnIndex = srcColNum;
     _tracker = tracker;
 }
 public static void Setup(String[] workbookNames, WorkbookEvaluator[] evaluators)
 {
     int nItems = workbookNames.Length;
     if (evaluators.Length != nItems)
     {
         throw new ArgumentException("Number of workbook names is " + nItems
                 + " but number of evaluators is " + evaluators.Length);
     }
     if (nItems < 1)
     {
         throw new ArgumentException("Must provide at least one collaborating worbook");
     }
     CollaboratingWorkbooksEnvironment env = new CollaboratingWorkbooksEnvironment(workbookNames, evaluators, nItems);
     HookNewEnvironment(evaluators, env);
 }
        private static void HookNewEnvironment(WorkbookEvaluator[] evaluators, CollaboratingWorkbooksEnvironment env)
        {

            // All evaluators will need To share the same cache.
            // but the cache takes an optional evaluation listener.
            int nItems = evaluators.Length;
            IEvaluationListener evalListener = evaluators[0].GetEvaluationListener();
            // make sure that all evaluators have the same listener
            for (int i = 0; i < nItems; i++)
            {
                if (evalListener != evaluators[i].GetEvaluationListener())
                {
                    // This would be very complex To support
                    throw new Exception("Workbook evaluators must all have the same evaluation listener");
                }
            }
            EvaluationCache cache = new EvaluationCache(evalListener);

            for (int i = 0; i < nItems; i++)
            {
                evaluators[i].AttachToEnvironment(env, cache, i);
            }

        }
 private void UnhookOldEnvironments(WorkbookEvaluator[] evaluators)
 {
     ArrayList oldEnvs = new ArrayList();
     for (int i = 0; i < evaluators.Length; i++)
     {
         oldEnvs.Add(evaluators[i].GetEnvironment());
     }
     CollaboratingWorkbooksEnvironment[] oldCWEs = new CollaboratingWorkbooksEnvironment[oldEnvs.Count];
     oldCWEs = (CollaboratingWorkbooksEnvironment[])oldEnvs.ToArray(typeof(CollaboratingWorkbooksEnvironment));
     for (int i = 0; i < oldCWEs.Length; i++)
     {
         oldCWEs[i].Unhook();
     }
 }
 /**
  * @param udfFinder pass <code>null</code> for default (AnalysisToolPak only)
  */
 public HSSFFormulaEvaluator(IWorkbook workbook, IStabilityClassifier stabilityClassifier, UDFFinder udfFinder)
 {
     _bookEvaluator = new WorkbookEvaluator(HSSFEvaluationWorkbook.Create(workbook), stabilityClassifier, udfFinder);
 }
 /**
  * Coordinates several formula evaluators together so that formulas that involve external
  * references can be evaluated.
  * @param workbookNames the simple file names used to identify the workbooks in formulas
  * with external links (for example "MyData.xls" as used in a formula "[MyData.xls]Sheet1!A1")
  * @param evaluators all evaluators for the full set of workbooks required by the formulas. 
  */
 public static void SetupEnvironment(String[] workbookNames, HSSFFormulaEvaluator[] evaluators)
 {
     WorkbookEvaluator[] wbEvals = new WorkbookEvaluator[evaluators.Length];
     for (int i = 0; i < wbEvals.Length; i++)
     {
         wbEvals[i] = evaluators[i]._bookEvaluator;
     }
     CollaboratingWorkbooksEnvironment.Setup(workbookNames, wbEvals);
 }
Ejemplo n.º 9
0
 private ForkedEvaluator(IEvaluationWorkbook masterWorkbook, IStabilityClassifier stabilityClassifier, UDFFinder udfFinder)
 {
     _sewb = new ForkedEvaluationWorkbook(masterWorkbook);
     _evaluator = new WorkbookEvaluator(_sewb, stabilityClassifier, udfFinder);
 }