Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
To create a named range:
The code examples below show how to perform these steps using VSTO with either C#. The code examples that follow show how to do the same thing using Aspose.Cells for .NET, again with either C#.
//Create Excel Object
Excel.Application xl = Application;
//Create a new Workbook
Excel.Workbook wb = xl.Workbooks.Add(Missing.Value);
//Get Worksheets Collection
Excel.Sheets xlsheets = wb.Sheets;
//Select the first sheet
Excel.Worksheet excelWorksheet = (Excel.Worksheet)xlsheets[1];
//Select a range of cells
Excel.Range range = (Excel.Range)excelWorksheet.get_Range("A1:B4", Type.Missing);
//Add Name to Range
range.Name = "Test_Range";
//Put data in range cells
foreach (Excel.Range cell in range.Cells)
{
cell.set_Value(Missing.Value, "Test");
}
//Save New Workbook
wb.SaveCopyAs("Test_Range.xls");
//Quit Excel Object
xl.Quit();
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.Worksheets[0];
//Creating a named range
Range range = worksheet.Cells.CreateRange("A1", "B4");
//Setting the name of the named range
range.Name = "Test_Range";
for (int row = 0; row < range.RowCount; row++)
{
for (int column = 0; column < range.ColumnCount; column++)
{
range[row, column].PutValue("Test");
}
}
//Saving the modified Excel file in the default (i.e., Excel 2003) format
workbook.Save("Test_Range.xls");
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.