DataOrientation?ValidateXValuesRange(SheetCellRange[] ranges) { if ((ranges == null) || (ranges.Length == 0)) { return(0); } SheetCellRange range = ranges[0]; Worksheet sheet = range.Sheet; DataOrientation?nullable = new DataOrientation?((range.ColumnCount > range.RowCount) ? DataOrientation.Horizontal : DataOrientation.Vertical); for (int i = 1; i < ranges.Length; i++) { SheetCellRange range2 = ranges[i]; if (range2.Sheet != sheet) { throw new ArgumentException(ResourceStrings.NeedSingleCellRowColumn); } if (nullable.HasValue) { DataOrientation orientation2 = (range2.ColumnCount > range2.RowCount) ? DataOrientation.Horizontal : DataOrientation.Vertical; DataOrientation?nullable2 = nullable; if ((orientation2 != ((DataOrientation)nullable2.GetValueOrDefault())) || !nullable2.HasValue) { nullable = null; } } } return(nullable); }
public static SheetCellRange[] ExtractAllExternalReference(ICalcEvaluator evaluator, CalcExpression expression) { if (expression != null) { List <CalcReferenceExpression> nodes = new List <CalcReferenceExpression>(); FormulaUtility.ExtractAllReferenceExpression(evaluator, expression, nodes); if (nodes.Count > 0) { List <SheetCellRange> list2 = new List <SheetCellRange>(); foreach (CalcReferenceExpression expression2 in nodes) { if (expression2 is CalcExternalRangeExpression) { CalcExternalRangeExpression expression3 = expression2 as CalcExternalRangeExpression; SheetCellRange range = new SheetCellRange(expression3.Source as Worksheet, expression3.StartRow, expression3.StartColumn, (expression3.EndRow - expression3.StartRow) + 1, (expression3.EndColumn - expression3.StartColumn) + 1); list2.Add(range); } else if (expression2 is CalcExternalCellExpression) { CalcExternalCellExpression expression4 = expression2 as CalcExternalCellExpression; SheetCellRange range2 = new SheetCellRange(expression4.Source as Worksheet, expression4.Row, expression4.Column, 1, 1); list2.Add(range2); } else { return(null); } } return(list2.ToArray()); } } return(null); }
public static object[,] GetRangeValues(SheetCellRange valuesRange) { if ((valuesRange != null) && (valuesRange.Sheet != null)) { CalcExternalExpression expression = CreateExternalRangeExpressionByCount(valuesRange.Sheet, valuesRange.Row, valuesRange.Column, valuesRange.RowCount, valuesRange.ColumnCount, true, true, true, true); return(((ICalcEvaluator)valuesRange.Sheet).EvaluateExpression(expression, 0, 0, 0, 0, true) as object[, ]); } return(null); }
public static object[] GetRowValues(SheetCellRange valuesRange, int row) { object[,] rangeValues = GetRangeValues(valuesRange); int length = rangeValues.GetLength(1); List <object> list = new List <object>(length); for (int i = 0; i < length; i++) { object obj2 = rangeValues[row, i]; list.Add(obj2); } return(list.ToArray()); }
public static string SheetRange2Formula(ICalcEvaluator evaluator, SheetCellRange range) { if (evaluator == null) { return(null); } string str = null; try { CalcExternalRangeExpression expression = new CalcExternalRangeExpression(range.Sheet, range.Row, range.Column, (range.Row + range.RowCount) - 1, (range.Column + range.ColumnCount) - 1, false, false, false, false); str = evaluator.Expression2Formula(expression, 0, 0); } catch (Exception) { } return(str); }
public static List <List <SheetCellRange> > TryCombineSeriesRange(List <List <SheetCellRange> > seriesRanges, DataOrientation dataOrientation) { List <List <SheetCellRange> > list = new List <List <SheetCellRange> >(); for (int i = 0; i < seriesRanges.Count; i++) { List <SheetCellRange> list2 = seriesRanges[i]; if ((list2 != null) && (list2.Count != 0)) { if (list.Count == 0) { List <SheetCellRange> list3 = new List <SheetCellRange>(); for (int k = 0; k < list2.Count; k++) { list3.Add(list2[k].Clone() as SheetCellRange); } list.Add(list3); continue; } List <SheetCellRange> list4 = list[list.Count - 1]; if (list2.Count != list4.Count) { List <SheetCellRange> list5 = new List <SheetCellRange>(); for (int m = 0; m < list2.Count; m++) { list5.Add(list2[m].Clone() as SheetCellRange); } list.Add(list5); continue; } bool flag = true; for (int j = 0; j < list2.Count; j++) { SheetCellRange range = list2[j]; SheetCellRange range2 = list4[j]; if (dataOrientation == DataOrientation.Vertical) { if (((range.Row == range2.Row) && (range.RowCount == range2.RowCount)) && (range.Column == (range2.Column + range2.ColumnCount))) { continue; } flag = false; break; } if (((range.Column != range2.Column) || (range.ColumnCount != range2.ColumnCount)) || (range.Row != (range2.Row + range2.RowCount))) { flag = false; break; } } if (flag) { list.Remove(list4); List <SheetCellRange> list6 = new List <SheetCellRange>(); for (int n = 0; n < list2.Count; n++) { SheetCellRange range3 = list2[n]; SheetCellRange range4 = list4[n]; if (dataOrientation == DataOrientation.Vertical) { SheetCellRange range5 = new SheetCellRange(range4.Sheet, range4.Row, range4.Column, range4.RowCount, range4.ColumnCount + range3.ColumnCount); list6.Add(range5); } else { SheetCellRange range6 = new SheetCellRange(range4.Sheet, range4.Row, range4.Column, range4.RowCount + range3.RowCount, range4.ColumnCount); list6.Add(range6); } } list.Add(list6); } else { List <SheetCellRange> list7 = new List <SheetCellRange>(); for (int num6 = 0; num6 < list2.Count; num6++) { list7.Add(list2[num6].Clone() as SheetCellRange); } list.Add(list7); } } } List <List <SheetCellRange> > list8 = new List <List <SheetCellRange> >(); foreach (List <SheetCellRange> list9 in list) { if (list9.Count != 0) { List <SheetCellRange> list10 = new List <SheetCellRange> { list9[0] }; if (dataOrientation == DataOrientation.Vertical) { for (int num7 = 1; num7 < list9.Count; num7++) { SheetCellRange range7 = list10[list10.Count - 1]; SheetCellRange range8 = list9[num7]; if ((range7.Row + range7.RowCount) == range8.Row) { list10.Remove(range7); SheetCellRange range9 = new SheetCellRange(range7.Sheet, range7.Row, range7.Column, range7.RowCount + range8.RowCount, range7.ColumnCount); list10.Add(range9); } else { list10.Add(range8); } } } else { for (int num8 = 1; num8 < list9.Count; num8++) { SheetCellRange range10 = list10[list10.Count - 1]; SheetCellRange range11 = list9[num8]; if ((range10.Column + range10.ColumnCount) == range11.Column) { list10.Remove(range10); SheetCellRange range12 = new SheetCellRange(range10.Sheet, range10.Row, range10.Column, range10.RowCount, range10.ColumnCount + range11.ColumnCount); list10.Add(range12); } else { list10.Add(range11); } } } list8.Add(list10); } } return(list8); }