/// <summary>
        ///
        /// </summary>
        /// <param name="worksheetName">will be used if no worksheet name is specified in <paramref name="address"/></param>
        /// <param name="address">address of a range</param>
        /// <returns></returns>
        public RangeAddress Create(string worksheetName, string address)
        {
            Require.That(address).Named("range").IsNotNullOrEmpty();
            //var addressInfo = ExcelAddressInfo.Parse(address);
            var adr          = new ExcelAddressBase(address);
            var sheet        = string.IsNullOrEmpty(adr.WorkSheet) ? worksheetName : adr.WorkSheet;
            var dim          = _excelDataProvider.GetDimensionEnd(adr.WorkSheet);
            var rangeAddress = new RangeAddress()
            {
                Address   = adr.Address,
                Worksheet = sheet,
                FromRow   = adr._fromRow,
                FromCol   = adr._fromCol,
                ToRow     = (dim != null && adr._toRow > dim.Row) ? dim.Row : adr._toRow,
                ToCol     = adr._toCol
            };

            //if (addressInfo.IsMultipleCells)
            //{
            //    HandleMultipleCellAddress(rangeAddress, addressInfo);
            //}
            //else
            //{
            //    HandleSingleCellAddress(rangeAddress, addressInfo);
            //}
            return(rangeAddress);
        }
Example #2
0
 public void Initialize()
 {
     _excelDataProvider = A.Fake <ExcelDataProvider>();
     A.CallTo(() => _excelDataProvider.GetDimensionEnd(A <string> .Ignored)).Returns(new ExcelCellAddress(10, 1));
     _parser    = new FormulaParser(_excelDataProvider);
     _package   = new ExcelPackage();
     _worksheet = _package.Workbook.Worksheets.Add("Test");
 }
Example #3
0
        public void HLookupShouldReturnClosestValueBelowIfLastArgIsTrue()
        {
            var lookupAddress = "A1:B2";

            A.CallTo(() => _excelDataProvider.GetDimensionEnd(A <string> .Ignored)).Returns(new ExcelCellAddress(5, 5));
            A.CallTo(() => _excelDataProvider.GetCellValue(WorksheetName, 1, 1)).Returns(3);
            A.CallTo(() => _excelDataProvider.GetCellValue(WorksheetName, 1, 2)).Returns(5);
            A.CallTo(() => _excelDataProvider.GetCellValue(WorksheetName, 2, 1)).Returns(1);
            A.CallTo(() => _excelDataProvider.GetCellValue(WorksheetName, 2, 2)).Returns(2);
            var result = _parser.Parse("HLOOKUP(4, " + lookupAddress + ", 2, true)");

            Assert.AreEqual(1, result);
        }