Example #1
0
 /// <summary>
 /// Convert position into relative address string. (format: A1)
 /// </summary>
 /// <returns>Related address in string.</returns>
 /// <seealso cref="ToAbsoluteAddress"/>
 public string ToAddress()
 {
     if (this.positionProperties == (PositionAbsoluteBits.StartRow | PositionAbsoluteBits.StartCol))
     {
         return("$" + RGUtility.GetAlphaChar(col) + "$" + (row + 1));
     }
     else if (this.positionProperties == PositionAbsoluteBits.StartCol)
     {
         return("$" + RGUtility.GetAlphaChar(col) + (row + 1));
     }
     else if (this.positionProperties == PositionAbsoluteBits.StartRow)
     {
         return(RGUtility.GetAlphaChar(col) + "$" + (row + 1));
     }
     else
     {
         return(RGUtility.GetAlphaChar(col) + (row + 1));
     }
 }
Example #2
0
 /// <summary>
 /// Convert into absolute address.
 /// </summary>
 /// <returns>absolute address identifier.</returns>
 public string ToAbsoluteAddress()
 {
     if (this.rows <= -1 && this.cols <= -1)
     {
         return("$1:$1048576");
     }
     else if (this.cols <= -1)
     {
         return(string.Format("${0}:${1}", this.row + 1, this.EndRow + 1));
     }
     else if (this.rows <= -1)
     {
         return(string.Format("${0}:${1}", RGUtility.GetAlphaChar(this.col), RGUtility.GetAlphaChar(this.EndCol)));
     }
     else
     {
         return(string.Format("${0}${1}:${2}${3}", RGUtility.GetAlphaChar(this.col), this.row + 1,
                              RGUtility.GetAlphaChar(this.EndCol), this.EndRow + 1));
     }
 }
Example #3
0
 /// <summary>
 /// Convert range into address string A1:B1 style.
 /// </summary>
 /// <returns>Address string converted from range position.</returns>
 public string ToRelativeAddress()
 {
     if (this.rows <= -1 && this.cols <= -1)
     {
         return("1:1048576");
     }
     else if (this.cols <= -1)
     {
         return(string.Format("{0}:{1}", this.row + 1, this.EndRow + 1));
     }
     else if (this.rows <= -1)
     {
         return(string.Format("{0}:{1}", RGUtility.GetAlphaChar(this.col), RGUtility.GetAlphaChar(this.EndCol)));
     }
     else
     {
         return(string.Format("{0}{1}:{2}{3}", RGUtility.GetAlphaChar(this.col), this.row + 1,
                              RGUtility.GetAlphaChar(this.EndCol), this.EndRow + 1));
     }
 }
Example #4
0
        /// <summary>
        /// Convert position or range into address stringConvert position or range into address string
        /// </summary>
        /// <param name="row">Zero-based index number of row</param>
        /// <param name="col">Zero-based index number of column</param>
        /// <param name="rows">Zero-based number of rows</param>
        /// <param name="cols">Zero-based number of columns</param>
        /// <param name="absNum">Determine that which R1C1 format should be used.<br/>
        /// <ul>
        /// <li>1: [Absolute Row][Absolute Col] R1C1</li>
        /// <li>2: [Absolute Row][Relative Col] R1C[1]</li>
        /// <li>3: [Relative Row][Absolute Col] R[1]C1</li>
        /// <li>4: [Relative Row][Relative Col] R[1]C[1]</li>
        /// </ul>
        /// </param>
        /// <param name="a1style">true to use A1 style; false use the R1C1 style</param>
        /// <returns>position or range in address string</returns>
        public static string ToAddress(int row, int col, int rows, int cols, int absNum, bool a1style)
        {
            if (rows <= 1 && cols <= 1)
            {
                // pos
                if (a1style)
                {
                    return(RGUtility.GetAlphaChar(col) + (row + 1));
                }
                else
                {
                    switch (absNum)
                    {
                    default:
                    case 1:                             // absolute row, absolute col
                        return(string.Format("R{0}C{1}", row, col));

                    case 2:                             // absolute row, relative col
                        return(string.Format("R{0}C[{1}]", row, col));

                    case 3:                             // relative row, absolute col
                        return(string.Format("R[{0}]C{1}", row, col));

                    case 4:                             // relative row, relative col
                        return(string.Format("R[{0}]C[{1}]", row, col));
                    }
                }
            }
            else
            {
                // range

                int toRow = row + rows - 1;
                int toCol = col + cols - 1;

                return(ToAddress(row, col, absNum, a1style) + ":" + ToAddress(row, col, absNum, a1style));
            }
        }
Example #5
0
 /// <summary>
 /// Convert position into absolute address string. (format: $A$1)
 /// </summary>
 /// <returns>Absolute address in string</returns>
 /// <seealso cref="ToAddress"/>
 public string ToAbsoluteAddress()
 {
     return(string.Format("${0}${1}", RGUtility.GetAlphaChar(this.col), this.row + 1));
 }
Example #6
0
 public string ToRelativeAddress()
 {
     return(RGUtility.GetAlphaChar(col) + (row + 1));
 }
Example #7
0
        public string ToAddress()
        {
            if (this.rows <= -1 && this.cols <= -1)
            {
                #region full rows and cols
                StringBuilder sb = new StringBuilder();

                if (this.StartRowProperty == PositionProperty.Absolute)
                {
                    sb.Append('$');
                }

                sb.Append("1:");

                if (this.EndRowProperty == PositionProperty.Absolute)
                {
                    sb.Append('$');
                }

                sb.Append("1048576");

                return(sb.ToString());

                #endregion                 // full rows and cols
            }
            else if (this.cols <= -1)
            {
                #region full cols
                StringBuilder sb = new StringBuilder();

                if (this.StartRowProperty == PositionProperty.Absolute)
                {
                    sb.Append('$');
                }

                sb.Append(this.row + 1);
                sb.Append(':');

                if (this.EndRowProperty == PositionProperty.Absolute)
                {
                    sb.Append('$');
                }

                sb.Append(this.EndRow + 1);

                return(sb.ToString());

                #endregion                 // full cols
            }
            else if (this.rows <= -1)
            {
                #region full rows
                StringBuilder sb = new StringBuilder();

                if (this.StartColumnProperty == PositionProperty.Absolute)
                {
                    sb.Append('$');
                }

                sb.Append(RGUtility.GetAlphaChar(this.col));
                sb.Append(':');

                if (this.EndColumnProperty == PositionProperty.Absolute)
                {
                    sb.Append('$');
                }

                sb.Append(RGUtility.GetAlphaChar(this.EndCol));

                return(sb.ToString());

                #endregion                 // full rows
            }
            else
            {
                #region normal address
                StringBuilder sb = new StringBuilder();

                // start
                if (this.StartColumnProperty == PositionProperty.Absolute)
                {
                    sb.Append('$');
                }

                sb.Append(RGUtility.GetAlphaChar(this.col));

                if (this.StartRowProperty == PositionProperty.Absolute)
                {
                    sb.Append('$');
                }

                sb.Append(this.row + 1);

                sb.Append(':');

                // end
                if (this.EndColumnProperty == PositionProperty.Absolute)
                {
                    sb.Append('$');
                }

                sb.Append(RGUtility.GetAlphaChar(this.EndCol));

                if (this.EndRowProperty == PositionProperty.Absolute)
                {
                    sb.Append('$');
                }

                sb.Append(this.EndRow + 1);

                return(sb.ToString());

                #endregion                 // normal address
            }
        }