Understanding the Dynamic Keyword in C# 4: Listing 2

Scripting Excel with C#

// Add this line to the beginning of the file:
// using Excel = Microsoft.Office.Interop.Excel;

var excelApp = new Excel.Application();

excelApp.Workbooks.Add();
// excelApp.Workbooks.Add(Type.Missing);

excelApp.Visible = true;

Excel.Range targetRange = excelApp.Range["A1"];
// Excel.Range targetRange = excelApp.get_Range("A1", Type.Missing);

targetRange.Value = "Name";
// targetRange.set_Value(Type.Missing, "Name");

targetRange.Columns[1].AutoFit();
// ((Excel.Range)targetRange.Columns[1, Type.Missing]).AutoFit();

About the Author

Alexandra Rusina is a program manager on the Silverlight team. Prior to that she worked as a programming writer on the Visual Studio Languages team during the Visual Studio 2010 release. She also regularly blogged on the C# Frequently Asked Question blog.

comments powered by Disqus

Featured

  • C# Language Server Revamps VS 2022 Razor Editor for ASP.NET Core

    Microsoft is touting new capabilities in ASP.NET Core web development in Visual Studio 2022 thanks to a new Razor editor powered by a Razor Language Server.

  • Windows Forms Lives On in .NET 6

    Windows Forms would like you to know that the reports of its death are greatly exaggerated.

  • Uno Platform 4.0 Adds Visual Studio Code Plugin

    Uno Platform 4.0 is out, highlighted by a new extension for working in Microsoft's Visual Studio Code editor.

  • .NET 6 Support Leads New GA Features in Azure Functions Fall Update

    Microsoft announced several new features that are now generally available in the fall update of Azure Functions, used for event-driven serverless computing in the cloud.

Upcoming Events