Exemplo n.º 1
0
 /// <summary>
 ///     从Excel 单元格地址字符串 获取 CellAddress 对象实例
 /// 以 “#”开头的地址都为 <see cref="Ref"/>
 /// </summary>
 /// <param name="address"></param>
 /// <returns></returns>
 public static CellAddress Get(string address)
 {
     if (address == null)
     {
         throw new ArgumentNullException(nameof(address));
     }
     if (address.Length == 0)
     {
         throw new ArgumentException($"Argument Invalid Address {address}");
     }
     return(AddressParser.ParseAddress(address));
 }
Exemplo n.º 2
0
        /// <summary>
        /// 构建一个新的 <see cref="CellAddress"/>
        /// </summary>
        /// <param name="sheetName"></param>
        /// <param name="rowFirst">从0开始开始行索引</param>
        /// <param name="rowLast">从0开始最后行索引</param>
        /// <param name="columnFirst">从0开始开始列索引</param>
        /// <param name="columnLast">从0开始的最后列索引</param>
        public CellAddress(string sheetName, int rowFirst, int rowLast, int columnFirst, int columnLast)
        {
            SheetName = sheetName;
            if (rowFirst < 0 && columnFirst < 0)
            {
                throw new IndexOutOfRangeException("Row or Column out of range");
            }

            if (rowLast < 0 || columnLast < 0)
            {
                //整行/整列
                if (rowLast < 0)
                {
                    //整行
                    RowFirst    = 0;
                    RowLast     = RowsLimit - 1;
                    ColumnFirst = columnFirst;
                    ColumnLast  = columnLast;
                    Count       = Rows * ColumnsLimit;
                }
                else
                {
                    //整列
                    RowFirst    = rowFirst;
                    RowLast     = rowLast;
                    ColumnFirst = 0;
                    ColumnLast  = ColumnsLimit - 1;
                    Count       = Columns * RowsLimit;
                }
                LocalAddress = $"{AddressParser.ToAddress(rowFirst, columnFirst)}:{AddressParser.ToAddress(rowLast, columnLast)}";
            }
            else
            {
                if (columnFirst == columnLast && rowFirst == rowLast)
                {
                    LocalAddress = AddressParser.ToAddress(rowFirst, columnFirst);
                }
                else
                {
                    LocalAddress =
                        $"{AddressParser.ToAddress(rowFirst, columnFirst)}:{AddressParser.ToAddress(rowLast, columnLast)}";
                }

                RowFirst    = rowFirst;
                RowLast     = rowLast;
                ColumnFirst = columnFirst;
                ColumnLast  = columnLast;
                Count       = Rows * Columns;
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// 解析单元格地址,并返回一个 <see cref="CellAddress"/> 对象
 /// </summary>
 /// <param name="rangeAddress"></param>
 /// <returns></returns>
 public static CellAddress Parse(string rangeAddress)
 {
     return(AddressParser.ParseAddress(rangeAddress));
 }