コード例 #1
0
ファイル: ExcelCellBase.cs プロジェクト: mmsgau/EPPlus-1
        internal static string GetFullAddress(string worksheetName, string address, bool fullRowCol)
        {
            var wsForAddress = "";

            if (!string.IsNullOrEmpty(worksheetName))
            {
                if (ExcelWorksheet.NameNeedsApostrophes(worksheetName))
                {
                    wsForAddress = "'" + worksheetName.Replace("'", "''") + "'";   //Makesure addresses handle single qoutes
                }
                else
                {
                    wsForAddress = worksheetName;
                }
            }
            if (address.IndexOf("!") == -1 || address == "#REF!")
            {
                if (fullRowCol)
                {
                    string[] cells = address.Split(':');
                    if (cells.Length > 0)
                    {
                        address = string.IsNullOrEmpty(wsForAddress) ? cells[0] : string.Format("{0}!{1}", wsForAddress, cells[0]);
                        if (cells.Length > 1)
                        {
                            address += string.Format(":{0}", cells[1]);
                        }
                    }
                }
                else
                {
                    var a = new ExcelAddressBase(address);
                    if ((a._fromRow == 1 && a._toRow == ExcelPackage.MaxRows) || (a._fromCol == 1 && a._toCol == ExcelPackage.MaxColumns))
                    {
                        if (string.IsNullOrEmpty(wsForAddress))
                        {
                            address = $"{wsForAddress}!";
                        }
                        address += string.Format("{0}{1}:{2}{3}", ExcelAddress.GetColumnLetter(a._fromCol), a._fromRow, ExcelAddress.GetColumnLetter(a._toCol), a._toRow);
                    }
                    else
                    {
                        address = GetFullAddress(worksheetName, address, true);
                    }
                }
            }
            return(address);
        }