The C# programming language does not expect non-default properties to have parameters. However, some properties in the Excel object model do have parameters. Therefore, C# may access properties in the Excel object model that have parameters as methods. These properties may appear in the Object Browser and in IntelliSense prefixed with
get_, or prefixed with
set_, or prefixed with both
get_ and
set_.
The following C# code sample uses Excel properties that have the
get_Range method and the
set_Value method:
//Start Excel, and then add a new workbook.
Excel.Application oXl = new Excel.Application();
Excel.Workbooks oBooks = oXl.Workbooks;
Excel.Workbook oBook =
oBooks.Add(System.Reflection.Missing.Value);
Excel.Sheets oSheets = oBook.Sheets;
//Acquire a reference to the first worksheet in the new workbook.
Excel.Worksheet oSheet = (Excel.Worksheet)oSheets["Sheet1"];
//Acquire a reference to cell A1 on the worksheet, and then set the
//value for the range.
Excel.Range oRange = oSheet.get_Range("A1","A1");
oRange.set_Value(Excel.XlRangeValueDataType.xlRangeValueDefault,
"Hello World!");
//Make Excel visible, and then give the user control.
oXl.Visible = true;
oXl.UserControl = true;