It seems you are having trouble retrieving the named range “Print_Area” from your workbook. The “Print_Area” is a special named range in Excel that defines the area of the worksheet that will be printed. Depending on the version of Aspose.Cells you are using, it may not be included in the standard named ranges returned by the method you are using.
To ensure you can access all named ranges, including special ones like “Print_Area”, you can try the following approach:
// Load the workbook
Workbook workbook = new Workbook("yourfile.xlsx");
// Get all named ranges
var namedRanges = workbook.Worksheets.Names;
// Check if "Print_Area" is in the named ranges
if (namedRanges["Print_Area"] != null)
{
Console.WriteLine("Print_Area found!");
}
else
{
Console.WriteLine("Print_Area not found.");
}
This code snippet retrieves all named ranges from the workbook, including any special ones. Make sure to replace "yourfile.xlsx" with the path to your actual file.
If you still cannot find “Print_Area”, please verify that it is defined correctly in your Excel file. Additionally, check for any version-specific issues with the Aspose.Cells library you are using.
@sachinganiger
From the screenshot you provided, we can see that the named range “Print_Area” belongs to the worksheet scope. By testing on v25.9 using the following example code, we can obtain the correct results. Please refer to the attachment. result.zip (46.8 KB)
// Create a new Workbook object
Workbook workbook = new Workbook();
// Get first worksheet of the workbook
Worksheet sheet = workbook.Worksheets[0];
// Get worksheet's cells collection
Cells cells = sheet.Cells;
// Create a range of Cells from Cell A1 to C10
Range workbookScope = cells.CreateRange("A1", "C10");
// Assign the nsame to workbook scope named range
workbookScope.Name = "workbookScope";
Worksheet sheet2 = workbook.Worksheets.Add("Sheet2");
cells = sheet2.Cells;
// Create a range of Cells
Range localRange = cells.CreateRange("D1", "E10");
// Assign name to range with sheet raference
localRange.Name = "Sheet2!Print_Area";
// Getting all named ranges
Range[] ranges = workbook.Worksheets.GetNamedRanges();
for (int i = 0; i < ranges.Length; i++)
{
Console.WriteLine(ranges[i].Name);
}
Range temp = workbook.Worksheets.GetRangeByName("Sheet2!Print_Area");
Console.WriteLine(temp.RefersTo);
// Save the workbook
workbook.Save(filePath + "out_net.xlsx");
If you still find the issue, kindly do share your complete sample (runnable) code and template Excel file (if any) to reproduce the issue on our end, we will check it soon.