using System;
using System.IO;
using OfficeOpenXml;
// Create a new Excel file
var file = new MemoryStream();
using (var package = new ExcelPackage(file))
{
// Create a new worksheet
var worksheet = package.Workbook.Worksheets.Add("MyWorksheet");
// Establish a range on the worksheet
var range = worksheet.Cells[1, 1].TransformToType<ExcelRange>();
Console.WriteLine(range.Address);
// Save the Excel file
package.Save();
}
In this example, we first create a new Excel file using the ExcelPackage class. Then, we create a new worksheet using the Worksheet class. Finally, we establish a range on the worksheet using the TransformToType<ExcelRange>() method, and print the address of the range using the Address property.
Note that the TransformToType<ExcelRange>() method is used to convert the Cells object into an ExcelRange object, which is the type of the range in Office Open XML.
Also, the Address property of the ExcelRange object returns the range address in the format A1:B2, where A1 is the cell reference and B2 is the row and column index.
You can also use the ExcelRange.Address property to get the range address in a more flexible format, such as A1:B2 or 'A1:B2'.
It's worth noting that the ExcelRange class also provides other methods and properties that can be used to work with ranges in Office Open XML, such as Cells, Row, Column, Height, Width, and more.