コード例 #1
0
 public void CompileMultiCellReferenceAbsolute()
 {
     var parsingContext = ParsingContext.Create();
     var file = new FileInfo("filename.xlsx");
     using (var package = new ExcelPackage(file))
     using (var sheet = package.Workbook.Worksheets.Add("NewSheet"))
     using (var excelDataProvider = new EpplusExcelDataProvider(package))
     {
         var rangeAddressFactory = new RangeAddressFactory(excelDataProvider);
         using (parsingContext.Scopes.NewScope(rangeAddressFactory.Create("NewSheet", 3, 3)))
         {
             var expression = new ExcelAddressExpression("$A$1:$A$5", excelDataProvider, parsingContext);
             var result = expression.Compile();
             var rangeInfo = result.Result as ExcelDataProvider.IRangeInfo;
             Assert.IsNotNull(rangeInfo);
             Assert.AreEqual("$A$1:$A$5", rangeInfo.Address.Address);
             // Enumerating the range still yields no results.
             Assert.AreEqual(0, rangeInfo.Count());
         }
     }
 }
コード例 #2
0
 public void CompileSingleCellReferenceResolveToRangeRowAbsolute()
 {
     var parsingContext = ParsingContext.Create();
     var file = new FileInfo("filename.xlsx");
     using (var package = new ExcelPackage(file))
     using (var sheet = package.Workbook.Worksheets.Add("NewSheet"))
     using (var excelDataProvider = new EpplusExcelDataProvider(package))
     {
         var rangeAddressFactory = new RangeAddressFactory(excelDataProvider);
         using (parsingContext.Scopes.NewScope(rangeAddressFactory.Create("NewSheet", 3, 3)))
         {
             var expression = new ExcelAddressExpression("$A1", excelDataProvider, parsingContext);
             expression.ResolveAsRange = true;
             var result = expression.Compile();
             var rangeInfo = result.Result as ExcelDataProvider.IRangeInfo;
             Assert.IsNotNull(rangeInfo);
             Assert.AreEqual("$A1", rangeInfo.Address.Address);
         }
     }
 }
コード例 #3
0
 public void CompileSingleCellReferenceWithValue()
 {
     var parsingContext = ParsingContext.Create();
     var file = new FileInfo("filename.xlsx");
     using (var package = new ExcelPackage(file))
     using (var sheet = package.Workbook.Worksheets.Add("NewSheet"))
     using (var excelDataProvider = new EpplusExcelDataProvider(package))
     {
         sheet.Cells[1, 1].Value = "Value";
         var rangeAddressFactory = new RangeAddressFactory(excelDataProvider);
         using (parsingContext.Scopes.NewScope(rangeAddressFactory.Create("NewSheet", 3, 3)))
         {
             var expression = new ExcelAddressExpression("A1", excelDataProvider, parsingContext);
             var result = expression.Compile();
             Assert.AreEqual("Value", result.Result);
         }
     }
 }
コード例 #4
0
 public void CompileMultiCellReferenceWithValues()
 {
     var parsingContext = ParsingContext.Create();
     var file = new FileInfo("filename.xlsx");
     using (var package = new ExcelPackage(file))
     using (var sheet = package.Workbook.Worksheets.Add("NewSheet"))
     using (var excelDataProvider = new EpplusExcelDataProvider(package))
     {
         sheet.Cells[1, 1].Value = "Value1";
         sheet.Cells[2, 1].Value = "Value2";
         sheet.Cells[3, 1].Value = "Value3";
         sheet.Cells[4, 1].Value = "Value4";
         sheet.Cells[5, 1].Value = "Value5";
         var rangeAddressFactory = new RangeAddressFactory(excelDataProvider);
         using (parsingContext.Scopes.NewScope(rangeAddressFactory.Create("NewSheet", 3, 3)))
         {
             var expression = new ExcelAddressExpression("A1:A5", excelDataProvider, parsingContext);
             var result = expression.Compile();
             var rangeInfo = result.Result as ExcelDataProvider.IRangeInfo;
             Assert.IsNotNull(rangeInfo);
             Assert.AreEqual("A1:A5", rangeInfo.Address.Address);
             Assert.AreEqual(5, rangeInfo.Count());
             for (int i = 1; i <= 5; i++)
             {
                 var rangeItem = rangeInfo.ElementAt(i - 1);
                 Assert.AreEqual("Value" + i, rangeItem.Value);
             }
         }
     }
 }