Пример #1
0
        /**
         *  Example return values:
         *    <table border="0" cellpAdding="1" cellspacing="0" summary="Example return values">
         *      <tr><th align='left'>Result</th><th align='left'>Comment</th></tr>
         *      <tr><td>A1:A1</td><td>Single cell area reference without sheet</td></tr>
         *      <tr><td>A1:$C$1</td><td>Multi-cell area reference without sheet</td></tr>
         *      <tr><td>Sheet1!A$1:B4</td><td>Standard sheet name</td></tr>
         *      <tr><td>'O''Brien''s Sales'!B5:C6' </td><td>Sheet name with special Chars</td></tr>
         *    </table>
         * @return the text representation of this area reference as it would appear in a formula.
         */
        public String FormatAsString()
        {
            // Special handling for whole-column references
            if (IsWholeColumnReference())
            {
                return
                    (CellReference.ConvertNumToColString(_firstCell.Col)
                     + ":" +
                     CellReference.ConvertNumToColString(_lastCell.Col));
            }

            StringBuilder sb = new StringBuilder(32);

            sb.Append(_firstCell.FormatAsString());
            if (!_isSingleCell)
            {
                sb.Append(CELL_DELIMITER);
                if (_lastCell.SheetName == null)
                {
                    sb.Append(_lastCell.FormatAsString());
                }
                else
                {
                    // don't want to include the sheet name twice
                    _lastCell.AppendCellReference(sb);
                }
            }
            return(sb.ToString());
        }