/// <summary> /// Gets the cell data. /// </summary> /// <param name="worksheet">The sheet</param> /// <param name="area">The area</param> /// <param name="rowIndex">Index of the row</param> /// <param name="columnIndex">Index of the column</param> /// <param name="opt">The opt</param> /// <returns></returns> static object GetCellData(Worksheet worksheet, SheetArea area, int rowIndex, int columnIndex, ImportExportOptions opt) { if (opt.Formula && (area == SheetArea.Cells)) { string formula = worksheet.GetFormula(rowIndex, columnIndex); if (!string.IsNullOrEmpty(formula)) { return(string.Format("={0}", (object[])new object[] { formula })); } } if (!opt.UnFormatted) { IFormatter formatter = worksheet.GetActualFormatter(rowIndex, columnIndex, area); if (formatter != null) { return(worksheet.Value2Text(worksheet.GetValue(rowIndex, columnIndex, area), formatter)); } } object columnLabel = worksheet.GetValue(rowIndex, columnIndex, area); if ((columnLabel == null) && (area == SheetArea.ColumnHeader)) { columnLabel = worksheet.GetColumnLabel(rowIndex, columnIndex); } if ((columnLabel == null) && (area == (SheetArea.CornerHeader | SheetArea.RowHeader))) { columnLabel = worksheet.GetRowLabel(rowIndex, columnIndex); } return(columnLabel); }
static bool IsEmptyCell(Worksheet sheetView, int r, int c) { object obj2 = sheetView.GetValue(r, c); if ((obj2 != null) && (obj2.ToString().Length > 0)) { return(false); } return(true); }
public static bool DetectRanges(Worksheet sheetView, int row, int column, int rowCount, int columnCount, out CellRange seriesName, out CellRange category, out CellRange data) { int num = sheetView.RowCount; int num2 = sheetView.ColumnCount; if (((rowCount < 1) && (row != -1)) || ((columnCount < 1) && (column != -1))) { throw new ArgumentException("Cannot detect an empty cell range."); } TrimCellRange(sheetView, ref row, ref column, ref rowCount, ref columnCount); category = null; seriesName = null; data = null; if ((rowCount <= 0) || (columnCount <= 0)) { return(false); } Windows.Foundation.Rect rect = new Windows.Foundation.Rect((double)column, (double)row, (double)columnCount, (double)rowCount); Windows.Foundation.Rect rect2 = new Windows.Foundation.Rect(0.0, 0.0, (double)num2, (double)num); rect.Intersect(rect2); row = (int)rect.Y; column = (int)rect.X; rowCount = (int)rect.Height; columnCount = (int)rect.Width; if ((row < 0) || (column < 0)) { throw new ArgumentException("The cell range is invalid."); } if ((rowCount == 1) && (columnCount == 1)) { if (!IsEmptyCell(sheetView, row, column)) { data = new CellRange(row, column, rowCount, columnCount); } return(false); } if (IsEmptyCell(sheetView, row, column)) { int c = column + 1; int r = row + 1; while ((c < (column + columnCount)) && IsEmptyCell(sheetView, row, c)) { c++; } int num3 = c; int num4 = (column + columnCount) - num3; if (num4 == 0) { while ((r < (row + rowCount)) && IsEmptyCell(sheetView, r, column)) { r++; } if (r == (row + rowCount)) { if (rowCount > 1) { if (columnCount > 1) { category = new CellRange(row, column + 1, 1, columnCount - 1); seriesName = new CellRange(row + 1, column, rowCount - 1, 1); data = new CellRange(row + 1, column + 1, rowCount - 1, columnCount - 1); } else { seriesName = new CellRange(row, column, 1, 1); data = new CellRange(row + 1, column, rowCount - 1, 1); } } else { seriesName = new CellRange(row, column, 1, 1); data = new CellRange(row, column + 1, rowCount, columnCount - 1); } } else if (columnCount > 1) { if ((columnCount > 1) && ((r - row) >= 1)) { category = new CellRange(row, column + 1, r - row, columnCount - 1); } if ((rowCount > 1) && ((row + rowCount) > r)) { seriesName = new CellRange(r, column, (row + rowCount) - r, 1); } data = new CellRange(r, column + 1, (row + rowCount) - r, columnCount - 1); } else { seriesName = null; if (((rowCount > 1) && (r > row)) && (r < (row + rowCount))) { category = new CellRange(row, column, r - row, columnCount); } if ((r < (row + rowCount)) && (r > row)) { data = new CellRange(r, column, (row + rowCount) - r, columnCount); } else { data = new CellRange(row, column, rowCount, columnCount); } } } else { c--; while ((r < (row + rowCount)) && IsEmptyCell(sheetView, r, c)) { r++; } if (r == (row + rowCount)) { if (rowCount > 1) { if ((columnCount > 1) && ((r - row) >= 1)) { category = new CellRange(row, num3, 1, num4); } if ((rowCount > 1) && (columnCount > num4)) { seriesName = new CellRange(row + 1, column, rowCount - 1, columnCount - num4); } data = new CellRange(row + 1, num3, rowCount - 1, num4); } else { seriesName = new CellRange(row, column, rowCount, num3 - column); data = new CellRange(row, num3, rowCount, num4); } } else { if ((columnCount > 1) && ((r - row) >= 1)) { category = new CellRange(row, num3, r - row, num4); } if (((rowCount > 1) && ((row + rowCount) > r)) && (columnCount > num4)) { seriesName = new CellRange(r, column, (row + rowCount) - r, columnCount - num4); } data = new CellRange(r, num3, (row + rowCount) - r, num4); } } } else { int num7 = (column + columnCount) - 1; int num8 = (row + rowCount) - 1; if ((columnCount > 1) && (rowCount > 1)) { int num9 = num7; int num10 = 0; while ((num9 >= column) && IsNumericData(sheetView.GetValue(num8, num9))) { num10++; num9--; } bool flag = num10 == 0; if (flag) { num10 = 1; num9--; } int num11 = num7; if (columnCount > 1) { num11 = num9 + 1; num9 = num8 - 1; int num12 = 1; if (!flag) { while ((num9 >= row) && IsNumericData(sheetView.GetValue(num9, num7))) { num12++; num9--; } } if (((num10 > 0) && (num11 >= column)) && ((num9 + 1) > row)) { category = new CellRange(row, num11, (num9 + 1) - row, num10); } if ((num12 > 0) && (num11 > column)) { seriesName = new CellRange(num9 + 1, column, num12, num11 - column); } data = new CellRange(num9 + 1, num11, num12, num10); } } else if (rowCount > 1) { if (IsNumericData(sheetView.GetValue(row, column))) { data = new CellRange(row, column, rowCount, columnCount); } else { int num13 = 0; int num14 = num8; while ((num14 >= row) && IsNumericData(sheetView.GetValue(num14, column))) { num14--; num13++; } if ((num14 == num8) && !IsNumericData(sheetView.GetValue(num14, column))) { num14--; } data = new CellRange(num14 + 1, column, num8 - num14, columnCount); if (num14 >= row) { seriesName = new CellRange(row, column, (num14 - row) + 1, columnCount); } } } else if (IsNumericData(sheetView.GetValue(row, column))) { data = new CellRange(row, column, rowCount, columnCount); } else { int num15 = 0; int num16 = num7; while ((num16 >= column) && IsNumericData(sheetView.GetValue(row, num16))) { num16--; num15++; } if ((num16 == num7) && !IsNumericData(sheetView.GetValue(row, num16))) { num16--; } data = new CellRange(row, num16 + 1, rowCount, num7 - num16); if (num16 >= column) { seriesName = new CellRange(row, column, rowCount, (num16 - column) + 1); } } } if ((((data != null) && (data.RowCount > data.ColumnCount)) && (data.RowCount > 1)) && ((data.ColumnCount > 1) || ((data.ColumnCount == 1) && ((seriesName != null) || (category != null))))) { bool flag2 = false; if (seriesName != null) { flag2 = seriesName.Row == data.Row; } else if (category != null) { flag2 = category.Column == data.Column; } if (flag2) { CellRange range = category; category = seriesName; seriesName = range; } return(true); } if (data != null) { if (data.RowCount == 1) { return(false); } if (data.ColumnCount == 1) { return(true); } } return(((seriesName != null) && (seriesName.Column == data.Column)) || ((category != null) && (category.Row == data.Row))); }