Пример #1
0
        /// <inheritdoc/>
        public override void FromString(string value)
        {
            var m = RowRegex.Match(value);

            if (m.Success)
            {
                if (m.Groups[1].Value.ToLower() == "null")
                {
                    Key = null;
                }
                else if (ulong.TryParse(m.Groups[1].Value, out var l))
                {
                    if (Dat.x64 && l == Nullx64Key || !Dat.x64 && l == Nullx32Key)
                    {
                        Key = null;
                    }
                    else
                    {
                        Key = l;
                    }
                }
                else
                {
                    throw new InvalidCastException("Unable to convert " + value + " to RowData");
                }
            }
            else
            {
                throw new InvalidCastException("Unable to convert " + value + " to RowData");
            }
        }
Пример #2
0
        public static Range ParseRange(string rangeString, ExcelVersion version)
        {
            var range = new Range();

            string[] split = rangeString.Split('!');

            if (split.Length > 1)
            {
                range.SheetName = split[0];
                split[1]        = split[1].Replace("$", "");
            }

            var cells = split.Last().Split(':').Select(r => new
            {
                ColumnIndex = ConvertColumnLettersToIndex(ColumnRegex.Match(r).Value, version),
                RowIndex    = ConvertRowNumberToIndex(RowRegex.Match(r).Value, version)
            }).ToArray();

            var start = cells[0];
            var end   = cells.Length == 1 ? start : cells[1];

            Func <int?, int?, RowColumn, bool> isAll = (startIndex, endIndex, rowColumn) =>
                                                       startIndex == 0 && endIndex == GetMax(rowColumn, version) - 1;

            Func <int?, RowColumn, int?> getMax = (index, rowColumn) =>
                                                  index == GetMax(rowColumn, version) - 1 ? null : index;

            if (!isAll(start.RowIndex, end.RowIndex, RowColumn.Row))
            {
                range.RowStart = start.RowIndex;
                range.RowEnd   = getMax(end.RowIndex, RowColumn.Row);
            }
            if (!isAll(start.ColumnIndex, end.ColumnIndex, RowColumn.Column))
            {
                range.ColumnStart = start.ColumnIndex;
                range.ColumnEnd   = getMax(end.ColumnIndex, RowColumn.Column);
            }

            return(range);
        }